async-exit-stack
AsyncExitStack backport for Python 3.5+
What it is and what it does
AsyncExitStack is a backport of Python 3.7's asynchronous context manager from the standard library, extracted into a standalone package for use on Python 3.5 and 3.6. It allows you to combine multiple async context managers and register async cleanup callbacks within a single async with block, ensuring resources are properly released even if exceptions occur during setup.
The package is essentially a copy of CPython's implementation and provides the same API as the standard library version: enter_async_context() to register async context managers, push_async_callback() to register coroutine cleanup handlers, and aclose() to trigger cleanup. It is most useful as a compatibility shim for older Python versions; modern projects targeting Python 3.7+ should use the built-in contextlib.AsyncExitStack instead.
Use it for:
- Managing multiple database or network connections in async code on Python 3.5–3.6 with automatic cleanup.
- Registering async cleanup handlers (e.g., closing resources) that must run even if earlier setup steps fail.
- Combining both sync and async context managers in a single async with block on older Python versions.
- Porting async code from Python 3.7+ back to Python 3.5–3.6 without rewriting resource management logic.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides AsyncExitStack, a backport of Python 3.7's asynchronous context manager for combining and cleaning up both sync and async context managers in async code.
No, unless you are maintaining legacy code on Python 3.5 or 3.6. The package is abandoned and receives no updates. Modern Python versions (3.7+) include AsyncExitStack in the standard library; use that instead. If you must support older Python, this backport works but carries no active maintenance risk mitigation.
Install
async-exit-stack on PyPI
pip
pip install async-exit-stackuv
uv add async-exit-stackpoetry
poetry add async-exit-stackInstalling async-exit-stack
Before you install
Installation is straightforward with no runtime dependencies. However, the package is abandoned—last updated in 2022 with no commits since December 2022—so it receives no active maintenance or security updates.
License in practice
Licensed under the Python Software Foundation License (permissive), which allows free use, modification, and distribution with minimal restrictions.
Quickstart
pip install async-exit-stack
from async_exit_stack import AsyncExitStack
async def example():
async with AsyncExitStack() as stack:
resource = await stack.enter_async_context(get_connection())
# Resource automatically cleaned up on exit
Requires Python 3.5 or later; intended for older Python versions that lack native AsyncExitStack support.
Verify before relying
- Whether AsyncExitStack is still needed: Python 3.7+ includes it in the standard library contextlib module.
- Compatibility with Python versions beyond 3.6: classifiers list only 3.5 and 3.6, but requires_python states >=3.5.
Package facts
| License | Python Software Foundation License (permissive) |
| Python support | supports the current Python release (>=3.5) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | abandoned — 3,021 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 88,016/month — #13,754 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: async_exit_stack-1.0.1-py3-none-any.whl
Keywords: async_exit_stack
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
async_generatorProvides async generators and async context…
permissive · top 5,000 on PyPI
asyncio-atexitRegisters cleanup functions to run when an…
permissive · top 15,000 on PyPI
backports.weakrefBackports the `weakref.finalize` class from…
permissive · top 5,000 on PyPI
asyncioThis package is an obsolete backport of…
permissive · top 1,000 on PyPI
contextlib2contextlib2 backports the Python standard…
permissive · top 5,000 on PyPI
aiotoolsaiotools provides idiomatic asyncio utilities…
permissive · top 15,000 on PyPI
uncalled-forProvides async dependency injection for Python…
permissive · top 1,000 on PyPI
pyleakDetects leaked asyncio tasks, threads, and…
unclear · top 15,000 on PyPI
backports.asyncio.runnerProvides the Python 3.11 asyncio.Runner context…
permissive · top 1,000 on PyPI
contextvarsProvides the PEP 567 contextvars module for…
permissive · top 5,000 on PyPI