Skip to main content
Robust streaming utilities for the X API SDK. This module provides streaming connection handling with automatic reconnection, exponential backoff, and comprehensive error handling. Clients can consume streaming endpoints without worrying about connection management - the SDK handles all recovery automatically.

class xdk.streaming.StreamConfig

Configuration for streaming connections with retry behavior.

Parameters

path.max_retries
int
default:"10"
path.initial_backoff
float
default:"1.0"
path.max_backoff
float
default:"64.0"
path.backoff_multiplier
float
default:"2.0"
path.jitter
bool
default:"True"
path.timeout
float or None
default:"None"
path.chunk_size
int
default:"1024"
path.on_connect
Callable[[], None] or None
default:"None"
path.on_disconnect
Callable[[Exception or None], None] or None
default:"None"
path.on_reconnect
Callable[[int, float], None] or None
default:"None"
path.on_error
Callable[[[StreamError

__init__

Parameters

path.max_retries
int
default:"10"
path.initial_backoff
float
default:"1.0"
path.max_backoff
float
default:"64.0"
path.backoff_multiplier
float
default:"2.0"
path.jitter
bool
default:"True"
path.timeout
float or None
default:"None"
path.chunk_size
int
default:"1024"
path.on_connect
Callable[[], None] or None
default:"None"
path.on_disconnect
Callable[[Exception or None], None] or None
default:"None"
path.on_reconnect
Callable[[int, float], None] or None
default:"None"
path.on_error
Callable[[[StreamError

on_error : Callable[[[StreamError]

exception xdk.streaming.StreamError

Exception raised for streaming errors with classification.

Parameters

path.message
str
path.error_type
StreamErrorType

__init__

Parameters

path.message
str
path.error_type
StreamErrorType

class xdk.streaming.StreamErrorType

Classification of streaming errors for retry decisions.

Parameters

path.value
Any

class xdk.streaming.StreamState

Internal state for a streaming connection.

Parameters

path.retry_count
int
default:"0"
path.current_backoff
float
default:"1.0"
path.is_connected
bool
default:"False"
path.total_items_received
int
default:"0"
path.last_error
StreamError

__init__

Parameters

path.retry_count
int
default:"0"
path.current_backoff
float
default:"1.0"
path.is_connected
bool
default:"False"
path.total_items_received
int
default:"0"
path.last_error
StreamError

last_error : [StreamError]

xdk.streaming.stream_with_retry

Stream data from an endpoint with automatic reconnection and exponential backoff. This function handles all connection management, including:
  • Automatic reconnection on disconnects
  • Exponential backoff with jitter for retry delays
  • Classification of errors as retryable vs fatal
  • Lifecycle callbacks for monitoring connection state

Parameters

path.session
Session
The requests Session to use for HTTP calls.
path.method
str
HTTP method (typically “get”).
path.url
str
The full URL to stream from.
path.config
StreamConfig
StreamConfig with retry and callback settings.