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

# Python XDK

> Instale e use a biblioteca cliente oficial Python XDK para a X API v2, incluindo configuração de autenticação, solicitações paginadas e exemplos de streaming.

O [Python XDK](https://github.com/xdevplatform/xdk-py) é a biblioteca cliente oficial para a X API v2. Ele cuida de autenticação, paginação e streaming, para que você possa focar em construir.

<Card title="Repositório no GitHub" icon="github" href="https://github.com/xdevplatform/xdk-py">
  Código-fonte, issues e releases.
</Card>

***

## Instalação

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

Requer Python 3.8+.

***

## Início rápido

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

client = Client(bearer_token="YOUR_BEARER_TOKEN")

# Search for posts
for page in client.posts.search_recent(query="X API", max_results=10):
    if page.data and len(page.data) > 0:
        print(page.data[0].text)
        break
```

***

## Principais recursos

| Recurso                       | Descrição                                                                        |
| :---------------------------- | :------------------------------------------------------------------------------- |
| **Suporte a OAuth**           | Bearer Token, OAuth 2.0 com PKCE e OAuth 1.0a                                    |
| **Paginação automática**      | Itere pelos resultados sem manipular `next_token` manualmente                    |
| **Streaming**                 | Dados em tempo real via conexões persistentes (filtered stream etc.)             |
| **Cobertura completa da API** | Todos os endpoints da X API v2 — search, timelines, filtered stream e muito mais |

***

## Autenticação

<Tabs>
  <Tab title="Bearer Token">
    ```python theme={null}
    from xdk import Client

    client = Client(bearer_token="YOUR_BEARER_TOKEN")
    ```
  </Tab>

  <Tab title="OAuth 2.0">
    ```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"
    )

    auth_url = auth.get_authorization_url()
    tokens = auth.fetch_token(authorization_response=callback_url)
    client = Client(bearer_token=tokens["access_token"])
    ```
  </Tab>

  <Tab title="OAuth 1.0a">
    ```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)
    ```
  </Tab>
</Tabs>

***

## Métodos comuns

| Categoria  | Método                         |
| :--------- | :----------------------------- |
| **Posts**  | `client.posts.search_recent()` |
| **Users**  | `client.users.get_me()`        |
| **Spaces** | `client.spaces.get()`          |
| **Lists**  | `client.lists.get()`           |
| **DMs**    | `client.direct_messages.get()` |

***

## Saiba mais

<CardGroup cols={2}>
  <Card title="Instalação" icon="download" href="/xdks/python/install">
    Instalação de desenvolvimento, pré-requisitos e verificação.
  </Card>

  <Card title="Início rápido" icon="rocket" href="/xdks/python/quickstart">
    Passo a passo da primeira solicitação.
  </Card>

  <Card title="Autenticação" icon="key" href="/xdks/python/authentication">
    Guia detalhado para todos os métodos de autenticação.
  </Card>

  <Card title="Paginação" icon="arrows-left-right" href="/xdks/python/pagination">
    Paginação automática e iteradores.
  </Card>

  <Card title="Streaming" icon="satellite-dish" href="/xdks/python/streaming">
    Dados em tempo real via filtered stream.
  </Card>

  <Card title="Referência da API" icon="book" href="/xdks/python/reference/modules">
    Referência completa de cliente e modelos.
  </Card>
</CardGroup>

Para ver exemplos de código, confira o [repositório de samples](https://github.com/xdevplatform/samples/tree/main/python).
