Early access is open. Free sample datasets are live now. Download a sample

Python Quickstart with pandas

Details

Docs navigation

Python plus pandas is how most of our early-access sign-ups plan to use the data, so this page gets you from an empty file to a DataFrame of stock data in Python in a few minutes. It uses plain requests, because an official client is still on the roadmap, and the whole helper fits in about 30 lines you can paste into a notebook.

Early access. The API is planned and not live yet. You can practise every pandas step below today on the free CSVs from /sample-data.

Details

Steps

1. Install two packages

pip install requests pandas pyarrow

pyarrow is optional; it lets you save to Parquet.

2. Store your key

export MARKETDATA_API_KEY="paste-your-key-here"

3. Write a small helper

Example, saved as md.py:

import os
import requests
import pandas as pd

API = "https://api.marketdata.co/v1"
SESSION = requests.Session()
SESSION.headers["Authorization"] = f"Bearer {os.environ['MARKETDATA_API_KEY']}"

def get_df(path: str, **params) -> pd.DataFrame:
    """Call an endpoint, follow every page, return one DataFrame."""
    params.setdefault("limit", 50000)
    frames = []
    while True:
        r = SESSION.get(f"{API}{path}", params=params, timeout=60)
        if not r.ok:
            err = r.json().get("error", {})
            raise RuntimeError(f"{r.status_code} {err.get('code')}: {err.get('message')}")
        body = r.json()
        frames.append(pd.DataFrame(body["results"]))
        if not body.get("next_cursor"):
            break
        params["cursor"] = body["next_cursor"]
    df = pd.concat(frames, ignore_index=True)
    for col in ("timestamp", "date"):
        if col in df:
            df[col] = pd.to_datetime(df[col], utc=(col == "timestamp"))
    return df

4. Pull daily bars

Example (Python):

from md import get_df

msft = get_df("/stocks/bars", symbol="MSFT", interval="1d", start="2020-01-01")
msft = msft.set_index("date")
msft["ret"] = msft["adjusted_close"].pct_change()
print(msft[["close", "adjusted_close", "ret"]].tail())

Use adjusted_close for returns that include dividends, close for split-adjusted prices only. See adjustments.

5. Pull minute bars and resample

Example (Python):

spy = get_df("/stocks/bars", symbol="SPY", interval="1m",
             start="2026-11-18T14:30:00Z", end="2026-11-18T21:00:00Z")
spy = spy.set_index("timestamp").tz_convert("America/New_York")

five = spy.resample("5min", label="left", closed="left").agg(
    {"open": "first", "high": "max", "low": "min", "close": "last", "volume": "sum"}
).dropna()

Bars are stamped at the start, so resample with label="left" and closed="left" to keep the same convention.

6. Many symbols at once

Example (Python):

symbols = ["AAPL", "MSFT", "NVDA", "AMZN"]
closes = pd.concat(
    {s: get_df("/stocks/bars", symbol=s, interval="1d", start="2024-01-01").set_index("date")["adjusted_close"]
     for s in symbols},
    axis=1,
)
print(closes.pct_change().corr().round(2))

7. Save it

closes.to_parquet("closes.parquet")

Sample data

Try it now on a real sample

The free SEC fundamentals sample loads the same way. Download us-company-financials.zip from /sample-data and run:

Works today on the free sample.

import pandas as pd

fin = pd.read_csv("us-company-financials.csv", parse_dates=["period_end", "filed_date"])
rev = fin[fin["metric"] == "revenue"].pivot_table(index="period_end", columns="symbol", values="value")
print(rev.tail())

The file covers AAPL, MSFT, NVDA, AMZN, GOOGL, META, TSLA and JPM since 2023. Source: SEC EDGAR.

Watch out

Notes and gotchas

  • Keep timestamp in UTC for joins and resampling; convert only for display. Daily date columns have no time zone.
  • pd.DataFrame(body["results"]) on an empty list gives an empty frame with no columns. Check df.empty before indexing.
  • Large numbers such as volume arrive as JSON integers and load as int64. Fundamentals value fields can exceed 100 billion; that still fits.
  • The helper reads every page into memory. For tick data, write each page to disk instead (see pagination).
  • Respect the rate limits. The loop in step 6 makes one call per symbol; on the Free plan add time.sleep(12) between calls.

Keep reading

Next steps

Details

Was this page useful?

[Yes] [No]

Want an official Python client sooner? Tell us on the custom data form.