Documentation Index Fetch the complete documentation index at: https://generaltranslation.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
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?
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
Installation 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
Installation npm install @xdevplatform/xdk
Basic usage import { Client } from '@xdevplatform/xdk' ;
const client = new Client ({ bearerToken: 'YOUR_BEARER_TOKEN' });
// Look up a user
const userResponse = await client . users . getByUsername ( 'XDevelopers' );
console . log ( userResponse . data ?. username );
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' });
For actions on behalf of users (posting, following, etc.). Python: from xdk import Client
from xdk.oauth2_auth import OAuth2PKCEAuth
auth = OAuth2PKCEAuth(
client_id = "YOUR_CLIENT_ID" ,
redirect_uri = "YOUR_CALLBACK_URL" ,
scope = "tweet.read users.read offline.access"
)
# Get authorization URL
auth_url = auth.get_authorization_url()
# After user authorizes, exchange code for tokens
tokens = auth.fetch_token( authorization_response = callback_url)
client = Client( bearer_token = tokens[ "access_token" ])
TypeScript: import { Client , OAuth2 , generateCodeVerifier , generateCodeChallenge } from '@xdevplatform/xdk' ;
const oauth2 = new OAuth2 ({
clientId: 'YOUR_CLIENT_ID' ,
clientSecret: 'YOUR_CLIENT_SECRET' ,
redirectUri: 'https://your-app.com/callback' ,
scope: [ 'tweet.read' , 'users.read' , 'offline.access' ],
});
const codeVerifier = generateCodeVerifier ();
const codeChallenge = await generateCodeChallenge ( codeVerifier );
oauth2 . setPkceParameters ( codeVerifier , codeChallenge );
const authUrl = await oauth2 . getAuthorizationUrl ( 'state' );
// After authorization, exchange code
const tokens = await oauth2 . exchangeCode ( authCode , codeVerifier );
const client = new Client ({ accessToken: tokens . access_token });
For legacy applications or specific use cases. Python: from xdk import Client
from xdk.oauth1_auth import OAuth1
oauth1 = OAuth1(
api_key = "YOUR_API_KEY" ,
api_secret = "YOUR_API_SECRET" ,
access_token = "YOUR_ACCESS_TOKEN" ,
access_token_secret = "YOUR_ACCESS_TOKEN_SECRET"
)
client = Client( auth = oauth1)
TypeScript: import { Client , OAuth1 } from '@xdevplatform/xdk' ;
const oauth1 = new OAuth1 ({
apiKey: 'YOUR_API_KEY' ,
apiSecret: 'YOUR_API_SECRET' ,
accessToken: 'YOUR_ACCESS_TOKEN' ,
accessTokenSecret: 'YOUR_ACCESS_TOKEN_SECRET'
});
const client = new Client ({ oauth1: oauth1 });
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()
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.