polymarket-client 0.1.0b1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- polymarket_client-0.1.0b1/.claude/CLAUDE.md +3 -0
- polymarket_client-0.1.0b1/.editorconfig +11 -0
- polymarket_client-0.1.0b1/.env.example +20 -0
- polymarket_client-0.1.0b1/.gitignore +16 -0
- polymarket_client-0.1.0b1/.python-version +1 -0
- polymarket_client-0.1.0b1/.release-please-manifest.json +3 -0
- polymarket_client-0.1.0b1/CHANGELOG.md +5 -0
- polymarket_client-0.1.0b1/LICENSE +21 -0
- polymarket_client-0.1.0b1/PKG-INFO +168 -0
- polymarket_client-0.1.0b1/README.md +137 -0
- polymarket_client-0.1.0b1/pyproject.toml +104 -0
- polymarket_client-0.1.0b1/src/polymarket/__init__.py +260 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/__init__.py +0 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/actions/__init__.py +0 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/actions/_cursor.py +41 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/actions/account.py +239 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/actions/auth.py +118 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/actions/builders.py +68 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/actions/clob.py +272 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/actions/data.py +444 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/actions/gamma.py +706 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/actions/orders/__init__.py +0 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/actions/orders/_numeric.py +27 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/actions/orders/allowance.py +90 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/actions/orders/cancel.py +60 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/actions/orders/context.py +35 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/actions/orders/estimate.py +168 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/actions/orders/limit.py +173 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/actions/orders/market.py +244 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/actions/orders/market_data.py +186 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/actions/orders/math.py +48 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/actions/orders/orders.py +73 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/actions/orders/place.py +190 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/actions/orders/post.py +90 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/actions/orders/typed_data.py +198 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/actions/orders/types.py +54 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/actions/relayer/__init__.py +0 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/actions/relayer/auth.py +91 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/actions/relayer/calls.py +202 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/actions/relayer/deployed.py +36 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/actions/relayer/gasless.py +587 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/actions/relayer/nonce.py +64 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/actions/relayer/poll.py +99 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/actions/relayer/positions.py +125 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/actions/relayer/signing/__init__.py +0 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/actions/relayer/signing/deposit_wallet.py +96 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/actions/relayer/signing/proxy.py +59 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/actions/relayer/signing/safe.py +110 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/actions/relayer/submit.py +54 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/actions/rewards.py +305 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/context.py +61 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/data_params.py +25 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/dispatch.py +330 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/eoa/__init__.py +0 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/eoa/broadcast.py +165 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/eoa/rpc.py +234 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/gamma_paths.py +97 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/hmac.py +34 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/l1_auth.py +84 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/pagination.py +330 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/request.py +85 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/streams/__init__.py +0 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/streams/clob/__init__.py +0 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/streams/clob/heartbeat.py +62 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/streams/clob/market.py +209 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/streams/clob/market_protocol.py +124 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/streams/clob/user.py +213 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/streams/clob/user_protocol.py +96 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/streams/handle.py +134 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/streams/merged_handle.py +140 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/streams/reconnect.py +93 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/streams/registry.py +73 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/streams/rtds/__init__.py +0 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/streams/rtds/heartbeat.py +60 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/streams/rtds/manager.py +183 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/streams/rtds/protocol.py +145 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/streams/sports/__init__.py +0 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/streams/sports/heartbeat.py +69 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/streams/sports/manager.py +173 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/validation.py +29 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/wallet.py +229 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/ws/__init__.py +11 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/ws/backoff.py +25 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/ws/connection.py +263 -0
- polymarket_client-0.1.0b1/src/polymarket/_internal/ws/heartbeat.py +26 -0
- polymarket_client-0.1.0b1/src/polymarket/auth.py +42 -0
- polymarket_client-0.1.0b1/src/polymarket/calls.py +25 -0
- polymarket_client-0.1.0b1/src/polymarket/clients/__init__.py +8 -0
- polymarket_client-0.1.0b1/src/polymarket/clients/_transport.py +372 -0
- polymarket_client-0.1.0b1/src/polymarket/clients/async_public.py +1048 -0
- polymarket_client-0.1.0b1/src/polymarket/clients/async_secure.py +2083 -0
- polymarket_client-0.1.0b1/src/polymarket/clients/public.py +906 -0
- polymarket_client-0.1.0b1/src/polymarket/clients/secure.py +1934 -0
- polymarket_client-0.1.0b1/src/polymarket/environments.py +78 -0
- polymarket_client-0.1.0b1/src/polymarket/errors.py +53 -0
- polymarket_client-0.1.0b1/src/polymarket/models/__init__.py +203 -0
- polymarket_client-0.1.0b1/src/polymarket/models/base.py +40 -0
- polymarket_client-0.1.0b1/src/polymarket/models/clob/__init__.py +84 -0
- polymarket_client-0.1.0b1/src/polymarket/models/clob/_validators.py +217 -0
- polymarket_client-0.1.0b1/src/polymarket/models/clob/account.py +201 -0
- polymarket_client-0.1.0b1/src/polymarket/models/clob/api_key.py +14 -0
- polymarket_client-0.1.0b1/src/polymarket/models/clob/builder.py +68 -0
- polymarket_client-0.1.0b1/src/polymarket/models/clob/cancel.py +13 -0
- polymarket_client-0.1.0b1/src/polymarket/models/clob/last_trade.py +21 -0
- polymarket_client-0.1.0b1/src/polymarket/models/clob/market_events.py +224 -0
- polymarket_client-0.1.0b1/src/polymarket/models/clob/order_book.py +58 -0
- polymarket_client-0.1.0b1/src/polymarket/models/clob/order_response.py +124 -0
- polymarket_client-0.1.0b1/src/polymarket/models/clob/orders.py +31 -0
- polymarket_client-0.1.0b1/src/polymarket/models/clob/price_history.py +17 -0
- polymarket_client-0.1.0b1/src/polymarket/models/clob/relayer.py +105 -0
- polymarket_client-0.1.0b1/src/polymarket/models/clob/requests.py +13 -0
- polymarket_client-0.1.0b1/src/polymarket/models/clob/rewards.py +215 -0
- polymarket_client-0.1.0b1/src/polymarket/models/clob/user_events.py +171 -0
- polymarket_client-0.1.0b1/src/polymarket/models/data/__init__.py +72 -0
- polymarket_client-0.1.0b1/src/polymarket/models/data/activity.py +262 -0
- polymarket_client-0.1.0b1/src/polymarket/models/data/analytics.py +76 -0
- polymarket_client-0.1.0b1/src/polymarket/models/data/leaderboard.py +88 -0
- polymarket_client-0.1.0b1/src/polymarket/models/data/market_positions.py +52 -0
- polymarket_client-0.1.0b1/src/polymarket/models/data/portfolio.py +123 -0
- polymarket_client-0.1.0b1/src/polymarket/models/gamma/__init__.py +115 -0
- polymarket_client-0.1.0b1/src/polymarket/models/gamma/comment.py +127 -0
- polymarket_client-0.1.0b1/src/polymarket/models/gamma/common.py +425 -0
- polymarket_client-0.1.0b1/src/polymarket/models/gamma/event.py +502 -0
- polymarket_client-0.1.0b1/src/polymarket/models/gamma/market.py +502 -0
- polymarket_client-0.1.0b1/src/polymarket/models/gamma/profile.py +54 -0
- polymarket_client-0.1.0b1/src/polymarket/models/gamma/search.py +168 -0
- polymarket_client-0.1.0b1/src/polymarket/models/gamma/series.py +23 -0
- polymarket_client-0.1.0b1/src/polymarket/models/gamma/tag.py +23 -0
- polymarket_client-0.1.0b1/src/polymarket/models/rtds_events.py +237 -0
- polymarket_client-0.1.0b1/src/polymarket/models/sports_events.py +63 -0
- polymarket_client-0.1.0b1/src/polymarket/models/types.py +56 -0
- polymarket_client-0.1.0b1/src/polymarket/pagination.py +141 -0
- polymarket_client-0.1.0b1/src/polymarket/py.typed +0 -0
- polymarket_client-0.1.0b1/src/polymarket/streams/__init__.py +142 -0
- polymarket_client-0.1.0b1/src/polymarket/streams/_specs.py +218 -0
- polymarket_client-0.1.0b1/src/polymarket/transactions.py +108 -0
- polymarket_client-0.1.0b1/src/polymarket/types.py +9 -0
- polymarket_client-0.1.0b1/src/polymarket/version.py +8 -0
- polymarket_client-0.1.0b1/uv.lock +1234 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Copy this file to .env for local integration tests.
|
|
2
|
+
# Use disposable test credentials only. Never commit real secrets.
|
|
3
|
+
|
|
4
|
+
POLYMARKET_RUN_METERED_TESTS=0
|
|
5
|
+
POLYMARKET_PRIVATE_KEY=0xYOUR_TEST_PRIVATE_KEY
|
|
6
|
+
POLYMARKET_DEPOSIT_WALLET=0xYOUR_TEST_WALLET
|
|
7
|
+
POLYMARKET_PROXY_PRIVATE_KEY=0xYOUR_PROXY_PRIVATE_KEY
|
|
8
|
+
POLYMARKET_PROXY_WALLET=0xYOUR_PROXY_WALLET
|
|
9
|
+
POLYMARKET_SAFE_PRIVATE_KEY=0xYOUR_SAFE_PRIVATE_KEY
|
|
10
|
+
POLYMARKET_SAFE_WALLET=0xYOUR_SAFE_WALLET
|
|
11
|
+
POLYMARKET_TEST_API_KEY=
|
|
12
|
+
POLYMARKET_TEST_API_SECRET=
|
|
13
|
+
POLYMARKET_TEST_API_PASSPHRASE=
|
|
14
|
+
POLYMARKET_BUILDER_CODE=0xYOUR_BUILDER_CODE_BYTES32
|
|
15
|
+
POLYMARKET_BUILDER_API_KEY=YOUR_BUILDER_API_KEY
|
|
16
|
+
POLYMARKET_BUILDER_SECRET=YOUR_BUILDER_SECRET
|
|
17
|
+
POLYMARKET_BUILDER_PASSPHRASE=YOUR_BUILDER_PASSPHRASE
|
|
18
|
+
POLYMARKET_RELAYER_API_KEY=YOUR_RELAYER_API_KEY
|
|
19
|
+
POLYMARKET_RELAYER_API_KEY_ADDRESS=YOUR_RELAYER_API_KEY_ADDRESS
|
|
20
|
+
POLYMARKET_TEST_CONDITION_ID=0xYOUR_TEST_CONDITION_ID_BYTES32
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.11
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Polymarket
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: polymarket-client
|
|
3
|
+
Version: 0.1.0b1
|
|
4
|
+
Summary: Official Python client for Polymarket
|
|
5
|
+
Project-URL: Homepage, https://polymarket.com
|
|
6
|
+
Project-URL: Documentation, https://docs.polymarket.com
|
|
7
|
+
Project-URL: Repository, https://github.com/Polymarket/py-sdk
|
|
8
|
+
Project-URL: Issues, https://github.com/Polymarket/py-sdk/issues
|
|
9
|
+
Author-email: Polymarket Engineering <engineering@polymarket.com>
|
|
10
|
+
Maintainer-email: Polymarket Engineering <engineering@polymarket.com>
|
|
11
|
+
License: MIT
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: client,polymarket,prediction-markets,trading,web3
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Typing :: Typed
|
|
23
|
+
Requires-Python: >=3.11
|
|
24
|
+
Requires-Dist: eth-abi<6,>=5
|
|
25
|
+
Requires-Dist: eth-account<1,>=0.13
|
|
26
|
+
Requires-Dist: eth-utils<6,>=4
|
|
27
|
+
Requires-Dist: httpx[http2]<1,>=0.27
|
|
28
|
+
Requires-Dist: pydantic<3,>=2
|
|
29
|
+
Requires-Dist: websockets<16,>=13
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
# Polymarket Python SDK
|
|
33
|
+
|
|
34
|
+
Official Python SDK for Polymarket.
|
|
35
|
+
|
|
36
|
+
The SDK gives Python developers one coherent, workflow-oriented interface for building on Polymarket, starting with public data access and expanding toward authenticated account, trading, builder attribution, and relayer-backed workflows.
|
|
37
|
+
|
|
38
|
+
## Installation
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
uv add polymarket-client
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
or:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install polymarket-client
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Usage
|
|
51
|
+
|
|
52
|
+
Synchronous client:
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
from polymarket import Market, PublicClient
|
|
56
|
+
|
|
57
|
+
with PublicClient() as client:
|
|
58
|
+
market: Market = client.get_market(url="https://polymarket.com/event/example-market")
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Asynchronous client:
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
import asyncio
|
|
65
|
+
|
|
66
|
+
from polymarket import AsyncPublicClient, Market
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
async def main() -> None:
|
|
70
|
+
async with AsyncPublicClient() as client:
|
|
71
|
+
market: Market = await client.get_market(
|
|
72
|
+
url="https://polymarket.com/event/example-market"
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
asyncio.run(main())
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## API Design
|
|
80
|
+
|
|
81
|
+
See [SDK Direction](docs/sdk-direction.md) for public API design principles and developer-experience decisions.
|
|
82
|
+
|
|
83
|
+
## Development
|
|
84
|
+
|
|
85
|
+
Install dependencies:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
make sync
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Run checks:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
make check
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Build package artifacts:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
make build
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
The `Makefile` is a thin convenience wrapper around `uv`. Running the underlying commands directly is also fine.
|
|
104
|
+
|
|
105
|
+
## Testing
|
|
106
|
+
|
|
107
|
+
Unit tests run by default:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
make test
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Run unit tests in watch mode:
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
make test-watch
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
This runs the tests once immediately, then reruns them when Python files change.
|
|
120
|
+
|
|
121
|
+
Integration tests are opt-in:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
make test-integration
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Integration tests can load local secrets from a gitignored `.env` copied from `.env.example`:
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
cp .env.example .env
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
See `.env.example` for the supported local and CI secret names.
|
|
134
|
+
|
|
135
|
+
Tests that require credentials should use the `require_env` fixture so they skip when secrets are unavailable:
|
|
136
|
+
|
|
137
|
+
```python
|
|
138
|
+
import pytest
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
@pytest.mark.integration
|
|
142
|
+
def test_authenticated_flow(require_env):
|
|
143
|
+
private_key = require_env("POLYMARKET_PRIVATE_KEY")
|
|
144
|
+
builder_api_key = require_env("POLYMARKET_BUILDER_API_KEY")
|
|
145
|
+
|
|
146
|
+
assert private_key
|
|
147
|
+
assert builder_api_key
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
The SDK does not load `.env` files at runtime. The integration test fixture loads `.env` only for tests that request credentials, and existing environment variables take precedence over local `.env` values.
|
|
151
|
+
|
|
152
|
+
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:
|
|
153
|
+
|
|
154
|
+
```python
|
|
155
|
+
import pytest
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
@pytest.mark.integration
|
|
159
|
+
@pytest.mark.metered
|
|
160
|
+
def test_order_lifecycle(require_env):
|
|
161
|
+
private_key = require_env("POLYMARKET_PRIVATE_KEY")
|
|
162
|
+
|
|
163
|
+
assert private_key
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
POLYMARKET_RUN_METERED_TESTS=1 make test-integration
|
|
168
|
+
```
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# Polymarket Python SDK
|
|
2
|
+
|
|
3
|
+
Official Python SDK for Polymarket.
|
|
4
|
+
|
|
5
|
+
The SDK gives Python developers one coherent, workflow-oriented interface for building on Polymarket, starting with public data access and expanding toward authenticated account, trading, builder attribution, and relayer-backed workflows.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
uv add polymarket-client
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
or:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip install polymarket-client
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
Synchronous client:
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
from polymarket import Market, PublicClient
|
|
25
|
+
|
|
26
|
+
with PublicClient() as client:
|
|
27
|
+
market: Market = client.get_market(url="https://polymarket.com/event/example-market")
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Asynchronous client:
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
import asyncio
|
|
34
|
+
|
|
35
|
+
from polymarket import AsyncPublicClient, Market
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
async def main() -> None:
|
|
39
|
+
async with AsyncPublicClient() as client:
|
|
40
|
+
market: Market = await client.get_market(
|
|
41
|
+
url="https://polymarket.com/event/example-market"
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
asyncio.run(main())
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## API Design
|
|
49
|
+
|
|
50
|
+
See [SDK Direction](docs/sdk-direction.md) for public API design principles and developer-experience decisions.
|
|
51
|
+
|
|
52
|
+
## Development
|
|
53
|
+
|
|
54
|
+
Install dependencies:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
make sync
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Run checks:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
make check
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Build package artifacts:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
make build
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
The `Makefile` is a thin convenience wrapper around `uv`. Running the underlying commands directly is also fine.
|
|
73
|
+
|
|
74
|
+
## Testing
|
|
75
|
+
|
|
76
|
+
Unit tests run by default:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
make test
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Run unit tests in watch mode:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
make test-watch
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
This runs the tests once immediately, then reruns them when Python files change.
|
|
89
|
+
|
|
90
|
+
Integration tests are opt-in:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
make test-integration
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Integration tests can load local secrets from a gitignored `.env` copied from `.env.example`:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
cp .env.example .env
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
See `.env.example` for the supported local and CI secret names.
|
|
103
|
+
|
|
104
|
+
Tests that require credentials should use the `require_env` fixture so they skip when secrets are unavailable:
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
import pytest
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
@pytest.mark.integration
|
|
111
|
+
def test_authenticated_flow(require_env):
|
|
112
|
+
private_key = require_env("POLYMARKET_PRIVATE_KEY")
|
|
113
|
+
builder_api_key = require_env("POLYMARKET_BUILDER_API_KEY")
|
|
114
|
+
|
|
115
|
+
assert private_key
|
|
116
|
+
assert builder_api_key
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
The SDK does not load `.env` files at runtime. The integration test fixture loads `.env` only for tests that request credentials, and existing environment variables take precedence over local `.env` values.
|
|
120
|
+
|
|
121
|
+
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:
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
import pytest
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
@pytest.mark.integration
|
|
128
|
+
@pytest.mark.metered
|
|
129
|
+
def test_order_lifecycle(require_env):
|
|
130
|
+
private_key = require_env("POLYMARKET_PRIVATE_KEY")
|
|
131
|
+
|
|
132
|
+
assert private_key
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
POLYMARKET_RUN_METERED_TESTS=1 make test-integration
|
|
137
|
+
```
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.26"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "polymarket-client"
|
|
7
|
+
version = "0.1.0b1"
|
|
8
|
+
description = "Official Python client for Polymarket"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "Polymarket Engineering", email = "engineering@polymarket.com" },
|
|
14
|
+
]
|
|
15
|
+
maintainers = [
|
|
16
|
+
{ name = "Polymarket Engineering", email = "engineering@polymarket.com" },
|
|
17
|
+
]
|
|
18
|
+
keywords = ["polymarket", "prediction-markets", "client", "trading", "web3"]
|
|
19
|
+
classifiers = [
|
|
20
|
+
"Development Status :: 4 - Beta",
|
|
21
|
+
"Intended Audience :: Developers",
|
|
22
|
+
"License :: OSI Approved :: MIT License",
|
|
23
|
+
"Operating System :: OS Independent",
|
|
24
|
+
"Programming Language :: Python :: 3",
|
|
25
|
+
"Programming Language :: Python :: 3.11",
|
|
26
|
+
"Programming Language :: Python :: 3.12",
|
|
27
|
+
"Programming Language :: Python :: 3.13",
|
|
28
|
+
"Typing :: Typed",
|
|
29
|
+
]
|
|
30
|
+
dependencies = [
|
|
31
|
+
"eth-abi>=5,<6",
|
|
32
|
+
"eth-account>=0.13,<1",
|
|
33
|
+
"eth-utils>=4,<6",
|
|
34
|
+
"httpx[http2]>=0.27,<1",
|
|
35
|
+
"pydantic>=2,<3",
|
|
36
|
+
"websockets>=13,<16",
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
[project.urls]
|
|
40
|
+
Homepage = "https://polymarket.com"
|
|
41
|
+
Documentation = "https://docs.polymarket.com"
|
|
42
|
+
Repository = "https://github.com/Polymarket/py-sdk"
|
|
43
|
+
Issues = "https://github.com/Polymarket/py-sdk/issues"
|
|
44
|
+
|
|
45
|
+
[dependency-groups]
|
|
46
|
+
dev = [
|
|
47
|
+
"pytest>=8,<9",
|
|
48
|
+
"pytest-cov>=6,<7",
|
|
49
|
+
"respx>=0.22,<1",
|
|
50
|
+
"ruff>=0.11,<1",
|
|
51
|
+
"pyright>=1.1,<2",
|
|
52
|
+
"pytest-watcher>=0.6.3",
|
|
53
|
+
"python-dotenv>=1.2.2",
|
|
54
|
+
]
|
|
55
|
+
|
|
56
|
+
[tool.hatch.build]
|
|
57
|
+
exclude = [
|
|
58
|
+
"/.github",
|
|
59
|
+
"/.vscode",
|
|
60
|
+
"/dist",
|
|
61
|
+
"/docs",
|
|
62
|
+
"/tests",
|
|
63
|
+
"/AGENTS.md",
|
|
64
|
+
"/CONTRIBUTING.md",
|
|
65
|
+
"/release-please-config.json",
|
|
66
|
+
"/Makefile",
|
|
67
|
+
]
|
|
68
|
+
|
|
69
|
+
[tool.hatch.build.targets.wheel]
|
|
70
|
+
packages = ["src/polymarket"]
|
|
71
|
+
|
|
72
|
+
[tool.pytest.ini_options]
|
|
73
|
+
testpaths = ["tests"]
|
|
74
|
+
addopts = "--strict-markers"
|
|
75
|
+
markers = [
|
|
76
|
+
"integration: tests that call live Polymarket services or require credentials",
|
|
77
|
+
"metered: integration tests that require explicit opt-in because they may place orders, spend funds, or mutate live state",
|
|
78
|
+
]
|
|
79
|
+
|
|
80
|
+
[tool.ruff]
|
|
81
|
+
line-length = 100
|
|
82
|
+
target-version = "py311"
|
|
83
|
+
src = ["src", "tests"]
|
|
84
|
+
|
|
85
|
+
[tool.ruff.lint]
|
|
86
|
+
select = [
|
|
87
|
+
"E",
|
|
88
|
+
"F",
|
|
89
|
+
"I",
|
|
90
|
+
"UP",
|
|
91
|
+
"B",
|
|
92
|
+
"SIM",
|
|
93
|
+
]
|
|
94
|
+
|
|
95
|
+
[tool.ruff.format]
|
|
96
|
+
quote-style = "double"
|
|
97
|
+
indent-style = "space"
|
|
98
|
+
|
|
99
|
+
[tool.pyright]
|
|
100
|
+
include = ["src", "tests"]
|
|
101
|
+
pythonVersion = "3.11"
|
|
102
|
+
typeCheckingMode = "strict"
|
|
103
|
+
venvPath = "."
|
|
104
|
+
venv = ".venv"
|