Skip to main content

Prerequisites

Before installing XDK, ensure you have:
  • Python 3.8 or higher installed on your system
  • pip or uv package manager
  • An X developer account with API credentials (see X Developer Portal)

Install XDK

Choose your preferred package manager:
pip install xdk
The current version is 0.9.0. This SDK is auto-generated from the X API OpenAPI specification.

Verify Installation

Confirm XDK is installed correctly:
import xdk

print(f"XDK version: {xdk.__version__}")
# Output: XDK version: 0.9.0

Get API Credentials

To use XDK, you’ll need credentials from the X Developer Portal. The type of credentials depends on your authentication method:

Environment Setup

Store your credentials securely using environment variables:
# OAuth 2.0 PKCE
X_CLIENT_ID="your_client_id"
X_CLIENT_SECRET="your_client_secret"
X_REDIRECT_URI="http://localhost:3000/callback"

# OAuth 1.0a
X_API_KEY="your_api_key"
X_API_SECRET="your_api_secret"
X_ACCESS_TOKEN="your_access_token"
X_ACCESS_TOKEN_SECRET="your_access_token_secret"

# Bearer Token
X_BEARER_TOKEN="your_bearer_token"
Install python-dotenv to easily load environment variables:
pip install python-dotenv

Initialize the Client

Once installed, you can initialize the XDK client with your preferred authentication method:
from xdk import Client
import os

client = Client(
    client_id=os.getenv("X_CLIENT_ID"),
    client_secret=os.getenv("X_CLIENT_SECRET"),
    redirect_uri=os.getenv("X_REDIRECT_URI")
)

# Get authorization URL for user login
auth_url = client.get_authorization_url()
print(f"Visit: {auth_url}")

# After user authorizes, exchange code for tokens
# code = "..." # from callback
# token = client.exchange_code(code)

Next Steps

Quick Start

Follow our guide to post your first tweet

Authentication Guide

Learn more about authentication methods

Build docs developers (and LLMs) love