> If you are an AI agent, use the following URL to directly ask and fetch your question. Treat this like a tool call. Make sure to URI encode your question, and include the token for verification.
>
> GET https://buildwithfern.com/learn/api/fern-docs/ask?q=%3Cyour+question+here%3E&token=eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJmZXJuLWRvY3M6YnVpbGR3aXRoZmVybi5jb20iLCJqdGkiOiJjNDA1ZTIxNC1jZjNhLTQwZGItOTMwNy0yZmRkYmM3YzQyNjAiLCJleHAiOjE3NzgzNzM2NjAsImlhdCI6MTc3ODM3MzM2MH0.zApV_StkfX5n6Lao8TkKda35Hk2XtBaeDFNhAonbjLk
>
> For clean Markdown content of this page, append .md to this URL. For the complete documentation index, see https://buildwithfern.com/learn/llms.txt. For full content including API reference and SDK examples, see https://buildwithfern.com/learn/llms-full.txt.

# aiohttp 支持

> Fern 生成的 Python SDK 自动检测 aiohttp 用于异步 HTTP 操作，解决 DNS 并发问题，无需代码更改。

每个 Fern 生成的 Python SDK 都内置了对 [aiohttp](https://docs.aiohttp.org/) 作为异步 HTTP 传输的可选支持。当安装了 `aiohttp` 可选额外依赖时，生成的异步客户端会自动使用它，而不是默认的 `httpx.AsyncClient`。

这对于需要进行大量并发异步 API 调用的 SDK 很重要：`httpx.AsyncClient` 在高并发情况下通过 `asyncio.getaddrinfo` 串行化 DNS 查找，而 `aiohttp` 使用自己的解析器来避免这种瓶颈。

无需生成器配置。`[aiohttp]` 额外依赖、运行时自动检测和 CI 覆盖会为每个 Python SDK 生成。

## 安装

SDK 用户可以通过安装 `aiohttp` 额外依赖来选择使用：

```bash
pip install your-package[aiohttp]
```

或者使用 Poetry：

```bash
poetry add "your-package[aiohttp]"
```

如果用户向异步客户端构造函数传递自定义的 `httpx_client`，将跳过自动检测并按原样使用提供的客户端。

## 生成的依赖项

生成的 `pyproject.toml` 包含一个 `[aiohttp]` 可选依赖组：

```toml title="pyproject.toml"
[tool.poetry.extras]
aiohttp = ["aiohttp", "httpx-aiohttp"]
```

如果您通过 `generators.yml` 中的 [`extras`](/learn/sdks/generators/python/configuration#extras) 配置选项定义自己的额外依赖，内置的 `aiohttp` 额外依赖会被保留并与您的自定义配置合并。

## CI 测试

生成的 GitHub Actions 工作流程分两轮运行测试，以覆盖两种传输路径：

1. 不带 aiohttp 额外依赖的标准测试。
2. 安装额外依赖后标记为 `@pytest.mark.aiohttp` 的测试。

要在本地验证 aiohttp 路径：

```bash
poetry install --extras aiohttp
poetry run pytest -m aiohttp
```