How agronholm/anyio works
AnyIO is a backend-neutral asynchronous networking and concurrency library. Applications call its APIs to run structured tasks and perform networking, stream I/O, synchronization, and blocking-work operations over either asyncio or Trio. Networking includes endpoint resolution, connection/listener creation, and optional TLS wrapping. The package also covers subprocesses, files, signals, cross-thread calls, subinterpreters, and async testing. The graph emphasizes the sampled event-loop, task, socket, stream, and backend paths; other README-listed capabilities are retained, but their internal call links are omitted where source was not sampled.
Main entry points: _eventloop.py Event loop API · _sockets.py Socket operations · _tasks.py Task groups · _asyncio.py Asyncio backend
Components 24
Runtime and tasks
- Event loop API
src/anyio/_core/_eventloop.py - Task groups
src/anyio/_core/_tasks.py - Task contracts
src/anyio/abc/_tasks.py - Asyncio backend
src/anyio/_backends/_asyncio.py - Trio backend
src/anyio/_backends/_trio.py - Low-level API
src/anyio/lowlevel.py
Networking and streams
- Socket operations
src/anyio/_core/_sockets.py - Socket contracts
src/anyio/abc/_sockets.py - Backend sockets
src/anyio/_backends/_asyncio.py - Stream contracts
src/anyio/abc/_streams.py - Memory streams
src/anyio/streams/memory.py - TLS streams
src/anyio/streams/tls.py
Blocking and parallel work
- Worker threads
src/anyio/to_thread.py - Subprocesses
src/anyio/to_process.py - Subinterpreters
src/anyio/to_interpreter.py - Thread portal
src/anyio/from_thread.py
I/O and testing
- Async files
src/anyio/_core/_fileio.py - Synchronization
src/anyio/_core/_synchronization.py - Async utilities
src/anyio/functools.py - Async iteration
src/anyio/itertools.py - Signal handling
src/anyio/_core/_signals.py - Async testing
src/anyio/_core/_testing.py - Pytest plugin
src/anyio/pytest_plugin.py
Other components
- Application
Connections 30
- Application → Event loop API: runs through
- Application → Task groups: starts tasks
- Application → Socket operations: uses networking
- Application → Worker threads: offloads work
- Application → Subprocesses: runs subprocesses
- Application → Subinterpreters: parallelizes work
- Application → Async files: uses async files
- Application → Synchronization: synchronizes tasks
- Application → Async utilities: uses utilities
- Application → Async iteration: uses iteration
- Application → Signal handling: handles signals
- Application → Pytest plugin: tests asynchronously
- Event loop API → Asyncio backend: selects backend
src/anyio/_backends/_asyncio.py - Event loop API → Trio backend: selects backend
src/anyio/_backends/_trio.py - Task groups → Asyncio backend: delegates to
src/anyio/_core/_tasks.py - Task groups → Task contracts: implements contracts
src/anyio/_core/_tasks.py - Asyncio backend → Task contracts: implements
src/anyio/_backends/_asyncio.py - Trio backend → Task contracts: implements
src/anyio/_backends/_trio.py - Socket operations → Backend sockets: requests socket wrapping
src/anyio/_core/_sockets.py - Socket operations → TLS streams: wraps with TLS
src/anyio/_core/_sockets.py - Socket operations → Socket contracts: uses contracts
src/anyio/abc/_sockets.py - Asyncio backend → Socket contracts: implements
src/anyio/_backends/_asyncio.py - Trio backend → Socket contracts: implements
src/anyio/_backends/_trio.py - Memory streams → Stream contracts: implements
src/anyio/streams/memory.py - TLS streams → Stream contracts: implements
src/anyio/streams/tls.py - TLS streams → Worker threads: offloads TLS work
src/anyio/streams/tls.py - Async files → Worker threads: uses worker threads
src/anyio/_core/_fileio.py - Thread portal → Task groups: runs async tasks
src/anyio/from_thread.py - Pytest plugin → Event loop API: uses event loop
src/anyio/pytest_plugin.py - Low-level API → Event loop API: exposes runtime controls