# AnyIO — card for AI agents

Async I/O framework supporting both asyncio and Trio with high-level networking abstractions.

Category: HTTP clients and networking · PyPI package `anyio` · latest version 4.15.1 (checked 2026-11-01)
Install: `pip install anyio`
License: MIT (permissive)

In your own product (generator, app, hosted service): **yes**. Permissive license: ship it inside your own product, closed or open source, and keep its license and copyright notice.

## Numbers (AgentGid data)
- Gid Score: 73.0 (#272 of all tools, 16 of 126 in its category)
- Used in 92 public projects set up for AI coding agents (1.5%)
- Downloads last week: 260,759,126 (as of 2026-11-24), +19.1% over 4 weeks
- GitHub stars: 2,572 (as of 2026-11-24)
- Last push: 2026-11-24

## Often used with
Pydantic 82.6%, Uvicorn 81.5%, python-dotenv 72.8%, FastAPI 59.8%, Requests 57.6%, Click 57.6%

## Checked alternatives (same job)
- httpx: https://agentgid.com/tools/httpx/agent.md
- aiohttp: https://agentgid.com/tools/aiohttp/agent.md
- urllib3: https://agentgid.com/tools/urllib3/agent.md

## Links
- AgentGid page: https://agentgid.com/tools/anyio/
- Repository: https://github.com/agronholm/anyio


## AnyIO: run many waiting tasks at once in Python

AnyIO is a free Python library for code that waits a lot, such as network calls, so it can do many of those waits at the same time. It adds safe task groups, timeouts and a way to run slow ordinary code in the background. Code written with it runs on Python's built-in asyncio or on Trio without changes.

### Where to use it
- Run slow calls side by side: Your app fetches three files or pages; instead of waiting for each in turn, it starts all three and waits once.
- Give up on a stuck call: A call to an outside service hangs; your code stops waiting after a set time and goes on.
- Use blocking code without freezing: An old library or an image resize blocks; running it in a worker thread keeps your app answering other requests.
- One library for asyncio and Trio: You publish a package and do not want to force users onto one async system; AnyIO code runs on both.
- Test async code with pytest: Your tests call async functions; the plugin that comes with AnyIO runs them, with nothing extra to install.
- Start a server, then use it: A test or a dev script starts a local service and waits until it is listening before it connects.

### How to start
- Install it (Python 3.10 or newer); add the trio extra only if you want Trio.

```
pip install anyio
```

- Write an async main function and start it with anyio.run.

```
from anyio import run

async def main() -> None:
    print("Hello, world!")

run(main)
```

- Start several tasks in a task group; the block ends when all of them are done.

```
async with create_task_group() as tg:
    for num in range(5):
        tg.start_soon(sometask, num)
```


### License
Free to use in paid and closed products under the MIT license. Keep the license notice if you ship AnyIO's own files.

### Good to know
- It needs Python 3.10 or newer.
- In version 4, an error inside a task group always arrives wrapped in an ExceptionGroup, even when only one task failed.
- Cancelling a task that waits on a worker thread does not stop the thread; the thread keeps running and its result is dropped.
- Its test plugin can clash with pytest-asyncio when both use automatic mode.
- The project is active; version 4.16.0 came out on 1 November 2026.

Checked 2026-11-11 against: https://anyio.readthedocs.io/en/stable/, https://anyio.readthedocs.io/en/stable/basics.html, https://anyio.readthedocs.io/en/stable/tasks.html, https://anyio.readthedocs.io/en/stable/threads.html, https://anyio.readthedocs.io/en/stable/cancellation.html, https://anyio.readthedocs.io/en/stable/testing.html, https://anyio.readthedocs.io/en/stable/migration.html, https://anyio.readthedocs.io/en/stable/versionhistory.html, https://github.com/agronholm/anyio/blob/master/README.rst, https://github.com/agronholm/anyio/blob/master/LICENSE, https://pypi.org/pypi/anyio/4.16.0/json, https://pypi.org/pypi/anyio/json

### Mistakes to avoid
- Don't: try: async with create_task_group() ... except ValueError: → Do: except* ValueError:  (Python 3.11+), or exceptiongroup.catch on older Python (AnyIO 4 wraps even a single error in an ExceptionGroup; in our run except ValueError did not catch it.)
- Don't: async with move_on_after(5): → Do: with move_on_after(5):  (also fail_after) (Timeout scopes are plain context managers, not async ones.)
- Don't: to_thread.run_sync(fn, cancellable=True) → Do: to_thread.run_sync(fn, abandon_on_cancel=True) (The argument was renamed in AnyIO 4.1 and the old name is deprecated.)
- Don't: time.sleep() or requests.get() directly inside an async function → Do: await anyio.sleep(); await anyio.to_thread.run_sync(requests.get, url) (Blocking calls stop every other task until they return.)
- Don't: asyncio_mode = "auto" (pytest-asyncio) together with AnyIO tests → Do: Use pytestmark = pytest.mark.anyio, or remove asyncio_mode so pytest-asyncio stays in strict mode (The two plugins in auto mode conflict.)

### Questions
- Do I need Trio to use it? No. It runs on Python's built-in asyncio by default; Trio is an optional extra.
- Why does except ValueError not catch the error from my task group? Since AnyIO 4 the error comes inside an ExceptionGroup. Use except* ValueError on Python 3.11+, or the exceptiongroup backport.
- What is the difference between move_on_after and fail_after? move_on_after quietly leaves the block when time is up; fail_after raises a TimeoutError.
- Can I mix it with plain asyncio code? Yes. It can be adopted bit by bit and blends in with the libraries of the async system you use.

---
AgentGid's catalog is curated: every entry was checked against the maker's official pages (registry, repository, license and pricing pages) on the date shown; a license value shows the quote it stands on wherever AgentGid has one. Usage numbers come from AgentGid's own scan of public repositories set up for AI coding agents. Claims by makers are reported, not tested by AgentGid.
