Skip to content
Agents tracked: 506 Releases (7d): 634 Agent status: 3 with issuesSince last limit reset: Claude 15d · Codex 0d For AI agents: Markdown Updated Nov 26, 2026

AnyIO

Run many waiting tasks at once in Python.

HTTP clients and networkingPYPI

GitHub

1. License

“Permission is hereby granted, free of charge, to any person obtaining a copy”

MIT allows use in paid and closed-source products.

github.com/agronholm/anyio/blob/master/LICENSE

From the package registry and GitHub, checked daily; card checked Nov 11, 2026. Tap a verdict to see its source.How we checkedReport an error

What AnyIO does

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.

What people build with 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.

AnyIO popularity

73 / 100
Gid Score, #272 overall
261M
downloads a week, pypi
2,572
GitHub stars
92
agent projects use it
AnyIO: downloads per weekPyPI, anyio 259,257,493
AnyIO: GitHub starsagronholm/anyio 2,572

Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated

How AnyIO is used

  • AnyIO is a dependency in 92 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (5.7% of the 1,623 Python ones), #14 of 126 in http clients and networking.
  • Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 1,390; those are left out of every share on this page.
  • The most used alternative in our scan is httpx (280 projects).
  • Projects that use it most often also use Pydantic (82.6%), Uvicorn (81.5%), python-dotenv (72.8%).

By coding agent

50 projects, 1.6%
49 projects, 1.5%
31 projects, 1.3%
10 projects, 3.0%
6 projects, 1.3%
5 projects, 1.1%

Often used with

In 82.6% of its projects
In 81.5% of its projects
In 72.8% of its projects
In 59.8% of its projects
In 57.6% of its projects
In 57.6% of its projects

More about AnyIO

Funding
  • Tidelift: https://tidelift.com/funding/github/pypi/anyio

See all

More in HTTP clients and networking

Alternatives

AnyIO This page

MITGid 73261M/wk

Trio

Pick Trio when you are fine with one async system and want its structured concurrency directly.

Asyncer

Pick Asyncer when you want a thin, typed helper layer on top of AnyIO for mixing async and regular code.

gevent

Pick gevent for older code written without async and await that should still handle many connections.

httpx

Modern Python HTTP client with async support, replacing the standard requests library.

BSDGid 78198M/wk

aiohttp

Async HTTP client/server framework for Python with WebSocket support.

Apache-2.0 AND MITGid 81134M/wk

urllib3

HTTP client with thread-safe connection pooling, file uploads and advanced features.

MITGid 75376M/wk

Compare AnyIO with another tool

Get started

Tell your AI assistant

“Use anyio 4.16.0 (Python 3.10+) for concurrency: run independent awaits in anyio.create_task_group(), wrap slow calls in with anyio.fail_after(seconds), run blocking functions with await anyio.to_thread.run_sync(fn), and catch task group errors with except* because AnyIO 4 raises ExceptionGroup.”

  1. Install it (Python 3.10 or newer); add the trio extra only if you want Trio.

    pip install anyio

    From anyio.readthedocs.io/en/stable/basics.html

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

    from anyio import run
    
    async def main() -> None:
        print("Hello, world!")
    
    run(main)
    

    From anyio.readthedocs.io/en/stable/basics.html

  3. 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)
    

    From anyio.readthedocs.io/en/stable/tasks.html

Mistakes to avoid

try: async with create_task_group() ... except ValueError:
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.

async with move_on_after(5):
with move_on_after(5): (also fail_after)

Timeout scopes are plain context managers, not async ones.

to_thread.run_sync(fn, cancellable=True)
to_thread.run_sync(fn, abandon_on_cancel=True)

The argument was renamed in AnyIO 4.1 and the old name is deprecated.

time.sleep() or requests.get() directly inside an async function
await anyio.sleep(); await anyio.to_thread.run_sync(requests.get, url)

Blocking calls stop every other task until they return.

asyncio_mode = "auto" (pytest-asyncio) together with AnyIO tests
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.