Official SDKs
X provides official SDKs for TypeScript and Python with full X API v2 support.Python SDK
Async support, type hints, and automatic token refresh. Perfect for data analysis and automation.
TypeScript SDK
Full type safety and ESM support. Works in Node.js and modern bundlers.
Why use the official SDKs?
| Benefit | Description |
|---|---|
| Always up-to-date | Maintained by X, updated with new endpoints |
| Type safety | Full type definitions for all objects and methods |
| Built-in auth | OAuth 2.0 and OAuth 1.0a support |
| Automatic pagination | Iterate through results without manual token handling |
Quick start
Authentication
Both SDKs support multiple authentication methods:- Bearer Token (App-only)
- OAuth 2.0 (User Context)
- OAuth 1.0a (User Context)
Simplest option for reading public data.Python:TypeScript:
Available methods
The SDKs provide methods for all X API v2 endpoints:| Category | Python | TypeScript |
|---|---|---|
| Posts | client.posts.search_recent() | client.posts.search() |
| Users | client.users.get_me() | client.users.getMe() |
| Spaces | client.spaces.get() | client.spaces.findSpaceById() |
| Lists | client.lists.get() | client.lists.getList() |
| DMs | client.direct_messages.get() | client.directMessages.lookup() |
Python SDK Docs
Complete Python documentation.
TypeScript SDK Docs
Complete TypeScript documentation.
Python GitHub
Source code and issues.
TypeScript GitHub
Source code and issues.
Official tools
| Tool | Description |
|---|---|
| Postman Collection | Interactive API testing for all v2 endpoints |
| xurl | Command line tool for the X APIs that handles authentication for you |
| OpenAPI Spec | Machine-readable API specification |
| twitter-text | Parse and validate post text, count characters |
| Embed Generator | Build embeddable posts, timelines, or buttons for your site |
Community libraries
These community-maintained libraries support X API v2. Check each library’s documentation for current API coverage.- Python
- JavaScript/TypeScript
- Go
- Java/Kotlin
- PHP
- Ruby
- Other
| Library | Description |
|---|---|
| tweepy | Popular Python library with v2 support |
| twarc | CLI and library for data collection |
| python-twitter | Simple Python wrapper |
| TwitterAPI | Minimal Python wrapper |
Community libraries are not maintained by X. Check their repositories for support and current status.
X Ads API libraries
For tools and libraries specific to the X Ads API, see the Ads API tools and libraries page.Code samples
Find examples on GitHub:- X API v2 Sample Code - Examples in Python, JavaScript, Ruby, and more
- X Developer GitHub - Official repos and tools
- Code Samples Repo - Examples using the official XDKs
- Glitch Examples - Interactive, remixable apps
- Replit Examples - Browser-based coding
Building a library?
If you have built an X API library, share it with the community:- Post in the Libraries and SDKs forum
- We may add it to this page!
Getting help
Developer Forum
Get help from the community.