Python SDK for the Worm prediction markets platform
Project description
worm-sdk
Official Python client for the Worm prediction markets API.
Features
- Full coverage of the Worm REST API — markets, events, search, spot orders, margin, redeems, and account data
- Typed responses with Pydantic models
- HMAC authentication for private endpoints
- Optional Solana wallet signing for order, margin, and redeem flows
- Cursor-based pagination helpers
- HTTP/2 via httpx
Requirements
- Python 3.10 or later
Installation
pip install worm-sdk
Install from source:
git clone https://github.com/wormwtf/worm-sdk.git
cd worm-sdk
pip install -e .
For wallet signing (orders, margin, redeems):
pip install "worm-sdk[signing]"
Quickstart
Fetch public market data — no credentials required:
from worm_sdk import WormClient
with WormClient() as client:
page = client.markets.list(sort="trending", limit=5)
for market in page.items:
print(market.title, market.condition_id)
Authentication
Worm uses HMAC-signed API keys. Create a key once with a Solana wallet, then reuse the key and secret for all authenticated calls.
from worm_sdk import WormClient
from worm_sdk.auth import SolanaWalletSigner
# One-time setup — store the returned credentials securely
signer = SolanaWalletSigner("YOUR_SOLANA_PRIVATE_KEY")
credentials = WormClient.create_api_key(signer)
# Authenticated client
client = WormClient(
api_key=credentials.api_key,
api_secret=credentials.secret,
signer=signer, # optional; needed for place/redeem/open_position helpers
)
profile = client.account.get_summary()
print(profile.username)
SolanaWalletSigner accepts a base58 string, 128-character hex keypair, or raw 64-byte keypair bytes. You can also provide any object that implements SignerProtocol (Ledger, KMS, etc.).
Set credentials via environment variables when running the examples:
export WORM_API_KEY="..."
export WORM_API_SECRET="..."
export WORM_PRIVATE_KEY="..." # only for signing flows
Usage
WormClient exposes namespaced APIs:
| Namespace | Auth | Description |
|---|---|---|
client.markets |
— | Market listings, order books, candles, prices, trades |
client.events |
— | Event listings and detail |
client.search |
— | Search markets and events |
client.sports |
— | Sports and league catalog |
client.orders |
✓ | Spot order lifecycle |
client.trades |
✓ | Your trade history |
client.account |
✓ | Profile, portfolio, P&L |
client.margin |
✓ / — | Margin estimate (public); positions, requests, settlements |
client.redeems |
✓ | Redeem resolved positions |
client.api_keys |
✓ | List and revoke API keys |
List endpoints return a CursorPage[T] with items, next_cursor, and limit:
page = client.markets.list(limit=20)
while page.next_cursor:
page = client.markets.list(limit=20, cursor=page.next_cursor)
Convenience methods combine draft, sign, and submit in one call when a signer is configured:
from worm_sdk import OrderSide, OrderType
client.orders.place(
market_condition_id="...",
is_yes=True,
side=OrderSide.BUY,
order_type=OrderType.LIMIT,
amount="10",
price="0.55",
)
See the examples/ directory for complete scripts covering markets, orders, margin, redeems, and more.
Error handling
from worm_sdk import AuthenticationRequired, WormAPIError
try:
client.orders.list(limit=1)
except WormAPIError as exc:
print(exc.error_code, exc.slug, exc.message)
except AuthenticationRequired:
print("Pass api_key and api_secret to WormClient")
Configuration
client = WormClient(
api_key="...",
api_secret="...",
base_url="https://api.worm.wtf", # default
timeout=30.0,
signer=signer,
)
Inspect rate limits and response metadata on client.last_response after each request.
Development
pip install -e ".[dev,signing]"
pytest
ruff check .
mypy src
Build locally:
python -m build
Releases are published to PyPI automatically when you push a version tag (e.g. v0.9.0) or publish a GitHub Release. Set the PYPI_API_TOKEN repository secret first.
Links
License
MIT — see LICENSE.
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 worm_sdk-0.9.0.tar.gz.
File metadata
- Download URL: worm_sdk-0.9.0.tar.gz
- Upload date:
- Size: 37.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
636b3761dedf16cc666f5bcc6dfc4d04b223a05b76ac95437618af77813dcf2b
|
|
| MD5 |
e79950c8ca98d8965d1d5cb4bf16f305
|
|
| BLAKE2b-256 |
2424b4201d78a091a59891ccd8f353cd0e62e58b1ee0327b64dd7d40f05a646f
|
Provenance
The following attestation bundles were made for worm_sdk-0.9.0.tar.gz:
Publisher:
release.yml on wormwtf/worm-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
worm_sdk-0.9.0.tar.gz -
Subject digest:
636b3761dedf16cc666f5bcc6dfc4d04b223a05b76ac95437618af77813dcf2b - Sigstore transparency entry: 1747033243
- Sigstore integration time:
-
Permalink:
wormwtf/worm-sdk@367a9858e4f3df39f5b42ed43c528b5d8c20dcb7 -
Branch / Tag:
refs/tags/v0.9.0 - Owner: https://github.com/wormwtf
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@367a9858e4f3df39f5b42ed43c528b5d8c20dcb7 -
Trigger Event:
release
-
Statement type:
File details
Details for the file worm_sdk-0.9.0-py3-none-any.whl.
File metadata
- Download URL: worm_sdk-0.9.0-py3-none-any.whl
- Upload date:
- Size: 38.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ffcbc6d0bc62b993a912eb536c606a3230ccb357b83d1b16a7cdf8263296e7d9
|
|
| MD5 |
be9d8cf25a773ef4263cb5e62834766d
|
|
| BLAKE2b-256 |
dc7765026f5876c2516ff4b2867a1f2ef1b9526467b90d7f4731170eecbe145f
|
Provenance
The following attestation bundles were made for worm_sdk-0.9.0-py3-none-any.whl:
Publisher:
release.yml on wormwtf/worm-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
worm_sdk-0.9.0-py3-none-any.whl -
Subject digest:
ffcbc6d0bc62b993a912eb536c606a3230ccb357b83d1b16a7cdf8263296e7d9 - Sigstore transparency entry: 1747033482
- Sigstore integration time:
-
Permalink:
wormwtf/worm-sdk@367a9858e4f3df39f5b42ed43c528b5d8c20dcb7 -
Branch / Tag:
refs/tags/v0.9.0 - Owner: https://github.com/wormwtf
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@367a9858e4f3df39f5b42ed43c528b5d8c20dcb7 -
Trigger Event:
release
-
Statement type: