nest-asyncio2
Patch asyncio to allow nested event loops
Decision gist · record as of 2026-08-14
Yes, if you need to run async code from within an already-running event loop. The package is lightweight, has no dependencies, and is actively maintained with broad Python version support. The aging maintenance status (182 days since release) is not a concern given the repository is not archived and recent commits exist. No known vulnerabilities. The leaked event loop caveat on Python 3.12+ is minor and documented; use `run_close_loop=True` if it matters for your use case.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires Python 3.5 or higher.
- Only patches asyncio event loops; loops from other projects like uvloop or quamash cannot be patched.
- Low friction: pure Python wheel with no runtime dependencies.
License · maintenance · safety
BSD (permissive) — BSD license is permissive; you can use this package freely in commercial and private projects with minimal restrictions.
last release 2026-02-13 (182 days) · last repo commit 2026-02-13 · 20 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 41,911,695 downloads/mo, #665 on PyPI
Alternatives
Verify before relying
pip install nest-asyncio2
import nest_asyncio2
nest_asyncio2.apply()
# Now asyncio.run() works even if an event loop is already running
asyncio.run(some_async_function())- Whether the leaked event loop behavior (ResourceWarning on Python 3.12+) will impact your specific use case or environment.
- Compatibility with projects that may already be patched by the original unmaintained nest_asyncio package.
What it is and what it does
nest-asyncio2 solves a fundamental asyncio limitation: by design, Python's asyncio does not allow nested event loops, which causes `RuntimeError: This event loop is already running` when you try to call `asyncio.run()` or `loop.run_until_complete()` from within code that is already executing inside an event loop. This is a practical problem in Jupyter notebooks, web servers, and GUI applications where an event loop is already active.
The package patches asyncio's internals to permit nesting, allowing you to run async code synchronously even when an event loop is already running. It is a fork of the unmaintained original nest_asyncio, with updates for Python 3.12 and 3.14, a `run_close_loop` option to control event loop cleanup, and warnings if conflicting patches are detected. Installation is frictionless (no dependencies), and it supports Python 3.5 through 3.14.
Use it for
- Running async functions from a Jupyter notebook cell without encountering the 'event loop already running' error.
- Calling async code from a synchronous wrapper function in a web framework that already manages an event loop.
- Mixing async and sync code in GUI applications where the event loop is managed by the framework.
- Testing async functions in a test runner that may already have an active event loop.
- Wrapping async libraries (like aiohttp) for use in environments with pre-existing event loops.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes, if you need to run async code from within an already-running event loop.
The package is lightweight, has no dependencies, and is actively maintained with broad Python version support. The aging maintenance status (182 days since release) is not a concern given the repository is not archived and recent commits exist. No known vulnerabilities. The leaked event loop caveat on Python 3.12+ is minor and documented; use `run_close_loop=True` if it matters for your use case.
Install
nest-asyncio2 on PyPI
Before you install
Low friction: pure Python wheel with no runtime dependencies. Maintenance status is aging (182 days since last release), but the repository is active and not archived, with recent commits and explicit support for Python 3.5 through 3.14.
Requires Python 3.5 or higher. Only patches asyncio event loops; loops from other projects like uvloop or quamash cannot be patched.
License in practice
BSD license is permissive; you can use this package freely in commercial and private projects with minimal restrictions.
Quickstart
pip install nest-asyncio2
import nest_asyncio2
nest_asyncio2.apply()
# Now asyncio.run() works even if an event loop is already running
asyncio.run(some_async_function())
Verify before relying
- Whether the leaked event loop behavior (ResourceWarning on Python 3.12+) will impact your specific use case or environment.
- Compatibility with projects that may already be patched by the original unmaintained nest_asyncio package.
Package facts
| License | BSD permissive |
| Python support | Supports the current Python release >=3.5 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | None |
| Maintenance | Aging 182 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 41,911,695 / month, #665 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Development Status :: 5 - Production/StableFramework :: AsyncIOIntended Audience :: DevelopersLicense :: OSI Approved :: BSD LicenseProgramming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.5Programming Language :: Python :: 3.6Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9 |
Evidence: nest_asyncio2-1.7.2-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “asyncio.run in jupyter notebooks”
- nest-asyncio2Patches asyncio to allow nested event loops, enabling `asyncio.run()`…
- nest-asyncioPatches asyncio to allow nested event loops, enabling asyncio.run()…
- nbclientnbclient executes Jupyter notebooks programmatically in different…
Give your agent the search over MCP, or paste the wish link into any chat.
Similar packages
qasync integrates asyncio coroutines into PyQt/PySide applications by providing a PEP 3156 event loop, allowing async/await syntax directly in Qt's main thread without threading.
Install it if you're building a PyQt/PySide application and want to use async/await instead of threading.
Detects leaked asyncio tasks, threads, and event loop blocking in Python code using context managers or decorators, reporting violations with stack traces.
However, verify the license terms first (currently unclear in the metadata), and note that the project is aging—last release was 197 days ago.
uvloop is a drop-in replacement for Python's built-in asyncio event loop, implemented in Cython and using libuv, that accelerates async I/O operations.
Decorator-based library that runs async functions in an ambient event loop and regular functions in thread or process pools, returning awaitable futures that combine asyncio and concurrent.futures semantics.
However, dormancy since 2021-10-21 and unspecified Python version support mean you should verify compatibility with your target Python version before committing.
Winloop is a Windows-compatible alternative to uvloop that replaces the standard asyncio event loop with a faster, libuv-based implementation optimized for Windows.
Adds a concurrent monitor and interactive Python REPL to asyncio applications, accessible via telnet or a built-in CLI client, allowing inspection and control of running tasks without blocking the event loop.
See also nest-asyncio · synchronicity · aiofastnet · asynctest