Python SDK for the PolyMach low-latency Polymarket engine
Project description
PolyMach SDK
polymach is the public Python SDK for the private optimized Rust PolyMach execution engine for Polymarket.
It is designed for persistent sessions driven by agentic, low-latency quantitative trading where every millisecond matters.
What it does:
- installs as a normal Python package with
uv add polymach - auto-downloads the correct signed runtime binary on first use
- verifies the release manifest and archive hash before launch
- caches the runtime locally
- talks to a persistent local session for low-latency calls
No local Rust toolchain or source checkout is required for normal use.
Performance Highlights
Measured on March 8, 2026 on the live BTC 5-minute market against the official polymarket-cli from the same machine:
- quote path: 3554.7x faster at p50
PolyMach:0.022 mspolymarket-clibook call:78.48 ms
- midpoint path: 3801.1x faster at p50
PolyMach:0.020 mspolymarket-climidpoint call:76.70 ms
- live discovery: 4.7x faster at p50
PolyMach:64.12 mspolymarket-clicomposite:300.46 ms
- account-health-equivalent path: 5.0x faster at p50
PolyMach:54.84 mspolymarket-clicomposite:271.84 ms
- order create: 6.6x faster at p50
PolyMach:28.60 mspolymarket-clicreate call:188.37 ms
- order cancel: 4.4x faster at p50
PolyMach:28.43 mspolymarket-clicancel call:124.31 ms
- stream cadence vs official polling: 1.5x faster at p50
PolyMach:51.15 mspolymarket-climidpoint polling:75.65 ms
Correctness checks passed in that run:
- market metadata parity
- quote parity within tolerance
- balance parity within tolerance
This speedup goes far beyond “SDK vs CLI subprocess”. The backend itself is built around a warmed local Rust runtime with a persistent session, hot quote paths, websocket-driven data, prewarming, cached order metadata, and many runtime and micro-optimizations across critical paths.
These benchmark numbers are a live snapshot from one host and network path. Treat them as directional measurements of the current implementation, not as a guaranteed venue-wide SLA.
Install
uv add polymach
Single-file agent-oriented reference:
Supported Machines And Builds
The SDK bootstrap picks the best matching signed runtime artifact optimized for the current machine from the public release catalog.
PolyMach ships signed native builds for each supported target family rather than one lowest-common-denominator binary.
Current release targets:
- Linux
x86_64with glibc baseline:x86_64-unknown-linux-gnu-v2 - Linux
x86_64with glibc and AVX2-class CPUs:x86_64-unknown-linux-gnu-v3 - Linux
x86_64with glibc and AVX-512-capable CPUs:x86_64-unknown-linux-gnu-v4 - Linux
aarch64with glibc:aarch64-unknown-linux-gnu - macOS
aarch64native Apple Silicon:aarch64-apple-darwin
Selection rules:
- on Linux
x86_64, the SDK detects the host CPU level and chooses the highest compatible build v4hosts can runv4,v3, orv2, but the SDK prefersv4v3hosts can runv3orv2, but notv4v2hosts use the broadest baseline build- on Linux
aarch64, the SDK selects the ARM64 Linux build - on macOS
aarch64, the SDK selects the native Apple Silicon build
These artifacts are built specifically for their target systems. Linux x86_64 is intentionally split into multiple optimized CPU tiers instead of shipping one generic x86 binary for all machines.
You can also force a specific published artifact with POLYMACH_ARTIFACT_ID, for example:
export POLYMACH_ARTIFACT_ID=x86_64-unknown-linux-gnu-v2
If you run on a target outside the published release set, provide a compatible local runtime binary with POLYMACH_BIN.
Recommended Payment Flow
A polymach machine license costs a flat 50 USDC per 30-day cycle per machine to use.
Agentic setup and payment is incredibly simple.
The recommended first-run flow is:
- create the client
- call
start() - if no license exists yet, send the exact Polygon payment returned by the SDK
- call
start(tx_hash=...)to activate the machine license
from polymach import PolyMach
engine = PolyMach()
start = engine.start()
if not start.ready:
payment = start.payment
print(payment.token_symbol, payment.amount_display)
print(payment.token_address)
raise SystemExit("Send the exact Polygon payment above, then call start(tx_hash=...)")
start = engine.start(tx_hash="0xYOUR_PAYMENT_TX_HASH")
print(start.license_status.valid)
Notes:
start()auto-downloads the runtime if needed.- The payment request is machine-specific.
- Follow the exact payment instructions returned by the SDK.
- After sending payment, allow up to 15 minutes for confirmation during Polygon network congestion before treating activation as stuck.
- If the payment is already broadcast, retry
start(tx_hash=...)with the same transaction hash once the network catches up. - Use
cycles=Nif you want to prepay multiple billing cycles in one transaction.
Automated Payment Flow
If you want the SDK to submit the Polygon payment itself, use pay_and_start().
from polymach import LocalAccountSigner, PaymentPendingError, PolyMach
engine = PolyMach()
signer = LocalAccountSigner.from_private_key("0xYOUR_PAYMENT_WALLET_PRIVATE_KEY")
try:
start = engine.pay_and_start(signer=signer)
except PaymentPendingError as exc:
start = engine.start(tx_hash=exc.tx_hash)
print(start.license_status.valid)
Notes:
- The payment wallet must hold the payment token on Polygon and a small amount of POL for gas.
- Prefer
signer=...over rawprivate_key=.... - If the payment transaction is broadcast but public RPC confirmation polling times out, the SDK raises
PaymentPendingErrorwith a recoverabletx_hash. - You can resume activation later with
start(tx_hash=...). - You can also resume through the same helper with
pay_and_start(tx_hash="0x..."). - Optional stuck-pending controls:
replacement_attemptsreplacement_gas_bump_percent
Live Trading
To place live orders on Polymarket, set the live-trading gate and trading credentials before starting the runtime.
Venue availability is separate from SDK availability. Runtime bootstrap, payment, and license activation can succeed even if Polymarket later blocks trading from the current IP address, network, or jurisdiction. Verify venue access from the actual deployment host before depending on live order flow.
Minimal environment for a normal EOA wallet:
export POLYMACH_LIVE_ENABLED=true
export POLYMACH_LIVE_ACK=I_UNDERSTAND_REAL_MONEY_RISK
export POLYMACH_POLYMARKET_PRIVATE_KEY=0xYOUR_TRADING_WALLET_PRIVATE_KEY
export POLYMACH_POLYMARKET_SIGNATURE_TYPE=0
Then:
from polymach import PolyMach
engine = PolyMach()
engine.prewarm(["TOKEN_ID"])
print(engine.market.quote("TOKEN_ID"))
For live order placement, the important variables are:
POLYMACH_LIVE_ENABLED=truePOLYMACH_LIVE_ACK=I_UNDERSTAND_REAL_MONEY_RISKPOLYMACH_POLYMARKET_PRIVATE_KEYPOLYMACH_POLYMARKET_SIGNATURE_TYPE0= EOA1= proxy2= Gnosis Safe
POLYMACH_POLYMARKET_FUNDERif the signer and funded trading address differ
If you use Polymarket API credentials, set all three together:
POLYMACH_POLYMARKET_API_KEYPOLYMACH_POLYMARKET_API_SECRETPOLYMACH_POLYMARKET_API_PASSPHRASE
Environment Variables
Most users do not need to set anything just to install the SDK.
Runtime And Bootstrap
POLYMACH_RELEASE_INDEX_URL: explicit signedindex.jsonURLPOLYMACH_RELEASE_BASE_URL: custom release base;"{version}"is supportedPOLYMACH_RELEASE_PUBLIC_KEY: override the embedded release verification keyPOLYMACH_BIN: force a specific local runtime binaryPOLYMACH_ARTIFACT_ID: force a specific release artifactPOLYMACH_RELEASE_TOKEN: optional bearer token for private/custom artifact mirrorsPOLYMACH_PERSISTENT=0: disable the persistent local session path
License And Payment
POLYMACH_LICENSE_BASE_URL: license/payment service base URLPOLYMACH_LICENSE_TOKEN: optional bearer token for the license servicePOLYMACH_POLYGON_RPC_URL: primary Polygon RPC overridePOLYMACH_POLYGON_RPC_URLS: optional comma-separated Polygon RPC fallback listPOLYMACH_WALLET_PRIVATE_KEY: advanced fallback payment wallet key forpay()/pay_and_start()POLYMACH_PAYMENT_GAS_LIMIT: optional ERC-20 transfer gas overridePOLYMACH_PAYMENT_GAS_PRICE_WEI: optional gas price overridePOLYMACH_PAYMENT_REPLACEMENT_ATTEMPTS: optional number of same-nonce replacement attempts for pending paymentsPOLYMACH_PAYMENT_REPLACEMENT_GAS_BUMP_PERCENT: optional gas-price bump percent for replacement attempts
Default Polygon RPC fallback order:
https://polygon.publicnode.com
https://1rpc.io/matic
https://polygon-rpc.com
Live Trading
POLYMACH_LIVE_ENABLEDPOLYMACH_LIVE_ACKPOLYMACH_POLYMARKET_PRIVATE_KEYPOLYMACH_POLYMARKET_SIGNATURE_TYPEPOLYMACH_POLYMARKET_FUNDERPOLYMACH_POLYMARKET_API_KEYPOLYMACH_POLYMARKET_API_SECRETPOLYMACH_POLYMARKET_API_PASSPHRASEPOLYMACH_POLYMARKET_HOSTPOLYMACH_POLYMARKET_CHAIN_IDPOLYMACH_POLYMARKET_GAMMA_API_URL
Security
- The Rust engine source is not included in this repo.
- Prefer a dedicated low-balance payment wallet for automated subscription payments.
- Keep private keys out of shell history, chat logs, and code.
License And Legal
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file polymach-0.1.1.tar.gz.
File metadata
- Download URL: polymach-0.1.1.tar.gz
- Upload date:
- Size: 520.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fb57e33c0b1dc7258ef7cac279788545a52821cb90f77435fcf7071f1aaa21b4
|
|
| MD5 |
8ace30ec34db714613c3196017e590b0
|
|
| BLAKE2b-256 |
9c7533791e022cc58ca1d4a0bcf5aa762ad673027b6f237addb6edea3d3734ee
|
File details
Details for the file polymach-0.1.1-py3-none-any.whl.
File metadata
- Download URL: polymach-0.1.1-py3-none-any.whl
- Upload date:
- Size: 31.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c53a3e6ef5dfa8f8a20a6c32ac83fac137dec815bd96fd402ee192fc43b39cff
|
|
| MD5 |
fefbecd0b61cc616a4c9bfc2fa3678d5
|
|
| BLAKE2b-256 |
a07c823e1a3c9e113fde52dad8e802e0b904230b25ebe8cbf050885298bcd278
|