The SDK automatically retries on connection errors, timeouts, and HTTP 408/409/429/5xx
responses with exponential backoff (starting at 0.5s, max 8s, with jitter).
# Set max retriesclient = Rulebook(api_key="your-key", max_retries=5)# Disable retries for a single requestclient.with_options(max_retries=0).exchanges.retrieve("nasdaq")
with_options() — Client Overrides
Create a new client with overridden settings without mutating the original:
client = Rulebook(api_key="your-key")# Create a variant with different timeoutslow_client = client.with_options(timeout=120.0)# Create a variant with extra headersdebug_client = client.with_options(default_headers={"X-Debug": "true"})# Original client is unmodified
Per-Request Overrides
Every resource method accepts keyword arguments for single-request customization:
Access the raw HTTP response (headers, status code) while still getting typed parsing:
raw = client.exchanges.with_raw_response.retrieve("NYSE")print(raw.status_code) # 200print(raw.headers) # httpx.Headersprint(raw.http_request) # httpx.Request# Parse the body on demanddetail = raw.parse() # ExchangeDetailprint(detail.name) # "NYSE"
Works with all resources including fee schedule results:
Accessing metadata not included in the typed model
Raw response methods bypass the SDK’s automatic retry logic. If a request made
via with_raw_response fails due to a transient error (timeout, 429, 5xx), it
will not be retried automatically. Handle retries manually when using raw responses.
Using Types Directly
All response models are available for import and type hinting:
from rulebook import Rulebookfrom rulebook.types import ( Exchange, ExchangeDetail, DateRange, FeeScheduleResult, FeeScheduleResultFilters, Footnote, Definition, Relationships, PaginatedResponse,)def summarize_result(result: FeeScheduleResult) -> str: return f"{result.exchange_name} — {result.fee_action}: {result.fee_amount}"client = Rulebook(api_key="your-key")page = client.fee_schedule_results.list(latest_only=True)summaries = [summarize_result(r) for r in page.data]
Custom HTTP Client
Pass a pre-configured httpx.Client for full control over the HTTP layer: