rsloop
rsloop is an asyncio event loop written in Rust and packaged for Python.
If you already know normal asyncio, the short version is:
- You still write Python coroutines, tasks, and protocols.
- You swap the event loop implementation to
rsloop. - Rust handles the lower-level loop and I/O work.
This documentation is intentionally small and practical. It is written for junior Python programmers who want to understand both how to use the project and how the repository is organized.
What problem does this project solve?
Python's standard asyncio event loop is written in Python and C. rsloop explores the same idea with a Rust implementation under the hood.
That means:
- your application code stays Python
- the event loop core lives in Rust
- the package aims to support a familiar
asyncioprogramming style
Main ideas
rsloop.run(...)is the easiest way to start.rsloop.new_event_loop()creates a loop object manually.rsloop.Loopis the main event loop class.- Importing
rsloopalso installs a few compatibility patches so it fits better into normalasynciocode.
For Intermediate Python Developers
If you already use asyncio comfortably, these are the main things worth knowing early:
rslooptries to keep the standardasynciomental model, not invent a new one.- The Python package is mostly a thin wrapper around a Rust extension built with PyO3.
rsloop.run(...)behaves like a focusedasyncio.run(...)helper that ensures anrslooploop is actually being used.- Importing
rsloopcan monkeypatch parts ofasyncio, especiallyset_event_loop(...)and optionally stream helpers such asopen_connection(...)andstart_server(...). - The runtime model is hybrid: Python coroutines still run as Python code, while lower-level loop coordination and parts of the I/O stack are handled in Rust.
- Compatibility is a project goal, but not every
asyncioedge case is identical yet, especially around TLS and some transport internals.
If you want to read code instead of only using the package, a good path is:
python/rsloop/_run.pypython/rsloop/_loop_compat.pysrc/lib.rssrc/python_api.rssrc/loop_core.rs
What is inside this repository?
At a high level, the repository has five parts:
- The Python package in
python/rsloop/ - The Rust extension in
src/ - Example programs in
examples/ - Tests in
tests/ - Utility material such as
demo/,benchmarks/, andscripts/
The rest of the docs explain each part in plain language.
Typical usage
import rsloop
async def main() -> None:
print("hello from rsloop")
rsloop.run(main())
Recommended reading order
- Start with Getting Started if you want to use the package.
- Read Rust Extensions if you want to add your own async Rust functions and await them from Python.
- Read Examples if you want copy-paste usage patterns.
- Read How It Works if you want the big picture.
- Read Project Structure if you want to explore the codebase.
- Read Development if you want to build or test the project locally.