Skip to main content

worm-sdk

Official Python client for the Worm prediction markets API.

CI PyPI version Python 3.10+ License: MIT

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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

worm_sdk-0.11.0.tar.gz (38.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

worm_sdk-0.11.0-py3-none-any.whl (39.3 kB view details)

Uploaded Python 3

File details

Details for the file worm_sdk-0.11.0.tar.gz.

File metadata

  • Download URL: worm_sdk-0.11.0.tar.gz
  • Upload date:
  • Size: 38.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for worm_sdk-0.11.0.tar.gz
Algorithm Hash digest
SHA256 8525d28ed317486dd4d2a272b1b5197c28e3a516a452f1422d4f3caf601d53fd
MD5 7c98911431098516034b4450ab1c0eb3
BLAKE2b-256 b1c81f88acf337e6f60e3eb38a7d8b275a44aa34696284a753d16032cdea65e9

See more details on using hashes here.

Provenance

The following attestation bundles were made for worm_sdk-0.11.0.tar.gz:

Publisher: release.yml on wormwtf/worm-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file worm_sdk-0.11.0-py3-none-any.whl.

File metadata

  • Download URL: worm_sdk-0.11.0-py3-none-any.whl
  • Upload date:
  • Size: 39.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for worm_sdk-0.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a56a5a34a64f80464bee02358dcfa9e6cb7a06eabbe4e1ce7a97fee1e1ec9bce
MD5 e34a462951d941b417c79ace676c8ba8
BLAKE2b-256 787eef0c92d3ba1acf3b5d117d01ca347a131fde9fb3c8a14717577374279759

See more details on using hashes here.

Provenance

The following attestation bundles were made for worm_sdk-0.11.0-py3-none-any.whl:

Publisher: release.yml on wormwtf/worm-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page