Skip to content

Python SDK

The hypercore-sdk package is a typed, async-ready Python client for accessing Hyperliquid market data through Aleatoric infrastructure. It covers all supported transport protocols — HTTP JSON-RPC, gRPC, WebSocket, and Server-Sent Events — behind a consistent, well-documented interface.

The SDK is open-source on GitHub and published to PyPI as hypercore-sdk. It passes mypy in strict mode with zero errors, ships with 127 tests at 92.45% line coverage, and requires Python 3.10 or later.

Install from PyPI:

Terminal window
pip install hypercore-sdk

For development (includes test runner, linter, type checker, and build tools):

Terminal window
pip install hypercore-sdk[dev]

All clients read their defaults from environment variables. Override any value by passing the corresponding argument to the client constructor.

VariablePurposeDefault
HYPER_RPC_URLJSON-RPC endpointhttps://rpc.aleatoric.systems/
HYPER_GRPC_TARGETgRPC endpointhl.grpc.aleatoric.systems:443
HYPER_UNIFIED_STREAM_URLUnified Stream endpointhttps://unified.grpc.aleatoric.systems
HYPER_WS_URLWebSocket endpointwss://api.hyperliquid.xyz/ws
HYPER_API_KEYAPI key for authenticated requests
UNIFIED_STREAM_KEYUnified Stream API key
ALEATORIC_GRPC_KEYgRPC API key
HYPER_TIMEOUT_MSRequest timeout in milliseconds10000
HYPER_VERIFY_TLSEnable TLS certificate verification (HTTP)true
HYPER_GRPC_TLSEnable TLS for gRPC channeltrue

The primary HTTP client. Built on httpx with connection pooling, keepalive, and context manager support for deterministic resource cleanup.

from hypercore_sdk import HyperCoreAPI
with HyperCoreAPI() as api:
block = api.block_number()
mids = api.all_mids()
btc = api.coin_mid("BTC")

These methods aggregate multiple upstream calls into a single return value, reducing round trips and simplifying common workflows.

  • market_snapshot(coin) — returns mid price, top-of-book bid/ask, and asset context in one call.
  • user_flow_snapshot(address, dex) — returns open orders and a fill summary for a given address.
  • user_fills(), user_fills_by_time() — trade execution history.
  • funding_history() — funding rate payments received or paid.
  • portfolio() — current positions and margin state.
  • historical_orders() — past order records including cancellations.
  • user_non_funding_ledger_updates() — deposits, withdrawals, and other non-funding ledger events.

Async gRPC client with TLS, metadata-based authentication, and built-in health checking. Streaming methods return async generators that yield events as they arrive.

from hypercore_sdk import GrpcClient
async with GrpcClient() as grpc:
health = await grpc.health_check()
services = await grpc.list_services()
async for price in grpc.mid_price_stream("BTC", max_events=10):
print(f"BTC: {price}")
async for liq in grpc.liquidations_stream("BTC", max_events=5):
print(f"Liquidation: {liq}")

The health_check() method uses the standard gRPC health checking protocol. list_services() uses server reflection to enumerate available service definitions at runtime.

SSE event consumer that provides both point-in-time REST snapshots and long-lived streaming generators. Useful when you need a single client for both polling and real-time consumption.

from hypercore_sdk import UnifiedStreamClient
client = UnifiedStreamClient()
# REST snapshots
stats = client.stats()
pulse = client.consensus_pulse()
book = client.l2_book(coin="BTC", depth=10)
mids = client.all_mids()
# SSE streaming (generators)
for event in client.sse_events(max_events=20):
print(event["event_type"], event["payload"])
for mid in client.sse_all_mids(max_events=5):
print(mid)

Streaming methods accept a max_events parameter to bound consumption. Omit it to stream indefinitely until the connection closes or you break out of the loop.

The SDK ships with a command-line interface that exposes the most common operations without writing code. After installation, the hypercore-sdk command is available on your PATH.

Terminal window
hypercore-sdk --help
hypercore-sdk block-number
hypercore-sdk all-mids
hypercore-sdk grpc-health
hypercore-sdk grpc-stream-mids BTC
hypercore-sdk unified-stats

The CLI reads the same environment variables described in the Configuration section above.

The SDK includes a built-in MCP server for integration with AI assistants such as Claude and ChatGPT. The server exposes 12 tools that map to the SDK’s core methods. See MCP Servers for setup instructions.

Terminal window
hypercore-sdk-mcp

The SDK is designed for production use in trading systems where correctness and reliability are non-negotiable.

AspectDetail
Type safetymypy strict mode, zero errors
Test coverage127 tests, 92.45% line coverage (90% gate)
Build verificationpython -m build + twine check in CI
Async supportFull async/await via grpcio and httpx
Connection poolinghttpx connection limits with keepalive
Error handlingTyped exceptions with status propagation
DockerRuntime and dev targets with docker-compose
  • Added UnifiedStreamClient with REST snapshots and SSE streaming generators.
  • Added consensus_pulse() endpoint.
  • Added liquidations_stream() to GrpcClient.
  • MCP server with 12 tools.
  • Added GrpcClient with health checking and server reflection.
  • Added market_snapshot() and user_flow_snapshot() convenience methods.
  • Initial release with HyperCoreAPI and CLI.