{"id":20957,"library":"async-exit-stack","title":"async-exit-stack","description":"A backport of AsyncExitStack from Python 3.7+ for use on Python 3.5 and 3.6. It provides an async context manager that can combine multiple async context managers and cleanup callbacks. Current version 1.0.1, release cadence is low (last release in 2018).","status":"maintenance","version":"1.0.1","language":"python","source_language":"en","source_url":"https://github.com/sorcio/async_exit_stack","tags":["async","context manager","backport","async-exit-stack"],"install":[{"cmd":"pip install async-exit-stack","lang":"bash","label":"Install via pip"}],"dependencies":[],"imports":[{"note":"Common mistake: trying to import from a submodule. The package's top-level __init__.py re-exports AsyncExitStack.","wrong":"from async_exit_stack.async_exit_stack import AsyncExitStack","symbol":"AsyncExitStack","correct":"from async_exit_stack import AsyncExitStack"}],"quickstart":{"code":"import asyncio\nfrom async_exit_stack import AsyncExitStack\n\nasync def main():\n    async with AsyncExitStack() as stack:\n        # enter an async context manager\n        result = await stack.enter_async_context(some_async_context())\n        # push a callback\n        stack.push_async_callback(lambda: asyncio.sleep(0))\n        print('Inside stack')\n    print('Exited stack')\n\nasync def some_async_context():\n    class FakeAsyncCM:\n        async def __aenter__(self):\n            return self\n        async def __aexit__(self, *args):\n            pass\n    return FakeAsyncCM()\n\nasyncio.run(main())","lang":"python","description":"Minimal example using AsyncExitStack to enter an async context manager and push a callback."},"warnings":[{"fix":"Upgrade to Python 3.7+ and use `from contextlib import AsyncExitStack`. Remove dependency on async-exit-stack.","message":"This library is a backport for Python <3.7. Python 3.5 and 3.6 are end-of-life. Use Python 3.7+'s built-in contextlib.AsyncExitStack instead.","severity":"deprecated","affected_versions":"all versions"},{"fix":"Import as `from async_exit_stack import AsyncExitStack`.","message":"The package is named `async-exit-stack` on PyPI, but the import module is `async_exit_stack` (underscore). Confusing these leads to ImportError.","severity":"gotcha","affected_versions":"all versions"},{"fix":"Use `await stack.enter_async_context(cm)` instead of `stack.enter_context(cm)`.","message":"AsyncExitStack.enter_context (sync) is not available; use enter_async_context. Attempting to use enter_context will raise AttributeError.","severity":"gotcha","affected_versions":"all versions"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Run `pip install async-exit-stack` and then use `from async_exit_stack import AsyncExitStack`.","cause":"Package not installed or wrong import name (confused with hyphen name).","error":"ModuleNotFoundError: No module named 'async_exit_stack'"},{"fix":"Ensure you have the correct package installed and no local file named async_exit_stack.py. Uninstall and reinstall: `pip uninstall async-exit-stack` and `pip install async-exit-stack`.","cause":"Imported the module but did not import the class correctly, e.g., `import async_exit_stack` then `async_exit_stack.AsyncExitStack` when the class is not in the module's top-level? Actually it is. More likely: installed a different package or shadowed by a local file.","error":"AttributeError: module 'async_exit_stack' has no attribute 'AsyncExitStack'"},{"fix":"Use `async with AsyncExitStack() as stack:` not `await AsyncExitStack()`.","cause":"Trying to await AsyncExitStack() directly. AsyncExitStack is an async context manager, not a coroutine.","error":"TypeError: object AsyncExitStack can't be used in 'await' expression"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}