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

# Python SDK

> 安装并配置 UQPAY 官方 Python SDK。

UQPAY Python SDK以带类型的方式访问Account Center、Global Account、Global Acquiring、Card Issuance和Supporting Services。它内置自动鉴权、请求重试、Webhook签名验证、PGP授权决策和Sandbox交易模拟。

<Card title="PyPI" icon="python" href="https://pypi.org/project/uqpay/">
  uqpay
</Card>

<Info>
  SDK需要**Python 3.11**或更高版本。**1.2.0**是它首次加入协调客户端版本线的发布版本。
</Info>

<h2 id="installation">
  安装
</h2>

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

<h2 id="quick-start">
  快速开始
</h2>

开始前，请先[创建沙盒账户](/zh/account-center/v1.6/guide/create-a-sandbox-account)并[创建API密钥](/zh/account-center/v1.6/guide/create-api-keys)。

<Tabs>
  <Tab title="Sandbox">
    ```python theme={null}
    from uqpay import UQPayClient

    client = UQPayClient(client_id="your-client-id", api_key="your-api-key", environment="sandbox")
    ```
  </Tab>

  <Tab title="Production">
    ```python theme={null}
    from uqpay import UQPayClient

    client = UQPayClient(client_id="your-client-id", api_key="your-api-key", environment="production")
    ```
  </Tab>
</Tabs>

<h2 id="configuration">
  配置
</h2>

```python theme={null}
client = UQPayClient(
    client_id="your-client-id",
    api_key="your-api-key",
    environment="sandbox",       # "sandbox" (default) or "production"
    timeout=30.0,                # request timeout in seconds
    max_retries=2,               # automatic retries on transient errors
    log_level="none",            # "none" | "error" | "warn" | "info" | "debug"
    redact_fields=["card_number", "cvc"],
)
```

你也可以通过环境变量提供凭证：

```bash theme={null}
export UQPAY_CLIENT_ID="your-client-id"
export UQPAY_API_KEY="your-api-key"
```

<h2 id="authentication">
  鉴权
</h2>

SDK使用你的`client_id`和`api_key`获取UQPAY Access Token，缓存后在当前Token到期前重新获取新Token。你无需手动管理Token。

<Note>
  Stablecoin Account（Ramp）不在当前SDK产品范围内。
</Note>

<h2 id="per-request-options">
  单次请求选项
</h2>

你可以为单个请求设置幂等键、子账户、超时和重试行为：

```python theme={null}
result = client.banking.payouts.create(
    {...},
    request_options={
        "idempotency_key": "unique-key",
        "on_behalf_of": "sub-account-id",
        "timeout": 60,
        "max_retries": 0,
    },
)
```

<h2 id="pagination">
  分页
</h2>

所有列表方法都接受`page_number`和`page_size`：

```python theme={null}
page = 1
while True:
    result = client.issuing.cards.list({"page_number": page, "page_size": 50})
    items = result.get("items") or result.get("list") or []
    if not items:
        break
    for card in items:
        print(card["card_id"])
    page += 1
```

<CardGroup cols={2}>
  <Card title="资源" icon="brackets-curly" href="/zh/developer-tools/sdk/python/resources">
    查看可用的API namespace。
  </Card>

  <Card title="Webhooks" icon="webhook" href="/zh/developer-tools/sdk/python/webhooks">
    验证传入的Webhook签名。
  </Card>

  <Card title="授权决策" icon="key" href="/zh/developer-tools/sdk/python/authorization-decision">
    处理PGP加密的卡授权决策。
  </Card>

  <Card title="错误处理" icon="triangle-exclamation" href="/zh/developer-tools/sdk/python/error-handling">
    处理带类型的SDK错误和重试。
  </Card>
</CardGroup>
