The Demo venue is a paper-trading sandbox that mirrors real venue behavior without executing against live markets. Use it freely to validate your integration before connecting to Polymarket or Kalshi.
1
Install the SDK
Install the If the PyPI release is not yet available, install directly from the GitHub repository:The SDK requires Python 3.10 or later. It depends on
molecule package from PyPI:httpx for HTTP transport, PyNaCl for Ed25519 signing, and websockets for WebSocket streaming.2
Set Environment Variables
Configure three environment variables before running your code. The SDK reads them automatically if you do not pass the values explicitly to the constructor.
Keep your private key in an environment variable or a secrets manager — never commit it to source control or include it as a literal string in your code. The key never leaves your process; Molecule stores only the corresponding public key.
3
Initialize the Client
Import The client is synchronous. If your application uses
Molecule and instantiate the client. The constructor reads MOLECULE_BASE_URL, MOLECULE_KEY_ID, and MOLECULE_PRIVATE_KEY from the environment if you omit those arguments.asyncio, import AsyncMolecule instead — it exposes the same methods.base_url is required. The constructor raises ValueError if it is absent from both the argument and the environment variable.4
Search a Market
Use
client.search_markets() to run a full-text search across available instruments, or client.markets.match() to resolve a specific ticker or slug to a single instrument record.search_markets() returns a paginated list of instrument objects. markets.match() returns a single instrument object. Both calls are unauthenticated-compatible but will be signed automatically when a trading key is configured.Hold on to instrument["instrument_id"] — you will need it for the order book and order submission steps below.5
Inspect the Order Book
Fetch the current order book snapshot for an instrument to see resting bids and offers before you place an order.The response contains
bids and asks arrays, each with price and size entries sorted from best to worst. Use this to inform your limit price before submission.6
Submit an Order
Place a limit order on the Demo venue using
client.create_order(). Supply a client_order_id to make the request idempotent — retrying with the same client_order_id and identical payload is safe and returns the original order rather than creating a duplicate.A
routing.mode of "DIRECT" pairs with instrument_id. Use "BEST_PRICE" or "SPLIT" with generic_asset_id to route across venues.7
Check the Order
Retrieve the order by its server-assigned ID to confirm its current status.Order status transitions through the following values:
For continuous order updates without polling, subscribe to the
/v1/ws/orders WebSocket stream using client.iter_ws("/v1/ws/orders").Next Steps
Authentication
Understand Ed25519 key provisioning, the signing protocol, and JWT management sessions.
Orders Guide
Explore order types, routing modes, amendments, batch submission, and complex orders.
Market Data
Fetch order books, stream real-time prices, read candles, and subscribe to trade prints.
