reloop
Drop-in replacement for nest-asyncio. Allows nested asyncio event loops.
Why reloop?
nest-asyncio has 30M+ downloads/month but was archived in March 2024 after its maintainer passed away. It has known issues with Python 3.12+ (ResourceWarning for unclosed event loops), no way to undo patches, and no support for newer Python internals.
reloop is a maintained, improved replacement:
revert()support — permanently applying patches is optional; you can undo them- Context manager —
with reloop.applied():for scoped patching - Python 3.12+ compatible — no spurious
ResourceWarningfor unclosed event loops - Thread-safe — concurrent
apply()andrevert()calls are safe - Zero dependencies — just stdlib
Installation
pip install reloop
Quick Start
import reloop
reloop.apply()
That's it. Now asyncio.run() and loop.run_until_complete() work inside running event loops — Jupyter notebooks, LLM libraries, web framework sync handlers, and anywhere else Python's RuntimeError: This event loop is already running gets in your way.
Usage
import asyncio
import reloop
reloop.apply()
async def inner():
return 42
async def outer():
# This would normally raise RuntimeError
return asyncio.run(inner())
asyncio.run(outer()) # works
Scoped Patching
with reloop.applied():
asyncio.run(outer()) # patched
asyncio.run(outer()) # raises RuntimeError again
Revert
reloop.apply()
# ... use nested loops ...
reloop.revert() # restore original asyncio behavior
API Reference
reloop.apply() -> None
Patch asyncio to allow nested event loops.
- Idempotent — safe to call multiple times; subsequent calls are no-ops.
- Thread-safe — concurrent calls from multiple threads are safe.
import reloop
reloop.apply()
reloop.revert() -> None
Undo all asyncio patches, restoring original stdlib behavior.
- Idempotent — safe to call multiple times; subsequent calls are no-ops.
- Thread-safe — concurrent calls from multiple threads are safe.
reloop.revert()
reloop.applied() -> contextmanager
Context manager that calls apply() on entry and revert() on exit. Use this when you want nested loop support scoped to a block rather than process-wide.
with reloop.applied():
asyncio.run(outer()) # nested loops work here
asyncio.run(outer()) # raises RuntimeError again after the block
Migration from nest-asyncio
Search and replace:
- import nest_asyncio
- nest_asyncio.apply()
+ import reloop
+ reloop.apply()
Differences from nest-asyncio
revert()support — nest-asyncio patches are permanent; reloop can undo them- Context manager —
with reloop.applied():for scoped patching - Python 3.12+ fixes — no
ResourceWarningfor unclosed event loops - Thread-safe — concurrent
apply()calls are safe - Maintained — nest-asyncio was archived in March 2024
Compatibility
- Python 3.10+
- Zero dependencies
License
MIT
Metadata
Release files for reloop 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| reloop-0.1.0.tar.gz | 31.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| reloop-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 38.1 kB
Release files / reloop-0.1.0.tar.gz
| Download URL | reloop-0.1.0.tar.gz |
|---|---|
| Size | 31.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
80282200177a00dfd547cbe2e25ee077933966ca5774502c53dcdd91ee9e41d8
|
|
BLAKE2b-256 checksum How to use checksums |
77fd67e889a04bb21fa2edb1eca7b0c968c7576d3592310076304457e19e2467
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / reloop-0.1.0-py3-none-any.whl
| Download URL | reloop-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1010afc0fc7864663f55a191584b1f54bb3b56579dddefd8fd4236d000a2a49f
|
|
BLAKE2b-256 checksum How to use checksums |
73f8beea4cf9b82344832aee64b053063f3a9f7647060176be2e069192f04145
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|