Skip to main content

Polymarket Python SDK

Official Python SDK for Polymarket.

The SDK gives Python developers one coherent, workflow-oriented interface for building on Polymarket across public data, authenticated account, trading, builder attribution, and wallet workflows.

Installation

uv add polymarket-client

or:

pip install polymarket-client

Usage

Synchronous client:

from polymarket import Market, PublicClient

with PublicClient() as client:
    market: Market = client.get_market(url="https://polymarket.com/event/example-market")

Asynchronous client:

import asyncio

from polymarket import AsyncPublicClient, Market


async def main() -> None:
    async with AsyncPublicClient() as client:
        market: Market = await client.get_market(
            url="https://polymarket.com/event/example-market"
        )


asyncio.run(main())

Batch position merges:

# Merge regular market positions by condition or market id.
handle = client.merge_multiple_positions(
    positions=[
        {"condition_id": condition_id_1},
        {"market_id": market_id_2, "amount": "max"},
        {"condition_id": condition_id_3, "amount": 500_000},
    ],
)

outcome = handle.wait()

# Or merge combo positions by position id. Do not mix market and combo
# requests in the same batch.
handle = client.merge_multiple_positions(
    positions=[
        {"position_id": combo_position_id_1},
        {"position_id": combo_position_id_2, "amount": "max"},
        {"position_id": combo_position_id_3, "amount": 500_000},
    ],
)

outcome = handle.wait()

API Compatibility

The SDK follows semantic versioning. Although minor releases on the 0.x line may include breaking changes, we aim to avoid them and, whenever possible, provide a deprecation path before removing or changing an API. Patch releases remain backward compatible except for APIs marked experimental, which may change in any release. All Perps APIs are currently experimental, including client methods, sessions, stream subscriptions, and models.

Open order filters and fill tracking

When filtering open orders by asset, include the market condition ID:

orders = client.list_open_orders(asset_id=asset_id, market=condition_id)

The deprecated token_id alias also requires market. Unfiltered and market-only queries remain supported. Asset-only queries raise UserInputError when the paginator fetches a page. This applies to both sync and async clients.

associate_trades is deprecated and defaults to an empty tuple when absent. Use size_matched for an order's cumulative filled quantity, or list_account_trades() for individual fills, matching taker_order_id or maker_orders[].order_id to the order ID. An empty associate_trades tuple does not mean an order has no fills.

API Design

See SDK Direction for public API design principles and developer-experience decisions.

Development

Install dependencies:

make sync

Run checks:

make check

Build package artifacts:

make build

Build the Mintlify-compatible Sphinx JSON API-reference artifact:

make api-reference

The ZIP is written to build/api-reference/polymarket-client-sphinx.zip. The API Reference GitHub Actions workflow can also generate it manually for a selected branch or commit. Successful package releases attach a versioned copy to the corresponding GitHub Release.

The Makefile is a thin convenience wrapper around uv. Running the underlying commands directly is also fine.

Testing

Unit tests run by default:

make test

Run unit tests in watch mode:

make test-watch

This runs the tests once immediately, then reruns them when Python files change.

Integration tests are opt-in:

make test-integration

Integration tests can load local secrets from a gitignored .env copied from .env.example:

cp .env.example .env

See .env.example for the supported local and CI secret names.

Tests that require credentials should use the require_env fixture so they skip when secrets are unavailable:

import pytest


@pytest.mark.integration
def test_authenticated_flow(require_env):
    private_key = require_env("POLYMARKET_PRIVATE_KEY")
    builder_api_key = require_env("POLYMARKET_BUILDER_API_KEY")

    assert private_key
    assert builder_api_key

The SDK does not load .env files at runtime. Integration fixtures load .env for test configuration and credentials, and existing environment variables take precedence over local .env values.

Tests that place orders, spend funds, or mutate live state must also use @pytest.mark.metered. Metered tests are skipped unless POLYMARKET_RUN_METERED_TESTS=1 is set:

import pytest


@pytest.mark.integration
@pytest.mark.metered
def test_order_lifecycle(require_env):
    private_key = require_env("POLYMARKET_PRIVATE_KEY")

    assert private_key
POLYMARKET_RUN_METERED_TESTS=1 make test-integration

Contributing

We welcome bug reports, feature requests, and feedback through GitHub Issues. See CONTRIBUTING.md before proposing code changes.

Metadata

Release files for polymarket-client 0.20.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for polymarket-client 0.20.1
File Size Uploaded Provenance Actions
polymarket_client-0.20.1.tar.gz 467.9 kB With provenance Details for polymarket_client-0.20.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for polymarket-client 0.20.1
File Interpreter ABI Platform Actions
polymarket_client-0.20.1-py3-none-any.whl Python 3 none any Details for polymarket_client-0.20.1-py3-none-any.whl

Total release size: 898.1 kB

Release files / polymarket_client-0.20.1.tar.gz

Download URL polymarket_client-0.20.1.tar.gz
Size 467.9 kB
Tags Source
SHA-256 checksum
How to use checksums
aa33d6ba7ec9a4d510c8e6a564a5536220ff56087db20496b02e510e8c0299ef
BLAKE2b-256 checksum
How to use checksums
d1f41a7a9b23b41ec454e328f33c52f816e0a23d4c9bac898d882b74afe27187
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

Release files / polymarket_client-0.20.1-py3-none-any.whl

Download URL polymarket_client-0.20.1-py3-none-any.whl
Size 430.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
45109077df2b22aafb63879c4dbd292149de63bcadbefbc9686fd7cb71227997
BLAKE2b-256 checksum
How to use checksums
aec7b9975f0c80e88a8bedc939450eb9ec31ee76a49ae70b8b08697b32e5f4bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

Security for polymarket-client 0.20.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for polymarket_client-0.20.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.20.1 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page