> ## Documentation Index
> Fetch the complete documentation index at: https://docs.entityml.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Python SDK

> Use the official EntityML Python SDK for Polymarket and Kalshi market data.

## Overview

The EntityML Python SDK wraps the EntityML Market Data API and provides typed method groups for:

* API keys
* Polymarket market data
* Kalshi market data
* Lookup utilities
* Billing and usage
* User and system analytics
* Health checks

SDK repository:

* [github.com/anaygupta2004/entityml](https://github.com/anaygupta2004/entityml)

## Install

Use one of these install methods:

<CodeGroup>
  ```bash pip (recommended) theme={null}
  python3 -m pip install --upgrade entityml
  ```

  ```bash latest from GitHub theme={null}
  python3 -m pip install --upgrade "git+https://github.com/anaygupta2004/entityml.git"
  ```

  ```bash download with cURL theme={null}
  curl -L https://github.com/anaygupta2004/entityml/archive/refs/heads/main.tar.gz -o entityml.tar.gz
  tar -xzf entityml.tar.gz
  python3 -m pip install ./entityml-main
  ```

  ```bash local checkout (development) theme={null}
  pip install -e /path/to/entityml
  ```
</CodeGroup>

For CLI + SDK usage from the terminal, see [CLI](/cli).

## Initialize client

```python theme={null}
from entityml import EntityMLClient

client = EntityMLClient(
    api_key="YOUR_API_KEY",
    base_url="https://api.entityml.com",  # /api/v1 is added automatically
)
```

## Polymarket example

```python theme={null}
markets = client.polymarket.list_markets(prefix="0x8213", limit=5)
availability = client.polymarket.get_market_date_range(
    condition_id="0x8213d395e079614d6c4d7f4cbb9be9337ab51648a21cc2a334ae8f1966d164b4",
)

market_data = client.polymarket.get_market_data(
    condition_id="0x8213d395e079614d6c4d7f4cbb9be9337ab51648a21cc2a334ae8f1966d164b4",
    date="2026-02-13",
    offset=0,
    limit=500,
)

market_range = client.polymarket.get_market_data_range(
    condition_id="0x8213d395e079614d6c4d7f4cbb9be9337ab51648a21cc2a334ae8f1966d164b4",
    start_timestamp=1770940800000,
    end_timestamp=1770944400000,
    limit=500,
)

summary = client.polymarket.get_orderbook_summary(
    condition_id="0x8213d395e079614d6c4d7f4cbb9be9337ab51648a21cc2a334ae8f1966d164b4",
    asset_id="97684905927345553455494278582909124912046930226695064344571162061840768197777",
    start_timestamp=1770940800000,
    end_timestamp=1770944399999,
    resolution=60,
)
```

## Kalshi example

```python theme={null}
kalshi_markets = client.kalshi.list_markets(prefix="KXBTC", limit=5)
kalshi_availability = client.kalshi.get_market_date_range(
    ticker="KXBTC-26FEB2606-B60125",
)

kalshi_data = client.kalshi.get_market_data(
    ticker="KXBTC-26FEB2606-B60125",
    date="2026-02-26",
    offset=0,
    limit=500,
)

kalshi_range = client.kalshi.get_market_data_range(
    ticker="KXBTC-26FEB2606-B60125",
    start_timestamp=1772103600000,
    end_timestamp=1772107200000,
    limit=500,
)

kalshi_summary = client.kalshi.get_orderbook_summary(
    ticker="KXBTC-26FEB2606-B60125",
    start_timestamp=1772103600000,
    end_timestamp=1772107199999,
    resolution=60,
)
```

## API keys example

```python theme={null}
created = client.api_keys.create(name="my-key", user_id="YOUR_USER_ID")
keys = client.api_keys.list(user_id="YOUR_USER_ID")
last_used = client.api_keys.get_last_used(key_id="KEY_UUID")
name = client.api_keys.get_name(key_id="KEY_UUID")
```

## Utilities, billing, and analytics

```python theme={null}
lookup = client.lookup.polymarket_slug(slug="will-bitcoin-hit-100k")
usage = client.billing.get_usage(user_id="YOUR_USER_ID")
subscription = client.billing.get_subscription_status(user_id="YOUR_USER_ID")
popular = client.analytics.get_popular_markets(limit=10, days=7)
recent = client.analytics.get_user_recent_requests(user_id="YOUR_USER_ID", limit=5)
monitoring = client.system.monitoring_status()
```

## Error handling

```python theme={null}
from entityml import EntityMLAPIError, EntityMLAuthError

try:
    health = client.system.health()
except EntityMLAuthError as err:
    print("Auth failed:", err.detail)
except EntityMLAPIError as err:
    print("Request failed:", err.status_code, err.detail)
```

## Notes

* Market data endpoints require an API key.
* Historical coverage is source-specific.
* Orderbook data exists for a subset of markets from `2025-09-01` on Polymarket and `2026-02-17` for Kalshi, but coverage is not continuous.
* Broad Polymarket crypto-related market coverage begins on `2026-02-04`. Broad Kalshi crypto-related market coverage begins on `2026-02-25`.
* Broad all-market capture begins on `2026-04-02` for Polymarket and `2026-03-31` for Kalshi, with known April 2026 quality exceptions.
* Use the Polymarket and Kalshi date-range endpoints to confirm per-market availability.
* See [Data Quality](/data-quality) before depending on April 2026 data.
