🌐 HTTP Client

Async HTTP client with automatic retry logic and auth helpers.

🎯 Overview

Category Functions Purpose
🔄 Client AsyncAPIClient Async HTTP with retry
🔑 Auth bearer_token_auth, api_key_auth, oauth_token_auth Auth header generators

🏗️ Architecture

┌─────────────────────────────────────────────────────────────────┐
│                    Retry Logic Flow                             │
├─────────────────────────────────────────────────────────────────┤
│  Request → Response                                             │
│     ↓                                                           │
│  Status 429 or 500+ → Retry (exponential: 2s, 4s, 8s)          │
│     ↓                                                           │
│  Status 400-499 (except 429) → Fail immediately                │
│     ↓                                                           │
│  Network error → Retry                                          │
│     ↓                                                           │
│  Max 3 attempts → Raise exception                               │
└─────────────────────────────────────────────────────────────────┘

🔄 AsyncAPIClient

Method Purpose
AsyncAPIClient Async HTTP client with retry
.request() Execute HTTP request with retry
.get_json() GET request returning JSON

source

AsyncAPIClient


def AsyncAPIClient(
    base_url:str, auth_headers:dict=None, timeout:int=30
):

Async HTTP client with retry logic for external API integrations.


source

AsyncAPIClient.__init__


def __init__(
    base_url:str, auth_headers:dict=None, timeout:int=30
):

Initialize client with base URL, optional auth headers, and timeout.


source

AsyncAPIClient.request


def request(
    method:str, endpoint:str, params:dict=None, json:dict=None, headers:dict=None
)->httpx.Response:

Execute HTTP request with automatic retry on 429/500+ errors.


source

AsyncAPIClient.get_json


def get_json(
    endpoint:str, params:dict=None
)->Dict[str, Any]:

Convenience GET that returns parsed JSON.

🔑 Auth Helpers

Function Purpose
bearer_token_auth Bearer token header
api_key_auth API key header (customizable)
oauth_token_auth OAuth 2.0 access token

source

bearer_token_auth


def bearer_token_auth(
    token:str
)->dict:

Generate Bearer token authentication header.


source

api_key_auth


def api_key_auth(
    api_key:str, header_name:str='X-API-Key'
)->dict:

Generate API key header with customizable header name.


source

oauth_token_auth


def oauth_token_auth(
    access_token:str
)->dict:

Generate OAuth 2.0 access token header (alias for bearer_token_auth).