Skip to main content

Subpackages

Submodules

Module contents

XDK Python SDK. A Python SDK for the X API that provides convenient access to the X API endpoints with type safety and authentication support.

class xdk.Client

Client for interacting with the X API.

Parameters

str
default:"'https://api.x.com'"
str or None
default:"None"
str or None
default:"None"
str or None
default:"None"
str or None
default:"None"
str or None
default:"None"
Dict[str, Any] or None
default:"None"
str or List[str] or None
default:"None"
str
default:"'https://x.com/i'"
OAuth1

__init__

Initialize the X API client.

Parameters

str
default:"'https://api.x.com'"
The base URL for the X API (defaults to https://api.x.com).
str or None
default:"None"
The bearer token for the X API (app-only authentication).
str or None
default:"None"
The OAuth2 access token for user context (can be used directly as bearer token).
str or None
default:"None"
The client ID for the X API (required for OAuth2 PKCE flow).
str or None
default:"None"
The client secret for the X API.
str or None
default:"None"
The redirect URI for OAuth2 authorization.
Dict[str, Any] or None
default:"None"
An existing OAuth2 token dictionary (if available). If provided, access_token will be extracted.
str or List[str] or None
default:"None"
Space-separated string or list of strings for OAuth2 authorization scopes.
str
default:"'https://x.com/i'"
The base URL for OAuth2 authorization (defaults to https://x.com/i).
OAuth1
OAuth1 instance for OAuth1.0a authentication.

exchange_code

Exchange authorization code for tokens (matches TypeScript API).

Parameters

Any
The authorization code from the callback.
Any
default:"None"
Optional code verifier (uses stored verifier if not provided).

fetch_token

Fetch token using authorization response URL (legacy method).

Parameters

Any
The full callback URL received after authorization.

get_authorization_url

Get the authorization URL for the OAuth2 PKCE flow.

Parameters

Any
default:"None"
Optional state parameter for security.

is_token_expired

Check if the OAuth2 token is expired.

refresh_token

Refresh the OAuth2 token.

class xdk.Cursor

[ResponseType]

Parameters

PaginatableMethod

__init__

Initialize the cursor.

Parameters

PaginatableMethod
The API method to call for each page (must support pagination)

items

Iterate over individual items from paginated responses.

Parameters

int or None
default:"None"
Maximum number of items to return (None for unlimited)

Returns

IteratorAny

pages

Iterate over pages of responses.

Parameters

int or None
default:"None"
Maximum number of pages to return (None for unlimited)

Returns

IteratorResponseType

class xdk.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.StreamError

Exception raised for streaming errors with classification.

Parameters

str
StreamErrorType

__init__

Parameters

str
StreamErrorType

class xdk.StreamErrorType

Classification of streaming errors for retry decisions.

Parameters

Any

class xdk.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.cursor

Create a cursor with proper type inference and validation. This factory function helps with type inference so you get proper type hints for the response type, and validates that the method supports pagination at both static analysis and runtime.

Parameters

PaginatableMethod
The API method to wrap (must support pagination)