Registry / http-networking / anyio
library4.14.2pypypi✓ verified 25d ago

AnyIO is a high-level asynchronous networking and concurrency library that runs on top of either asyncio or Trio, implementing Trio-like structured concurrency on both backends. Code written against AnyIO's API runs unmodified on either backend, allowing incremental adoption. Current stable version is 4.13.0, with an active monthly-ish release cadence under Alex Grönholm (agronholm).

pip install anyio
INSTALL
IMPORT
SIG · ANYIO
A
anyio
http-networkingpythonv4.14.2
Install
2.9s avg
Import
183ms
Disk
37MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v4.14.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.915 runs
installs and imports cleanly · install 0.0s · import 0.189s · 37.6MB
glibc
py 3.103.915 runs
installs and imports cleanly · install 2.9s · import 0.176s · 38MB
37MB installed
● package 37MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

anyio
import anyio
import anyio

Demonstrates concurrent task groups, move_on_after timeout scopes, and offloading blocking calls to a worker thread — all backend-agnostic.

import anyio async def fetch(name: str, delay: float) -> None: print(f'{name}: starting') await anyio.sleep(delay) print(f'{name}: done after {delay}s') async def main() -> None: # Task group: all tasks run concurrently; exceptions surface as ExceptionGroup async with anyio.create_task_group() as tg: tg.start_soon(fetch, 'task-A', 1.0) tg.start_soon(fetch, 'task-B', 0.5) # Timeout via CancelScope with anyio.move_on_after(2.0) as scope: await anyio.sleep(5) if scope.cancelled_caught: print('timed out (moved on)') # Run a blocking call in a thread import time result = await anyio.to_thread.run_sync(time.strftime, '%X') print('wall-clock time from thread:', result) if __name__ == '__main__': # Default backend is asyncio; swap to 'trio' with no code changes anyio.run(main, backend='asyncio')
Debug
Known issues
breakingIn AnyIO 4, task groups always raise ExceptionGroup (PEP 654) when any child task raises. The old anyio.ExceptionGroup class was removed. Code catching exceptions from task groups must use 'except*' syntax (Python 3.11+) or the 'exceptiongroup' backport on older Pythons.
fix
Use 'except* ValueError as eg:' on Python 3.11+, or install the 'exceptiongroup' package and import ExceptionGroup from it on Python 3.10.
affects: <4.0
breakingTaskGroup.spawn() was removed in AnyIO 4. Calling it raises AttributeError.
fix
Replace 'await tg.spawn(fn, arg)' with the synchronous 'tg.start_soon(fn, arg)' (no await).
affects: <4.0
breakingstart_blocking_portal() was moved to anyio.from_thread and must be used as a synchronous context manager. Importing it from the top-level anyio namespace raises ImportError.
fix
Use: from anyio.from_thread import start_blocking_portal
with start_blocking_portal() as portal: portal.call(fn)
affects: <3.0
deprecatedThe 'item_type' keyword argument to create_memory_object_stream() is deprecated and will be removed in a future major version.
fix
Use the generic syntax: create_memory_object_stream[MyType](max_buffer_size=N)
affects: >=4.0
deprecatedThe 'cancellable' parameter of to_thread.run_sync() is a deprecated alias for 'abandon_on_cancel'. Passing it emits a DeprecationWarning.
fix
Replace cancellable=True with abandon_on_cancel=True.
affects: >=4.x
gotchaanyio.Path cannot be substituted for pathlib.Path. APIs expecting a pathlib.Path will reject an anyio.Path instance; convert with str(path) or pass the underlying pathlib.Path via path._path (private, unstable).
fix
Pass str(anyio_path) to third-party APIs expecting pathlib.Path, or open the file with await anyio_path.open() and hand the file object over.
affects: all
gotchaMixing native asyncio tasks (asyncio.create_task) with AnyIO cancel scopes can cause tasks spawned outside AnyIO to escape cancellation, and await inside a finally block can receive multiple CancelledError instances under scoped cancellation.
fix
Spawn all concurrent work through anyio.create_task_group().start_soon() and avoid bare asyncio.create_task() inside AnyIO-managed code.
affects: all
Upgrade
Version history
4.14.2latest on PyPI · released Jul 12, 2026
Audit
Dependencies
triooptionalRequired only for the Trio backend; install via anyio[trio] extra
idnaoptionalUsed for IDNA 2008 hostname resolution on asyncio; installed automatically
exceptiongroupoptionalBackport of PEP 654 ExceptionGroup for Python < 3.11; required if catching exception groups on older Pythons
Agent activity
61 hits · last 30 days
node
56
OpenAI (training)
1
Resources
anyio — pip install anyio · libregistry