AnyIO
AnyIO is an asynchronous networking and concurrency library that works on top of either asyncio or trio. It implements trio-like structured concurrency (SC) on top of asyncio and works in harmony with the native SC of trio itself.
Applications and libraries written against AnyIO’s API will run unmodified on either asyncio or trio. AnyIO can also be adopted into a library or application incrementally – bit by bit, no full refactoring necessary. It will blend in with the native libraries of your chosen backend.
Documentation
View full documentation at: https://anyio.readthedocs.io/
Features
AnyIO offers the following functionality:
Task groups (nurseries in trio terminology)
High-level networking (TCP, UDP and UNIX sockets)
Happy eyeballs algorithm for TCP connections (more robust than that of asyncio on Python 3.8)
async/await style UDP sockets (unlike asyncio where you still have to use Transports and Protocols)
A versatile API for byte streams and object streams
Inter-task synchronization and communication (locks, conditions, events, semaphores, object streams)
Worker threads
Subprocesses
Asynchronous file I/O (using worker threads)
Signal handling
AnyIO also comes with its own pytest plugin which also supports asynchronous fixtures. It even works with the popular Hypothesis library.
The manual
- The basics
- Creating and managing tasks
- Cancellation and timeouts
- Using synchronization primitives
- Streams
- Using typed attributes
- Using sockets and streams
- Working with threads
- Running a function in a worker thread
- Calling asynchronous code from a worker thread
- Calling synchronous code from a worker thread
- Calling asynchronous code from an external thread
- Spawning tasks from worker threads
- Using asynchronous context managers from worker threads
- Context propagation
- Adjusting the default maximum worker thread count
- Reacting to cancellation in worker threads
- Sharing a blocking portal on demand
- Using subprocesses
- Asynchronous file I/O support
- Receiving operating system signals
- Testing with AnyIO
- API reference
- Event loop
- Asynchronous resources
- Typed attributes
- Timeouts and cancellation
- Task groups
- Running code in worker threads
- Running code in worker processes
- Running asynchronous code from other threads
- Async file I/O
- Streams and stream wrappers
- Sockets and networking
- Subprocesses
- Synchronization
- Operating system signals
- Low level operations
- Testing and debugging
- Exceptions
- Migrating from AnyIO 3 to AnyIO 4
- Migrating from AnyIO 2 to AnyIO 3
- Frequently Asked Questions
- Getting help
- Reporting bugs
- Contributing to AnyIO
- Version history