DataFrames¶
Page[T] carries .to_dataframe() (pandas) and .to_polars() (polars).
Neither library is a hard dependency.
Install¶
pip install 'kalshi-sdk[pandas]'
# or
pip install 'kalshi-sdk[polars]'
# or both
pip install 'kalshi-sdk[all]'
Calling either method without the corresponding library installed raises
ImportError with the exact pip install hint.
Quick example¶
df = client.markets.list(status="open", limit=500).to_dataframe()
print(df[["ticker", "yes_bid", "yes_ask", "volume_24h"]].head())
How it works¶
Both methods walk page.items and call item.model_dump(mode="python") on
each, then hand the records to pd.DataFrame(...) / pl.DataFrame(...).
This means:
-
DecimalstaysDecimal. Prices come through as Decimals in a pandas object-dtype column. Cast to float yourself if you want numeric ops: -
datetimestaysdatetime. Timestamp fields are real datetimes, not ISO strings. -
Nested models become nested structures. A
Candlestickrow hasyes_bid: BidAskDistribution(aBaseModel). Aftermodel_dump, that field becomes adict. Polars infers a struct; pandas keeps it as an object column.
One page only¶
Both methods convert the current page, not every page across cursors. To flatten a multi-page result into one frame:
import pandas as pd
from kalshi import KalshiClient
with KalshiClient.from_env() as client:
rows = list(client.orders.list_all(status="resting"))
df = pd.DataFrame([o.model_dump(mode="python") for o in rows])
list_all() returns the items already unwrapped (not Page objects), so you
work with BaseModels directly.
Async¶
The async client's list_all() returns an AsyncIterator[T]. Materialize it
once before converting:
import asyncio
import polars as pl
from kalshi import AsyncKalshiClient
async def collect() -> list:
async with AsyncKalshiClient.from_env() as c:
return [o async for o in c.orders.list_all(status="resting")]
rows = asyncio.run(collect())
df = pl.DataFrame([o.model_dump(mode="python") for o in rows])
Reference¶
kalshi.models.common.Page.to_dataframe ¶
Return page items as a pandas DataFrame (requires kalshi-sdk[pandas]).
kalshi.models.common.Page.to_polars ¶
Return page items as a polars DataFrame (requires kalshi-sdk[polars]).