Python SDK#
The canonical Python package is seesaw-sdk. It shares instruction, PDA,
account-layout, and math vectors with the TypeScript and Rust clients.
from collections.abc import Callable
from solders.pubkey import Pubkey
from seesaw import (
derive_market_pda,
derive_orderbook_pda,
decode_market,
decode_deep_orderbook,
)
def read_market(
feed_id: bytes,
duration_seconds: int,
market_id: int,
creator: Pubkey,
currency_record: Pubkey,
fetch_finalized_bytes: Callable[[Pubkey], bytes],
):
market_address, _ = derive_market_pda(
feed_id, duration_seconds, market_id, creator, currency_record
)
orderbook_address, _ = derive_orderbook_pda(market_address)
market = decode_market(fetch_finalized_bytes(market_address))
orderbook = decode_deep_orderbook(fetch_finalized_bytes(orderbook_address))
return market_address, market, orderbook
Supply a 32-byte feed ID and an application fetch_finalized_bytes adapter.
The adapter must fetch finalized account data, reject missing accounts and
unexpected owners, and return binary bytes. PDA helpers return (Pubkey, bump);
the orderbook address is derived separately, not read from a market field. The market PDA is currency-scoped: currency_record comes from derive_currency_record_pda(settlement_mint, token_program).
Use finalized account data for settlement and balances. Validate discriminator, size, version, PDA, and related-market fields before using a decoded value. Deep orderbooks accept only the canonical capacities 64, 128, 256, 512, 1024, 2048, and 4096.
For source markets, build the current lifecycle instructions with
seesaw.source_transactions. build_open() accepts a signed opening
result. build_lifecycle_result() accepts a signed packet for resolution,
halt, or a close-time update. Supply the deployment ID and the market
and signer addresses. The builder derives the witness registry and source
control accounts for that deployment.
The program checks witness signatures and the market's lifecycle revision when the transaction lands. Keep the original signed result bytes and retain evidence by digest. The source result example shows unsigned instruction construction using synthetic fixtures.
From a checkout:
pip install -e packages/sdk-python
python -m pytest packages/sdk-python/tests
Run bun --filter @seesaw/test-vectors test to verify cross-language parity.