> ## Documentation Index
> Fetch the complete documentation index at: https://generaltranslation.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Official SDKs

> Official X API SDKs for TypeScript and Python

export const Button = ({href, children}) => {
  return <div className="not-prose group">
    <a href={href}>
      <button className="flex items-center space-x-2.5 py-1 px-4 bg-primary-dark dark:bg-white text-white dark:text-gray-950 rounded-full group-hover:opacity-[0.9] font-medium">
        <span>
          {children}
        </span>
        <svg width="3" height="24" viewBox="0 -9 3 24" class="h-6 rotate-0 overflow-visible"><path d="M0 0L3 3L0 6" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"></path></svg>
      </button>
    </a>
  </div>;
};

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

<CardGroup cols={2}>
  <Card title="Python SDK" icon="python" href="/xdks/python/overview">
    Async support, type hints, comprehensive v2 coverage.
  </Card>

  <Card title="TypeScript SDK" icon="js" href="/xdks/typescript/overview">
    Full TypeScript types, ESM support, works with Node.js.
  </Card>
</CardGroup>

***

## 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

<Tabs>
  <Tab title="Python">
    ### Installation

    ```bash theme={null}
    pip install xdk
    ```

    ### Basic usage

    ```python theme={null}
    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
    ```

    <Button href="/xdks/python/overview">Full Python guide</Button>
  </Tab>

  <Tab title="TypeScript">
    ### Installation

    ```bash theme={null}
    npm install @xdevplatform/xdk
    ```

    ### Basic usage

    ```typescript theme={null}
    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);
    ```

    <Button href="/xdks/typescript/overview">Full TypeScript guide</Button>
  </Tab>
</Tabs>

***

## Authentication

Both SDKs support multiple authentication methods:

<Tabs>
  <Tab title="Bearer Token (App-only)">
    Simplest option for reading public data.

    **Python:**

    ```python theme={null}
    from xdk import Client

    client = Client(bearer_token="YOUR_BEARER_TOKEN")
    ```

    **TypeScript:**

    ```typescript theme={null}
    import { Client } from '@xdevplatform/xdk';

    const client = new Client({ bearerToken: 'YOUR_BEARER_TOKEN' });
    ```
  </Tab>

  <Tab title="OAuth 2.0 (User Context)">
    For actions on behalf of users (posting, following, etc.).

    **Python:**

    ```python theme={null}
    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:**

    ```typescript theme={null}
    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 });
    ```
  </Tab>

  <Tab title="OAuth 1.0a (User Context)">
    For legacy applications or specific use cases.

    **Python:**

    ```python theme={null}
    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:**

    ```typescript theme={null}
    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 });
    ```
  </Tab>
</Tabs>

***

## 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

<CardGroup cols={2}>
  <Card title="Python SDK Docs" icon="book" href="/xdks/python/overview">
    Complete Python documentation.
  </Card>

  <Card title="TypeScript SDK Docs" icon="book" href="/xdks/typescript/overview">
    Complete TypeScript documentation.
  </Card>

  <Card title="Python GitHub" icon="github" href="https://github.com/xdevplatform/xdk-py">
    Source code and issues.
  </Card>

  <Card title="TypeScript GitHub" icon="github" href="https://github.com/xdevplatform/twitter-api-typescript-sdk">
    Source code and issues.
  </Card>
</CardGroup>
