Skip to main content

Typed Python client for the Polymarket API: read Gamma markets, snapshot and stream the CLOB order book, and place orders. Built by antflow.

Project description

Polymarket API client for Python

A small, typed Python toolkit for the Polymarket API. Read markets from the Gamma API, snapshot and stream the Polymarket CLOB order book, generate idempotent client order ids, and place orders through Polymarket's official client (py-clob-client).

It wraps Polymarket's public CLOB and Gamma APIs. The read / stream / analytics surface needs only httpx and websockets and no API key. Order placement is opt-in.

Python License: MIT

pip install polymarket-api-python

30-second quickstart

Read the most-active market right now and check its order book — no credentials required:

from polymarket_api import GammaClient, fetch_order_book

with GammaClient() as gamma:
    # Markets sorted by 24h volume; grab the busiest one.
    market = next(iter(gamma.iter_markets(max_markets=1)))

print(market.question)

book = fetch_order_book(market.yes_token_id)
print(f"YES  bid={book.best_bid}  ask={book.best_ask}  spread={book.spread_bps:.0f} bps")
print(f"depth within 5% of mid:  bid={book.bid_depth_5pct}  ask={book.ask_depth_5pct}")
Will <…> happen by <…>?
YES  bid=0.62  ask=0.63  spread=160 bps
depth within 5% of mid:  bid=4210.0  ask=3880.0

What it does

Module What it gives you Needs
polymarket_api.gamma Typed market reader: pagination that handles the silent limit=100 clamp, and auto-decoding of the JSON-string fields (outcomes, outcomePrices, clobTokenIds) httpx
polymarket_api.orderbook OrderBookSnapshot with computed spread, spread (bps), mid, depth-within-5%, and total resting liquidity — not just the raw ladder httpx
polymarket_api.ws A resilient CLOB WebSocket subscriber: auto-reconnect, PING/PONG keepalive, a stale-feed watchdog, and typed events websockets
polymarket_api.client_order_id Deterministic client order ids for idempotent, retry-safe submission stdlib
polymarket_api.orders Thin, optional wrapper over Polymarket's official client for signing + placing + cancelling orders [trading] extra

Stream live prices

import asyncio
from polymarket_api import ClobWebSocketClient, PriceChange

async def main():
    client = ClobWebSocketClient()

    async def on_event(event):
        if isinstance(event, PriceChange):
            print(event.token_id[:12], event.best_bid, event.best_ask)

    # Runs forever, reconnecting as needed. Ctrl-C to stop.
    await client.run(["<clob_token_id>"], on_event)

asyncio.run(main())

Place an order (optional)

Order placement is opt-in and pulls in Polymarket's official, audited client, which performs all EIP-712 signing:

pip install "polymarket-api-python[trading]"
import os
from polymarket_api.orders import make_trading_client, place_limit_order

client = make_trading_client(os.environ["POLYMARKET_PRIVATE_KEY"])  # derives L2 creds for you
place_limit_order(client, token_id="<clob_token_id>", price=0.40, size=20, side="BUY")

This package never implements signing itself — see docs/sign-and-place-an-order.md.

Docs / Cookbook

Task-oriented, code-first recipes — each is a runnable snippet plus the gotchas that bite in production:

Install from source

git clone https://github.com/antflow-live/polymarket-api-python
cd polymarket-api-python
pip install -e ".[dev]"
pytest

About antflow

This toolkit is maintained by antflow — an autonomous trading bot for Polymarket. antflow scans prediction markets, applies operator-defined risk controls, and executes and monitors trades automatically. We open-sourced the generic API plumbing we rely on so other Polymarket developers don't have to rebuild it.

Disambiguation: this is antflow — Polymarket trading. It is unrelated to antflow.ai and to the AntFlow workflow-engine projects that share the name.

Disclaimer

This is developer tooling for the Polymarket API, provided for educational and informational purposes only. It is not financial advice and makes no representation about trading outcomes or profitability. Prediction-market trading carries risk. Comply with Polymarket's terms and the laws of your jurisdiction. Use at your own risk; see the MIT License for warranty terms.

License

MIT © 2026 antflow

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

polymarket_api_python-0.1.0.tar.gz (30.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

polymarket_api_python-0.1.0-py3-none-any.whl (18.7 kB view details)

Uploaded Python 3

File details

Details for the file polymarket_api_python-0.1.0.tar.gz.

File metadata

  • Download URL: polymarket_api_python-0.1.0.tar.gz
  • Upload date:
  • Size: 30.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for polymarket_api_python-0.1.0.tar.gz
Algorithm Hash digest
SHA256 92e59e16e7ddc9247e02bce4d272b5a2c8388fe200d195913b7401742bad45d8
MD5 fcfc83d720dacbb07e6236f9f039dc3c
BLAKE2b-256 96132ecbf10365ead58946b477ed245121847ce6de6099d071a7e4808fcd50e9

See more details on using hashes here.

Provenance

The following attestation bundles were made for polymarket_api_python-0.1.0.tar.gz:

Publisher: publish.yml on antflow-live/polymarket-api-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file polymarket_api_python-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for polymarket_api_python-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 654aebc60f5069986db0e8382774337cfa786a29d825fc505579b7ece68f336e
MD5 224f025a67723f6f23fd5ee3a859985b
BLAKE2b-256 022fab0aa8912446921e2678802c25cd5355f62c29d5fac35c951fbad17ebaf2

See more details on using hashes here.

Provenance

The following attestation bundles were made for polymarket_api_python-0.1.0-py3-none-any.whl:

Publisher: publish.yml on antflow-live/polymarket-api-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page