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

int
default:"10"
float
default:"1.0"
float
default:"64.0"
float
default:"2.0"
bool
default:"True"
float or None
default:"None"
int
default:"1024"
Callable[[], None] or None
default:"None"
Callable[[Exception or None], None] or None
default:"None"
Callable[[int, float], None] or None
default:"None"
Callable[[[StreamError

__init__

Parameters

int
default:"10"
float
default:"1.0"
float
default:"64.0"
float
default:"2.0"
bool
default:"True"
float or None
default:"None"
int
default:"1024"
Callable[[], None] or None
default:"None"
Callable[[Exception or None], None] or None
default:"None"
Callable[[int, float], None] or None
default:"None"
Callable[[[StreamError

on_error : Callable[[[StreamError]

exception xdk.streaming.StreamError

Exception raised for streaming errors with classification.

Parameters

str
StreamErrorType

__init__

Parameters

str
StreamErrorType

class xdk.streaming.StreamErrorType

Classification of streaming errors for retry decisions.

Parameters

Any

class xdk.streaming.StreamState

Internal state for a streaming connection.

Parameters

int
default:"0"
float
default:"1.0"
bool
default:"False"
int
default:"0"
StreamError

__init__

Parameters

int
default:"0"
float
default:"1.0"
bool
default:"False"
int
default:"0"
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

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