Python SDK Introduction
Overview
The SnipeRoute Python SDK provides a type-safe, async-first interface for interacting with the SnipeRoute API. It's the recommended way to integrate SnipeRoute into your Python applications.
Type-Safe
Full mypy strict mode support with Pydantic v2 models
Async-First
Built on httpx for high-performance async HTTP
Developer-Friendly
Intuitive API with comprehensive error handling
Well-Tested
96.73% test coverage with 45 passing tests
Features
- Async/Await Support: Fully async API built on
httpx - Type Safety: Complete type hints with Pydantic v2 models
- Automatic Retries: Configurable retry logic for transient failures
- Error Handling: Rich exception hierarchy for granular error handling
- Idempotency: Built-in support for idempotent requests
- Environment Variables: Automatic configuration from
.envfiles
Requirements
- Python 3.11+
httpx>= 0.26.0pydantic>= 2.5.0
Quick Example
import asyncio
from sniperoute import SnipeRouteClient
from sniperoute.models import TradeIntentRequest, OrderSide, OrderType
from decimal import Decimal
async def main():
# Initialize client
client = SnipeRouteClient()
# Create Trade Intent
intent = TradeIntentRequest(
intent_id="trade_001",
symbol="AAPL",
side=OrderSide.BUY,
quantity=Decimal("10"),
order_type=OrderType.MARKET,
broker_id="my_broker"
)
# Submit to SnipeRoute
response = await client.create_intent(intent)
print(f"Intent created: {response.intent_id}")
print(f" Status: {response.status}")
asyncio.run(main())Architecture
The SDK is organized into several modules:
| Module | Description |
|---|---|
sniperoute.client | Main SnipeRouteClient class |
sniperoute.models | Pydantic models for requests/responses |
sniperoute.exceptions | Exception hierarchy |
sniperoute.types | Type definitions and enums |
Comparison with Direct API Calls
With Python SDK
from sniperoute import SnipeRouteClient
from sniperoute.models import TradeIntentRequest, OrderSide, OrderType
from decimal import Decimal
client = SnipeRouteClient()
intent = TradeIntentRequest(
intent_id="trade_001",
symbol="AAPL",
side=OrderSide.BUY,
quantity=Decimal("10"),
order_type=OrderType.MARKET,
broker_id="my_broker"
)
response = await client.create_intent(intent)Benefits:
- Type-safe models
- Auto-completion in IDEs
- Built-in validation
- Proper error handling
Without SDK (Direct API)
import httpx
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json"
}
data = {
"intent_id": "trade_001",
"symbol": "AAPL",
"side": "buy", # Easy to typo
"quantity": 10, # Missing Decimal conversion
"order_type": "market",
"broker_id": "my_broker"
}
response = await httpx.post(
"https://api.sniperoute.io/api/v1/intents",
headers=headers,
json=data
)
# Manual error handling
if response.status_code >= 400:
# Handle errors manually
passDrawbacks:
- No type safety
- Manual JSON serialization
- Manual error handling
- No auto-completion
Installation
Get Started
Install the Python SDK