Skip to main content
The Python XDK is the official client library for the X API v2. It handles authentication, pagination, and streaming so you can focus on building.

GitHub repository

Source code, issues, and releases.

Installation

pip install xdk
Requires Python 3.8+.

Quick start

from xdk import Client

client = Client(bearer_token="YOUR_BEARER_TOKEN")

# Search for posts
for page in client.posts.search_recent(query="X API", max_results=10):
    if page.data and len(page.data) > 0:
        print(page.data[0].text)
        break

Key features

FeatureDescription
OAuth supportBearer Token, OAuth 2.0 with PKCE, and OAuth 1.0a
Automatic paginationIterate through results without manual next_token handling
StreamingReal-time data via persistent connections (filtered stream, etc.)
Full API coverageAll X API v2 endpoints — search, timelines, filtered stream, and more

Authentication

from xdk import Client

client = Client(bearer_token="YOUR_BEARER_TOKEN")

Common methods

CategoryMethod
Postsclient.posts.search_recent()
Usersclient.users.get_me()
Spacesclient.spaces.get()
Listsclient.lists.get()
DMsclient.direct_messages.get()

Learn more

Installation

Development install, prerequisites, and verification.

Quickstart

Step-by-step first request walkthrough.

Authentication

Detailed guide for all auth methods.

Pagination

Automatic pagination and iterators.

Streaming

Real-time data via filtered stream.

API Reference

Complete client and model reference.
For code examples, see the samples repo.