SDK
Python SDK
Introduction

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.

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 .env files

Requirements

  • Python 3.11+
  • httpx >= 0.26.0
  • pydantic >= 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:

ModuleDescription
sniperoute.clientMain SnipeRouteClient class
sniperoute.modelsPydantic models for requests/responses
sniperoute.exceptionsException hierarchy
sniperoute.typesType 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
    pass

Drawbacks:

  • No type safety
  • Manual JSON serialization
  • Manual error handling
  • No auto-completion

Installation

Get Started

Install the Python SDK

Next Steps