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.10.0.tar.gz (37.6 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.10.0-py3-none-any.whl (39.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for worm_sdk-0.10.0.tar.gz
Algorithm Hash digest
SHA256 0a692a6497824d8164c610df21f8fb013e13a4c14372cc3e00da0ef8738df9eb
MD5 1307d64f2985e9b2792e243f0c9ee430
BLAKE2b-256 b62aeb44753ff035fa742ffb7cbe97a5367385ec7d3366db45c08deb3e882dbd

See more details on using hashes here.

Provenance

The following attestation bundles were made for worm_sdk-0.10.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.10.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for worm_sdk-0.10.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fd1aae42a11db5c0e2cfa1fc42f03f243f878498a1af42bac2dd749dc877da23
MD5 340be250b2be9b7c8bad992b0b92e505
BLAKE2b-256 72f3588f93a621962708bee84393766a456020acb1ecab48a93bef6c1c14388d

See more details on using hashes here.

Provenance

The following attestation bundles were made for worm_sdk-0.10.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