Skip to main content

Welcome to XDK Python

XDK Python is an official Python SDK for the X API (v2) that provides a simple, intuitive interface for building applications on X. Built with type safety and modern Python practices, XDK makes it easy to create posts, manage users, search content, and more.

Installation

Get started by installing XDK with pip or uv

Quick Start

Post your first tweet in minutes with our guide

API Reference

Explore the complete API documentation

Authentication

Learn about OAuth1, OAuth2 PKCE, and bearer tokens

Key Features

XDK supports three authentication methods to fit your use case:
  • OAuth 1.0a: Traditional OAuth flow with consumer keys and access tokens
  • OAuth 2.0 PKCE: Modern authorization code flow with automatic token refresh
  • Bearer Token: Simple app-only authentication for read operations
The SDK automatically handles authentication headers and token management.
Access all X API v2 endpoints organized by resource:
  • Posts (tweets) - create, read, search, and manage
  • Users - profiles, followers, and relationships
  • Direct Messages - send and receive DMs
  • Lists, Spaces, Communities, and more
  • Streaming - real-time filtered stream
  • Media - upload images and videos
All request and response models use Pydantic for:
  • Automatic validation of API requests
  • Type hints for better IDE support
  • Clear error messages for invalid data
  • Serialization and deserialization
Many endpoints return iterators that automatically handle pagination:
from xdk import Client

client = Client(bearer_token="your_token")

# Automatically iterates through all pages
for page in client.posts.search_recent(query="python"):
    for tweet in page.data:
        print(tweet)

Quick Example

Here’s a simple example to get you started:
from xdk import Client
from xdk.posts.models import CreateRequest

# Initialize with OAuth2 access token
client = Client(access_token="your_access_token")

# Create a post
request = CreateRequest(text="Hello from XDK Python!")
response = client.posts.create(body=request)

print(f"Posted! Tweet ID: {response.data.id}")
The SDK version is 0.9.0. This is a beta release - some features may change before the 1.0 stable release.

Next Steps

1

Install the SDK

Follow the installation guide to add XDK to your project.
2

Set up authentication

Choose your authentication method and configure credentials.
3

Build your first integration

Follow the quickstart guide to post your first tweet.
4

Explore the API

Check out the API reference for all available endpoints.

Need Help?

For more detailed information, see:

Build docs developers (and LLMs) love