Skip to main content

Python SDK for Polymarket APIs (CLOB, Gamma, Data) — powered by Rust

Project description

Polyoxide

Python SDK for Polymarket APIs, powered by Rust via PyO3 and maturin.

Every client comes in async and sync variants. Async methods return Python awaitables; sync methods block via an internal Tokio runtime and release the GIL while waiting.

Async Sync API Description
Gamma GammaSync Gamma Market data, events, series, tags, comments, sports, search, users
ClobClient ClobClientSync CLOB Order book, prices, spreads, trade history, fee rates
DataApi DataApiSync Data User positions/trades/activity, leaderboard, holders, volume, open interest

Installation

pip install polyoxide

Wheels are published for Linux (x86_64, aarch64), macOS (x86_64, aarch64), and Windows (x86_64).

Quick Start

Async (Gamma -- market data)

import asyncio
from polyoxide import Gamma

async def main():
    gamma = Gamma()
    markets = await gamma.markets().list(limit=5, open=True)
    for m in markets:
        print(f"{m.question}  --  {m.slug}")

asyncio.run(main())

Sync (Gamma)

from polyoxide import GammaSync

gamma = GammaSync()
markets = gamma.markets().list(limit=5, open=True)
for m in markets:
    print(f"{m.question}  --  {m.slug}")

CLOB (order book data)

from polyoxide import ClobClientSync

clob = ClobClientSync()
book = clob.markets().order_book("TOKEN_ID")
print(book.bids, book.asks)

spread = clob.markets().spread("TOKEN_ID")
print(spread)

Data API (user positions and leaderboard)

import asyncio
from polyoxide import DataApi

async def main():
    data = DataApi()

    # Leaderboard
    leaders = await data.leaderboard().get(limit=10, time_period="WEEK")
    for t in leaders:
        print(t.username, t.pnl)

    # User positions
    positions = await data.user("0xADDRESS").list_positions(limit=5)
    for p in positions:
        print(p.title, p.size)

asyncio.run(main())

Client API Reference

Gamma / GammaSync

Constructed with optional base_url, timeout_ms, and pool_size keyword arguments.

Namespace Methods
.markets() get(id), get_by_slug(slug), list(...), tags(id)
.events() get(id), get_by_slug(slug), list(...), get_related_by_slug(slug), tags(id), tweet_count(id), comment_count(id)
.series() get(id), list(...)
.tags() get(id), get_by_slug(slug), list(...), get_related(id), get_related_by_slug(slug)
.comments() get(id), list(...), by_user(address)
.sports() list(), market_types(), list_teams(...)
.search() public_search(query, ...)
.user() get(address)
.health() ping()

ClobClient / ClobClientSync

No arguments required (uses public/unauthenticated endpoints).

Namespace Methods
.markets() get(condition_id), get_by_token_ids(token_ids), list(), order_book(token_id), price(token_id, side), midpoint(token_id), prices_history(token_id), neg_risk(token_id), fee_rate(token_id), tick_size(token_id), spread(token_id), last_trade_price(token_id), live_activity(condition_id), simplified(), sampling(), sampling_simplified(), calculate_price(token_id, side, amount)
.health() ping(), server_time()

DataApi / DataApiSync

Constructed with optional base_url, timeout_ms, and pool_size keyword arguments.

Namespace Methods
.user(address) list_positions(...), positions_value(...), closed_positions(...), trades(...), activity(...), traded()
.trades() list(...)
.holders() list(markets, ...)
.open_interest() get(...)
.live_volume() get(event_id)
.leaderboard() get(...)
.builders() leaderboard(...), volume(...)
.health() ping()

Result Objects

All response objects expose named properties matching the upstream JSON fields, plus:

  • .to_dict() -- convert to a plain Python dict
  • str(obj) -- JSON string representation
  • repr(obj) -- type-annotated representation

Error Handling

All exceptions inherit from PolyoxideError:

from polyoxide import PolyoxideError, ApiError, RateLimitError

try:
    markets = gamma.markets().list()
except RateLimitError:
    print("slow down")
except ApiError as e:
    print(f"API error: {e}")
except PolyoxideError as e:
    print(f"something else: {e}")
Exception When
ApiError API returned an error response
AuthenticationError Invalid or missing credentials
ValidationError Request parameters failed validation
RateLimitError Rate limit exceeded (HTTP 429)
NetworkError Connection failure
TimeoutError Request timed out

Async Support

Async clients (Gamma, ClobClient, DataApi) use pyo3-async-runtimes to bridge Rust futures into Python awaitables. They work with asyncio.run(), await, and any asyncio-compatible event loop.

Sync clients (GammaSync, ClobClientSync, DataApiSync) execute on a shared background Tokio runtime and release the GIL while blocking, so they are safe to use from threaded Python code.

Type Stubs

A .pyi stub file is included at python/polyoxide/__init__.pyi for editor autocomplete and type checking.

Building from Source

Requires Rust and Python 3.8+.

pip install maturin
maturin develop --release

License

Licensed under either of MIT or Apache-2.0 at your option.

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

polyoxide-0.12.5.tar.gz (187.8 kB view details)

Uploaded Source

Built Distributions

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

polyoxide-0.12.5-cp39-abi3-win_amd64.whl (3.5 MB view details)

Uploaded CPython 3.9+Windows x86-64

polyoxide-0.12.5-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64

polyoxide-0.12.5-cp39-abi3-macosx_11_0_arm64.whl (3.0 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

polyoxide-0.12.5-cp39-abi3-macosx_10_12_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

Details for the file polyoxide-0.12.5.tar.gz.

File metadata

  • Download URL: polyoxide-0.12.5.tar.gz
  • Upload date:
  • Size: 187.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.13.1

File hashes

Hashes for polyoxide-0.12.5.tar.gz
Algorithm Hash digest
SHA256 f19e57f67e5c4bd6aafcc77979bf9f99508199b45e5cf13ed5bc15ec11bca20f
MD5 4e1f7b9abe06ecd08c7f17cbe9c383f8
BLAKE2b-256 605119168e49f7f1636ac771dcec92833a52019951b800176689592340985eb0

See more details on using hashes here.

File details

Details for the file polyoxide-0.12.5-cp39-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for polyoxide-0.12.5-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 9ca71e889bd0c52f39de72c9d9bff37efd5cd835144bdb2a252812103fd2004d
MD5 1b163cda3bae7ff7b8f37060de141545
BLAKE2b-256 7836ffd906cb273f6f60fbbed54c8a595d8223f5c8f9ba4e559dd67931e379d3

See more details on using hashes here.

File details

Details for the file polyoxide-0.12.5-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for polyoxide-0.12.5-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 38b8d6e53c46b1e6929fd8d83f8927d8f9bd4a900bab4508e1f22ea858d66dfd
MD5 a34ad28caac0f1b0778d97152bdc1a93
BLAKE2b-256 a0ab1e2ecd328cf029252774dedcbd01e304c6c788c8b0571f6097980931dd06

See more details on using hashes here.

File details

Details for the file polyoxide-0.12.5-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for polyoxide-0.12.5-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 33376c467b809ae3723200c1e77d77b059d86f0248de1417e3feef27b853487b
MD5 4b709444a19f99113a0aa65b91bb6383
BLAKE2b-256 1cb244bd3a5f006d49743653e92268a30edf25d928484c227c48b9ac15c77d94

See more details on using hashes here.

File details

Details for the file polyoxide-0.12.5-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for polyoxide-0.12.5-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 997a3e8c2fc8353b36f21439d261fa9af98bfc96eedc89b0699f646b67eed9aa
MD5 6b778d9c05269c877158b871ed36f231
BLAKE2b-256 04c93ee5ec56d872e5b6fde6f651a4b69a1ba9b632552ffb581d939fc5e1a32e

See more details on using hashes here.

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