Registry / http-networking / py-clob-client

py-clob-client

JSON →
library0.34.6pypypi✓ verified 23d ago

A Python client library for interacting with the Polymarket Central Limit Order Book (CLOB). It provides functionalities for trading, fetching market data, and managing orders on Polymarket's platform. The library is actively developed with frequent patch and minor releases, reflecting ongoing enhancements and bug fixes.

pip install py-clob-client
INSTALL
IMPORT
SIG · PY-CLOB-CLIENT
P
py-clob-client
http-networkingpythonv0.34.6
Install
9.2s avg
Import
6407ms
Disk
80MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.34.6 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 6.542s · 78.1MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 9.2s · import 6.272s · 81MB
80MB installed
● package 80MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ClobClient
from py_clob_client.client import ClobClient
POLYGON_CHAIN_ID
from py_clob_client.constants import POLYGON_CHAIN_ID

Initializes the ClobClient with a private key (for signing transactions) and an RPC URL. It then fetches and prints the first two available markets. Remember to manage your private key securely, preferably via environment variables.

import os from py_clob_client.client import ClobClient from py_clob_client.constants import POLYGON_CHAIN_ID from eth_account import Account # WARNING: Store private keys securely, e.g., in environment variables. # DO NOT hardcode private keys in production code. pk = os.environ.get('POLYMARKET_PRIVATE_KEY', '0x123...abc') # Replace with your actual private key or fetch from env rpc_url = os.environ.get('POLYMARKET_RPC_URL', 'https://rpc.ankr.com/polygon_mumbai') # Or your preferred RPC endpoint if not pk.startswith('0x'): raise ValueError("Private key must start with '0x'") wallet = Account.from_key(pk) clob_client = ClobClient( wallet=wallet, rpc_url=rpc_url, chain_id=POLYGON_CHAIN_ID, ) try: markets = clob_client.get_markets() print(f"Successfully fetched {len(markets)} markets:") for market in markets[:2]: # Print first 2 markets for brevity print(f" - {market.title} (ID: {market.market_id})") except Exception as e: print(f"Error fetching markets: {e}") print("Please ensure your RPC URL and private key are correct and active.")
Debug
Known issues
breakingThe RFQ quotes endpoint was split into distinct requester and quoter views. Direct calls to the old unified endpoint for RFQ quotes will break.
fix
Update your code to use `get_rfq_requester_quotes()` or `get_rfq_quoter_quotes()` as appropriate for your application logic.
affects: >=0.34.5
breakingThe logic for RFQ requester orders was changed to invert the price. This directly affects how prices are interpreted when a requester is creating an RFQ.
fix
Review your RFQ requester order creation logic to account for the inverted price interpretation in `v0.34.0` and later versions. Incorrect price usage could lead to unintended trade execution.
affects: >=0.34.0
gotchaThe `ClobClient` requires a valid private key (for transaction signing) and an RPC URL for the Polygon network. Using an incorrect private key, an inactive key, or an invalid/unresponsive RPC URL will lead to authentication or connection errors.
fix
Ensure your `POLYMARKET_PRIVATE_KEY` environment variable holds a valid, active private key for a Polygon wallet. Verify your `POLYMARKET_RPC_URL` points to a working Polygon RPC endpoint (e.g., Ankr, Alchemy, Infura).
affects: All versions
gotchaThe library undergoes frequent updates and bug fixes. While beneficial, this can occasionally introduce subtle behavioral changes or new requirements for certain API calls, especially for advanced features like 'Post Only Orders' or 'HeartBeats'.
fix
Regularly check the GitHub releases and changelog for significant updates, especially before upgrading across minor versions. Test your integration thoroughly after updates.
affects: All versions
Errors
Common errors & fixes
PolyApiException[status_code=401, error_message={'error': 'Unauthorized/Invalid api key'}]
This error commonly occurs when authentication details like the private key, API keys, chain ID, signature type, or funder address are incorrectly configured or missing, especially for trading operations requiring Level 2 authentication, or due to signature serialization mismatches in older versions of the client.
fix
Ensure `ClobClient` is initialized with the correct `host`, `private_key`, `chain_id` (137 for Polygon mainnet), and the appropriate `signature_type` (0 for EOA/MetaMask, 1 for email/Magic wallet, 2 for browser wallet proxies/Safe). For proxy wallets, explicitly provide the `funder` address. Always call `client.set_api_creds(client.create_or_derive_api_creds())` after client initialization to enable Level 2 authentication for trading. Verify API keys are correctly set in environment variables or passed directly.
ModuleNotFoundError: No module named 'py_builder_signing_sdk'
The `py-clob-client` library depends on `py_builder_signing_sdk` for certain functionalities, and this dependency might not be automatically installed or is missing from the Python environment.
fix
Manually install the missing dependency using pip: `pip install py_builder_signing_sdk`.
AttributeError: 'NoneType' object has no attribute 'signature_type'
This specific `AttributeError` occurs in methods like `get_balance_allowance` or `update_balance_allowance` when a `params` object (expected to be `BalanceAllowanceParams`) is not provided or is `None`, and the method attempts to access its attributes.
fix
Always pass a `BalanceAllowanceParams` object to `get_balance_allowance` and `update_balance_allowance`, ensuring that required attributes like `signature_type` are properly set within it. For example, `client.get_balance_allowance(BalanceAllowanceParams(signature_type=YOUR_SIGNATURE_TYPE))`.
PolyApiException[status_code=400, error_message={'error': 'order X is invalid. Size (Y) lower than the minimum: Z'}]
This is a common order validation error indicating that the submitted order violates market rules, such as minimum order size, invalid price range, or insufficient balance/allowance for the specified market.
fix
Before placing an order, query market data to retrieve the valid `tick_size`, `min_order_size`, and acceptable price ranges using methods like `client.get_order_book(token_id)` or `client.get_markets()`. Ensure the trading wallet has sufficient balance and, for EOA/MetaMask users, that necessary token allowances are set for the Polymarket contracts.
Upgrade
Version history
0.34.6latest on PyPI · released Feb 19, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
57 hits · last 30 days
node
50
Resources
py-clob-client — pip install py-clob-client · libregistry