freshcrate
Home > Frameworks > anyio

anyio

High-level concurrency and networking framework on top of asyncio or Trio

Description

.. image:: https://github.com/agronholm/anyio/actions/workflows/test.yml/badge.svg :target: https://github.com/agronholm/anyio/actions/workflows/test.yml :alt: Build Status .. image:: https://coveralls.io/repos/github/agronholm/anyio/badge.svg?branch=master :target: https://coveralls.io/github/agronholm/anyio?branch=master :alt: Code Coverage .. image:: https://readthedocs.org/projects/anyio/badge/?version=latest :target: https://anyio.readthedocs.io/en/latest/?badge=latest :alt: Documentation .. image:: https://badges.gitter.im/gitterHQ/gitter.svg :target: https://gitter.im/python-trio/AnyIO :alt: Gitter chat .. image:: https://tidelift.com/badges/package/pypi/anyio :target: https://tidelift.com/subscription/pkg/pypi-anyio :alt: Tidelift 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. To find out why you might want to use AnyIO's APIs instead of asyncio's, you can read about it `here <https://anyio.readthedocs.io/en/stable/why.html>`_. 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 * Subinterpreter support for code parallelization (on Python 3.13 and later) * Asynchronous file I/O (using worker threads) * Signal handling * Asynchronous version of the functools_ module AnyIO also comes with its own pytest_ plugin which also supports asynchronous fixtures. It even works with the popular Hypothesis_ library. .. _asyncio: https://docs.python.org/3/library/asyncio.html .. _Trio: https://github.com/python-trio/trio .. _structured concurrency: https://en.wikipedia.org/wiki/Structured_concurrency .. _nurseries: https://trio.readthedocs.io/en/stable/reference-core.html#nurseries-and-spawning .. _Happy eyeballs: https://en.wikipedia.org/wiki/Happy_Eyeballs .. _pytest: https://docs.pytest.org/en/latest/ .. _functools: https://docs.python.org/3/library/functools.html .. _Hypothesis: https://hypothesis.works/ Security contact information ---------------------------- To report a security vulnerability, please use the `Tidelift security contact`_. Tidelift will coordinate the fix and disclosure. .. _Tidelift security contact: https://tidelift.com/security

Release History

VersionChangesUrgencyDate
4.13.0Imported from PyPI (4.13.0)Low4/21/2026
4.12.1- Changed all functions currently raising the private `NoCurrentAsyncBackend` exception (since v4.12.0) to instead raise the public `NoEventLoopError` exception ([\#1048](https://github.com/agronholm/anyio/issues/1048)) - Fixed `anyio.functools.lru_cache` not working with instance methods ([\#1042](https://github.com/agronholm/anyio/issues/1042))Low1/6/2026
4.12.0- Added support for asyncio's [task call graphs](https://docs.python.org/3/library/asyncio-graph.html) on Python 3.14 and later when using AnyIO's task groups ([\#1025](https://github.com/agronholm/anyio/pull/1025)) - Added an asynchronous implementation of the `functools` module ([\#1001](https://github.com/agronholm/anyio/pull/1001)) - Added support for `uvloop=True` on Windows via the [winloop](https://github.com/Vizonex/Winloop) implementation ([\#960](https://github.com/agronholm/anyio/puLow11/30/2025
4.11.0- Added support for cancellation reasons (the `reason` parameter to `CancelScope.cancel()`) ([\#975](https://github.com/agronholm/anyio/pull/975)) - Bumped the minimum version of Trio to v0.31.0 - Added the ability to enter the event loop from foreign (non-worker) threads by passing the return value of `anyio.lowlevel.current_token()` to `anyio.from_thread.run()` and `anyio.from_thread.run_sync()` as the `token` keyword argument ([\#256](https://github.com/agronholm/anyio/issues/256)) - Added pyLow9/23/2025
4.10.0- Added the `feed_data()` method to the `BufferedByteReceiveStream` class, allowing users to inject data directly into the buffer - Added various class methods to wrap existing sockets as listeners or socket streams: - `SocketListener.from_socket()` - `SocketStream.from_socket()` - `UNIXSocketStream.from_socket()` - `UDPSocket.from_socket()` - `ConnectedUDPSocket.from_socket()` - `UNIXDatagramSocket.from_socket()` - `ConnectedUNIXDatagramSocket.from_Low8/4/2025
4.9.0- Added async support for temporary file handling ([\#344](https://github.com/agronholm/anyio/issues/344); PR by @11kkw) - Added 4 new fixtures for the AnyIO `pytest` plugin: - `free_tcp_port_factory`: session scoped fixture returning a callable that generates unused TCP port numbers - `free_udp_port_factory`: session scoped fixture returning a callable that generates unused UDP port numbers - `free_tcp_port`: function scoped fixture that invokes the `free_tcp_port_factorLow3/17/2025
4.8.0- Added **experimental** support for running functions in subinterpreters on Python 3.13 and later - Added support for the `copy()`, `copy_into()`, `move()` and `move_into()` methods in `anyio.Path`, available in Python 3.14 - Changed `TaskGroup` on asyncio to always spawn tasks non-eagerly, even if using a task factory created via `asyncio.create_eager_task_factory()`, to preserve expected Trio-like task scheduling semantics (PR by @agronholm and @graingert) - Configure `SO_RCVBUF`, Low1/5/2025
4.7.0- Updated `TaskGroup` to work with asyncio's eager task factories ([\#764](https://github.com/agronholm/anyio/issues/764)) - Added the `wait_readable()` and `wait_writable()` functions which will accept an object with a `.fileno()` method or an integer handle, and deprecated their now obsolete versions (`wait_socket_readable()` and `wait_socket_writable()`) (PR by @davidbrochart) - Changed `EventAdapter` (an `Event` with no bound async backend) to allow `set()` to work even before an asyncLow12/5/2024
4.6.2- Fixed regression caused by ([\#807](https://github.com/agronholm/anyio/pull/807)) that prevented the use of parametrized async fixturesLow10/13/2024
4.5.2- Fixed regression caused by ([\#807](https://github.com/agronholm/anyio/pull/807)) that prevented the use of parametrized async fixtures.Low10/13/2024
4.6.1This release contains all the changes from both v4.5.1 and v4.6.0, plus: - Fixed TaskGroup and CancelScope producing cyclic references in tracebacks when raising exceptions ([\#806](https://github.com/agronholm/anyio/pull/806)) (PR by @graingert)Low10/13/2024
4.5.1As Python 3.8 support was dropped in v4.6.0, this interim release was created to bring a regression fix to Python 3.8, and adds a few other fixes also present in v4.6.1. - Fixed acquring a lock twice in the same task on asyncio hanging instead of raising a `RuntimeError` ([\#798](https://github.com/agronholm/anyio/issues/798)) - Fixed an async fixture's `self` being different than the test's `self` in class-based tests ([\#633](https://github.com/agronholm/anyio/issues/633)) (PR by @agronhoLow10/13/2024
4.6.0- Dropped support for Python 3.8 (as [\#698](https://github.com/agronholm/anyio/issues/698) cannot be resolved without cancel message support) - Fixed 100% CPU use on asyncio while waiting for an exiting task group to finish while said task group is within a cancelled cancel scope ([\#695](https://github.com/agronholm/anyio/issues/695)) - Fixed cancel scopes on asyncio not propagating `CancelledError` on exit when the enclosing cancel scope has been effectively cancelled ([\#698](https://gLow9/21/2024
4.5.0- Improved the performance of `anyio.Lock` and `anyio.Semaphore` on asyncio (even up to 50 %) - Added the `fast_acquire` parameter to `anyio.Lock` and `anyio.Semaphore` to further boost performance at the expense of safety (`acquire()` will not yield control back if there is no contention) - Added support for the `from_uri()`, `full_match()`, `parser` methods/properties in `anyio.Path`, newly added in Python 3.13 ([\#737](https://github.com/agronholm/anyio/issues/737)) - Added supportLow9/19/2024
4.4.0- Added the `BlockingPortalProvider` class to aid with constructing synchronous counterparts to asynchronous interfaces that would otherwise require multiple blocking portals - Added `__slots__` to `AsyncResource` so that child classes can use `__slots__` ([\#733](https://github.com/agronholm/anyio/pull/733); PR by Justin Su) - Added the `TaskInfo.has_pending_cancellation()` method - Fixed erroneous `RuntimeError: called 'started' twice on the same task status` when cancelling a task in Low5/26/2024
4.3.0- Added support for the Python 3.12 `walk_up` keyword argument in `anyio.Path.relative_to()` (PR by Colin Taylor) - Fixed passing `total_tokens` to `anyio.CapacityLimiter()` as a keyword argument not working on the `trio` backend ([\#515](https://github.com/agronholm/anyio/issues/515)) - Fixed `Process.aclose()` not performing the minimum level of necessary cleanup when cancelled. Previously: - Cancellation of `Process.aclose()` could leak an orphan process - Cancellation ofLow2/19/2024
4.2.0- Add support for `byte`-based paths in `connect_unix`, `create_unix_listeners`, `create_unix_datagram_socket`, and `create_connected_unix_datagram_socket`. (PR by Lura Skye) - Enabled the `Event` and `CapacityLimiter` classes to be instantiated outside an event loop thread - Broadly improved/fixed the type annotations. Among other things, many functions and methods that take variadic positional arguments now make use of PEP 646 `TypeVarTuple` to allow the positional arguments to be valiLow12/16/2023
4.1.0- Adapted to API changes made in Trio v0.23: - Call `trio.to_thread.run_sync()` using the `abandon_on_cancel` keyword argument instead of `cancellable` - Removed a checkpoint when exiting a task group - Renamed the `cancellable` argument in `anyio.to_thread.run_sync()` to `abandon_on_cancel` (and deprecated the old parameter name) - Bumped minimum version of Trio to v0.23 - Added support for voluntary thread cancellation via `anyio.from_thread.check_cancelled()` - BLow11/22/2023
4.0.0- **BACKWARDS INCOMPATIBLE** Replaced AnyIO\'s own `ExceptionGroup` class with the PEP 654 `BaseExceptionGroup` and `ExceptionGroup` - **BACKWARDS INCOMPATIBLE** Changes to cancellation semantics: - Any exceptions raising out of a task groups are now nested inside an `ExceptionGroup` (or `BaseExceptionGroup` if one or more `BaseException` were included) - Fixed task group not raising a cancellation exception on asyncio at exit if no child tasks were spawned and an outer canceLow8/30/2023

Dependencies & License Audit

Loading dependencies...

Similar Packages

pre-commitA framework for managing and maintaining multi-language pre-commit hooks.v4.6.0
azure-core-tracing-opentelemetryMicrosoft Azure Azure Core OpenTelemetry plugin Library for Pythonazure-template_0.1.0b6187637
spdx-toolsSPDX parser and tools.0.8.5
lacesDjango components that know how to render themselves.0.1.2
django-tasksA backport of Django's built in Tasks framework0.12.0