Skip to main content
X provides official SDKs for TypeScript and Python. These libraries handle authentication, pagination, and provide full type safety.

Python SDK

Async support, type hints, comprehensive v2 coverage.

TypeScript SDK

Full TypeScript types, ESM support, works with Node.js.

Why use the official SDKs?

BenefitDescription
Always up-to-dateMaintained by X, updated with new endpoints
Type safetyFull type definitions for all objects and methods
Built-in authOAuth 2.0 and OAuth 1.0a support
Automatic paginationIterate through results without manual token handling

Quick start

Installation

pip install xdk

Basic usage

from xdk import Client

client = Client(bearer_token="YOUR_BEARER_TOKEN")

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

Authentication

Both SDKs support multiple authentication methods:
Simplest option for reading public data.Python:
from xdk import Client

client = Client(bearer_token="YOUR_BEARER_TOKEN")
TypeScript:
import { Client } from '@xdevplatform/xdk';

const client = new Client({ bearerToken: 'YOUR_BEARER_TOKEN' });

Available methods

The SDKs provide methods for all X API v2 endpoints:
CategoryPythonTypeScript
Postsclient.posts.search_recent()client.posts.search()
Usersclient.users.get_me()client.users.getMe()
Spacesclient.spaces.get()client.spaces.findSpaceById()
Listsclient.lists.get()client.lists.getList()
DMsclient.direct_messages.get()client.directMessages.lookup()
See the full SDK documentation for complete method reference.

Resources

Python SDK Docs

Complete Python documentation.

TypeScript SDK Docs

Complete TypeScript documentation.

Python GitHub

Source code and issues.

TypeScript GitHub

Source code and issues.