Python SDK

Official Python client with sync and async interfaces covering every Dual API endpoint.

The Python SDK (v1.0.0) is an official Python client with sync and async interfaces covering every Dual API endpoint. Built on httpx with automatic retry, Pydantic models, and a typed error hierarchy.

Requirements: Python >= 3.9 · httpx · pydantic v2

Installation

bash
pip install dual-sdk

Quick Start

python
import os
from dual_sdk import DualClient
client = DualClient(
token=os.environ["DUAL_API_KEY"],
auth_mode="api_key",
)
# Returns a typed Wallet model
wallet = client.wallets.me()
print(wallet.id, wallet.email)
# Returns PaginatedResponse[Template]
page = client.templates.list(limit=20)
for tmpl in page.items:
print(tmpl.name)
# Returns a typed Object model
obj = client.objects.create(
template_id="tmpl_abc123",
properties={"name": "My First Token"}
)
print(obj.id)

Async Support

Use AsyncDualClient for non-blocking I/O. Every method mirrors the sync API with await.

python
import asyncio
from dual_sdk import AsyncDualClient
async def main():
async with AsyncDualClient(token=os.environ["DUAL_API_KEY"], auth_mode="api_key") as client:
wallet = await client.wallets.me()
templates = await client.templates.list(limit=20)
# Concurrent requests
import asyncio
results = await asyncio.gather(
client.objects.list(limit=10),
client.templates.list(limit=10),
client.organizations.list(limit=10),
)
asyncio.run(main())

Configuration

The SDK supports custom timeouts, retry policies with exponential backoff, and base URL configuration.

python
from dual_sdk import DualClient
# API key auth (default)
client = DualClient(
token=os.environ["DUAL_API_KEY"],
auth_mode="api_key",
base_url="https://api-testnet.dual.network", # default
timeout=10.0, # seconds
max_retries=3, # retry on 429/5xx
backoff=1.0, # exponential backoff base
)
# JWT bearer token auth
jwt_client = DualClient(
token=os.environ["DUAL_JWT"],
auth_mode="bearer",
)

Error Handling

All API errors are raised as DualError subclasses with status, code, message, and full response body.

python
from dual_sdk import DualClient, DualError, DualAuthError, DualRateLimitError
client = DualClient(token=os.environ["DUAL_API_KEY"], auth_mode="api_key")
try:
wallet = client.wallets.me()
except DualAuthError as e:
print(f"Auth failed [{e.status}]: {e.code}")
except DualRateLimitError as e:
print(f"Rate limited. Retry after {e.retry_after}s")
except DualError as e:
print(f"API error [{e.status}]: {e.message}")
print("Details:", e.body)

Modules

The SDK provides 14 modules accessible via client.module_name. Each module has identical sync and async interfaces.

View the full source on GitHub · 2,083 lines · 14 modules · sync + async