multiloop: Multi-Event-Loop Engine & Concurrency Toolkit for Python 3.14t
⚡ A high-performance multi-event-loop concurrency toolkit and Web server engine for Python 3.14t (Free-Threaded / No-GIL), powered by an ultra-fast Rust SIMD core.
Table of Contents
- 1. Installation
- 2. Verified Performance & Benchmarks
- 3. Web Server CLI
- 4. Python API Usage
- 5. Architecture & Developer Guide
- 6. Miscellaneous & Community
1. Installation
Prerequisites
- Python 3.14+: Free-Threaded (no-GIL) build, e.g.
python3.14t. - Rust Toolchain: Stable (via rustup) to compile the
_multiloop_coreRust extension.
Install with uv (Recommended)
# Add multiloop to your project
uv add multiloop
# Or install into the current active virtual environment
uv pip install multiloop
Install with pip
pip install multiloop
Build from source
# Clone and compile optimized release extension via maturin
git clone https://github.com/hankaihong1/multiloop.git
cd multiloop
maturin develop --release
2. Verified Performance & Benchmarks
Multi-Core Throughput (Python 3.14t)
multiloop achieves linear physical multi-core scalability without GIL bottlenecks.
3-round average benchmark metrics on Apple M1 (8 Cores, 8GB RAM, Python 3.14.6 Free-Threaded No-GIL):
| Workload (Benchmark Scenario) | Single loop (1-Worker) | multiloop 4-worker | multiloop 8-worker | Max Speedup |
|---|---|---|---|---|
JSON Ping API (GET /api/ping) |
44,302 req/s | 72,134 req/s | 62,234 req/s | 1.63x |
POST Request Body (POST /api/items) |
35,034 req/s | 58,915 req/s | 62,144 req/s | 1.77x |
| CPU-bound Dispatch (40 × 2M ops) | 2.88 s | 0.79 s | 0.60 s | 4.83x |
| Mixed I/O + CPU (400 tasks, SHA-256) | 134.0 req/s | 176.7 req/s | 116.6 req/s | 1.32x |
Reproducing Benchmarks
Run the built-in cross-platform pure-Python socket benchmark suite directly on your system (zero external dependencies like ab required):
uv run python benchmarks/bench_asgi_throughput.py
3. Web Server CLI
multiloop includes a high-performance CLI server runner. Unlike traditional multi-process process managers (gunicorn -w 4 or uvicorn --workers 4), multiloop run operates across multi-threaded isolated event loops in a single process with shared memory and zero IPC serialization overhead.
Run a FastAPI Application
Create main.py:
from fastapi import FastAPI
app = FastAPI(title="My multiloop API")
@app.get("/")
def read_root():
return {"message": "Hello from FastAPI on multiloop!"}
Start the multi-worker server with 1 command:
multiloop run main:app --port 8000 --workers 4 --reload
Open http://127.0.0.1:8000/docs to view the live interactive Swagger UI!
Run a Flask or Django Application
multiloop run automatically detects WSGI applications (PEP 3333). Create app.py:
from flask import Flask
app = Flask(__name__)
@app.route("/")
def index():
return "Hello from Flask running on multiloop WSGI thread pool!"
Launch the WSGI application with multi-thread pool offloading:
multiloop run app:app --port 5000 --workers 4
CLI Parameter Reference
multiloop run <module:app> [OPTIONS]
| Option | Default | Description |
|---|---|---|
<module:app> |
(Required) | Application import string, e.g. main:app or my_project.wsgi:application |
--host |
127.0.0.1 |
Network interface to bind on (0.0.0.0 for public access) |
--port |
8000 |
Port to bind on (0 for ephemeral random port) |
--workers |
auto |
Number of worker event loop threads (defaults to CPU core count) |
--reload |
off |
Enable automatic hot-reloading upon file modifications |
--interface |
auto |
Protocol interface: auto, asgi (FastAPI/Starlette), or wsgi (Django/Flask) |
--log-level |
info |
Logging verbosity: debug, info, warning, error |
4. Python API Usage
1. Multi-Core Thread Pool (asyncssh style)
import asyncio
import multiloop
async def heavy_task(x: int) -> int:
await asyncio.sleep(0.01)
return x * 2
async def main() -> None:
# async with manages the pool lifecycle automatically
async with multiloop.EventLoopThreadPool(num_threads=4) as pool:
# Submit an async coroutine (shared queue + work-stealing scheduler)
fut1 = pool.submit(heavy_task, 21)
# Target a specific worker loop (stateful connection affinity)
fut2 = pool.submit(heavy_task, 21, pin_to=0)
# Await results computed across physical CPU cores
print("Results:", await fut1, await fut2) # Output: 42 42
if __name__ == "__main__":
asyncio.run(main())
2. Go-Style Channel & select_channel
import asyncio
import multiloop
async def main() -> None:
ch1: multiloop.Channel[str] = multiloop.Channel()
ch2: multiloop.Channel[str] = multiloop.Channel()
async def producer() -> None:
await ch1.send("Data from Channel 1")
ch1.close()
asyncio.create_task(producer())
# select_channel waits for the first channel that becomes ready
selected_ch, val = await multiloop.select_channel(ch1, ch2)
print(f"Received: {val}")
if __name__ == "__main__":
asyncio.run(main())
3. Task Synchronization with AsyncWaitGroup
import asyncio
import multiloop
async def worker(name: str, wg: multiloop.AsyncWaitGroup) -> None:
try:
await asyncio.sleep(0.02) # simulated asynchronous work
print(f"worker {name} done")
finally:
wg.done() # decrement counter safely on completion or error
async def main() -> None:
wg = multiloop.AsyncWaitGroup()
# Dispatch 5 tasks across a 4-thread pool
async with multiloop.EventLoopThreadPool(num_threads=4) as pool:
for i in range(5):
wg.add() # increment counter
pool.submit(worker, f"task-{i}", wg)
# Block until all tasks finish (counter reaches zero)
await wg.wait()
print("All workers finished cleanly!")
if __name__ == "__main__":
asyncio.run(main())
4. Structured Concurrency with TaskGroup
import asyncio
import multiloop
async def fetch(name: str, delay: float) -> str:
await asyncio.sleep(delay) # simulated network latency
return f"{name}: ok"
async def main() -> None:
try:
# fail_after sets an overall deadline for the entire taskgroup
async with multiloop.fail_after(0.1):
async with multiloop.TaskGroup() as tg:
h1 = tg.start_soon(fetch, "fast", 0.01)
h2 = tg.start_soon(fetch, "slow", 0.5)
print(await h1, "|", await h2)
except TimeoutError:
print("Timed out: child tasks cancelled safely")
if __name__ == "__main__":
asyncio.run(main())
Explore more standalone scripts in examples/.
5. Architecture & Developer Guide
Core Architecture
multiloop assigns an isolated asyncio event loop to each worker OS thread, backed by lock-free task queues and padded atomic metrics in Rust:
graph TD
UserApp[User Application / FastAPI / ASGI 3.0] -->|pool.submit| Scheduler[Round-Robin Scheduler]
subgraph multiloop Core Engine
Scheduler -->|Round-Robin Notify| W1[Worker Loop Thread 1]
Scheduler -->|Round-Robin Notify| W2[Worker Loop Thread 2]
Scheduler -->|Round-Robin Notify| W3[Worker Loop Thread 3]
W1 <-->|Atomic Metrics| RustCore[Rust C-Extension _multiloop_core]
W2 <-->|Atomic Metrics| RustCore
W3 <-->|Atomic Metrics| RustCore
end
subgraph Golang Concurrency Toolkit
RustCore <--> FastChan[Channel / flume]
FastChan <--> Select[multiloop.select_channel]
FastChan <--> Context[AsyncContext]
RustCore <--> WaitGroup[AsyncWaitGroup]
end
Local Development & Testing Gates
# 1. Build and install release Rust extension
make develop
# 2. Run all linter & type checks (0 warnings, strict typing)
make lint
# 3. Run complete test suite (355+ tests)
make test
6. Miscellaneous & Community
Known Limits & Invariants
| Limit | Detail | Escape hatch |
|---|---|---|
| Requires Python 3.14t | Free-threaded CPython is experimental (PEP 703) | Pin Python 3.14t environment |
Barrier + cancelled party |
Cancelled party before round completion parks remainder | Use abort() on exception |
select_channel arbitration |
Non-consuming readiness check under high contention | Built-in re-register loop |
| Waiter removal is O(n) | Cancelling N parked waiters scales as O(n²) | Keep party counts realistic |
AsyncContext.cancel() |
Cancels awaiters rather than active pool coroutines | Design tasks to observe future |
CancelScope shield |
Absorbs pre-injected cancellations | Use retry-loop pattern |
| Windows | Proactor: single acceptor listener model | Documented platform behavior |
For formal invariants and concurrency design principles, see docs/CONCURRENCY.md.
Live Demo
Want to test a live production setup without writing code?
multiloop-fastapi-demo is
a real FastAPI application served directly by multiloop run / MultiloopASGIWorker without uvicorn:
git clone https://github.com/hankaihong1/multiloop-fastapi-demo
cd multiloop-fastapi-demo
uv sync
uv run python app.py # then open http://127.0.0.1:8000
Community & License
- Complete API Reference: docs/API.md
- Choosing Primitives Guide: docs/CHOOSING.md
- CONTRIBUTING.md — Contribution Guide
- CHANGELOG.md — Changelog
- SECURITY.md — Security Policy
- CODE_OF_CONDUCT.md — Code of Conduct
- AGENTS.md — AI Development Guide
- License: MIT License. See LICENSE for details.
Metadata
Release files for multiloop 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| multiloop-0.1.1.tar.gz | 247.5 kB | Details |
Built distributions (wheels)
Total release size: 6.0 MB
Release files / multiloop-0.1.1.tar.gz
| Download URL | multiloop-0.1.1.tar.gz |
|---|---|
| Size | 247.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8bb13e6f5a5b26b0af0c7e53734e74b12b20d92ac427058b59d059d754afe221
|
|
BLAKE2b-256 checksum How to use checksums |
a4b00c5356adbdf23c9dd19b5143a05a5e432216378daeab012a170f3a2c4e4d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 20, 2026.
Transparency logRelease files / multiloop-0.1.1-cp314-cp314t-win_amd64.whl
| Download URL | multiloop-0.1.1-cp314-cp314t-win_amd64.whl |
|---|---|
| Size | 562.5 kB |
| Tags | CPython 3.14 CPython 3.14 free-threading Windows x86-64 |
|
SHA-256 checksum How to use checksums |
2dc2e64242d4c282003e3bde28b35bf76c4f8e41664a1f88392c2c8dbc8f8599
|
|
BLAKE2b-256 checksum How to use checksums |
385b42634f6f31744510c956eb91a5f6a35552d54e6d482980aab328f7724d61
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 20, 2026.
Transparency logRelease files / multiloop-0.1.1-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | multiloop-0.1.1-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 602.8 kB |
| Tags | CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
b7a229c0ce7b2ca633e71aa48b0bab0fad8f37a965b14875806c37b9bb98327b
|
|
BLAKE2b-256 checksum How to use checksums |
5a9f64655d3114859258dcc714b0592b45ef31d44fbbeccf53581e3e86ef6577
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 20, 2026.
Transparency logRelease files / multiloop-0.1.1-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | multiloop-0.1.1-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 583.9 kB |
| Tags | CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ ARM64 |
|
SHA-256 checksum How to use checksums |
e481a3f7f6d3c4e3880e62bb809a55abbf44cd4828b557fc001988055c5cb2b0
|
|
BLAKE2b-256 checksum How to use checksums |
bf5000cffd3a0679d1293e1cb8c4b30f7403d0a30e420d59167ad3c1ebe4c4bc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 20, 2026.
Transparency logRelease files / multiloop-0.1.1-cp314-cp314t-macosx_11_0_arm64.whl
| Download URL | multiloop-0.1.1-cp314-cp314t-macosx_11_0_arm64.whl |
|---|---|
| Size | 554.1 kB |
| Tags | CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
a010909e074fd246341938124fd66256ff9c362b305132ad8216e7294046f511
|
|
BLAKE2b-256 checksum How to use checksums |
9d55d4f29afb11b82268ca50654932dc9f5737c04b814e5d42f7e8c9538dcece
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 20, 2026.
Transparency logRelease files / multiloop-0.1.1-cp314-cp314t-macosx_10_12_x86_64.whl
| Download URL | multiloop-0.1.1-cp314-cp314t-macosx_10_12_x86_64.whl |
|---|---|
| Size | 581.2 kB |
| Tags | CPython 3.14 CPython 3.14 free-threading macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
e7e1c442b220b4ca8ad02e7a1d59b0079d3f54da658b8a1237cc8fab9c19e38a
|
|
BLAKE2b-256 checksum How to use checksums |
f61ba5b8be02065c08c4eabe3bdb4e543df38b6e16676d25767bf44d48789380
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 20, 2026.
Transparency logRelease files / multiloop-0.1.1-cp314-cp314-win_amd64.whl
| Download URL | multiloop-0.1.1-cp314-cp314-win_amd64.whl |
|---|---|
| Size | 561.7 kB |
| Tags | CPython 3.14 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
75394251bb019fd89010c1589779227668aa4bee6fd0acc06338964a9d903de0
|
|
BLAKE2b-256 checksum How to use checksums |
3de7ce52daaea92deb88271c560f6569deac1f53cfa792b899585c6e083f8f66
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 20, 2026.
Transparency logRelease files / multiloop-0.1.1-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | multiloop-0.1.1-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 602.8 kB |
| Tags | CPython 3.14 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
985bc4c05f6b8891b55f5bf00ae2f8e2a8987ba75a6a397af16470c36d23ecc7
|
|
BLAKE2b-256 checksum How to use checksums |
01aa9935c14bf22d8a8bcbc1d2fd6f9e37957674c2c0910f1177870c3a32a8ef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 20, 2026.
Transparency logRelease files / multiloop-0.1.1-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | multiloop-0.1.1-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 585.3 kB |
| Tags | CPython 3.14 Linux glibc 2.17+ ARM64 |
|
SHA-256 checksum How to use checksums |
c32be2662e652d3dded83681e0eec3385bc492d05a6cd39332799177687fc845
|
|
BLAKE2b-256 checksum How to use checksums |
dc51da4010920caca3ca567e27f194fade9ca98f9e0328905a9034b0147dbeba
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 20, 2026.
Transparency logRelease files / multiloop-0.1.1-cp314-cp314-macosx_11_0_arm64.whl
| Download URL | multiloop-0.1.1-cp314-cp314-macosx_11_0_arm64.whl |
|---|---|
| Size | 556.4 kB |
| Tags | CPython 3.14 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
e6624b5821ad304dd7e79e664e4bf6717a6506241ee7ee0c4c175c81e6591151
|
|
BLAKE2b-256 checksum How to use checksums |
780fc5ff4095676a5579f811013dea7d778d2ed9c31ca4a62bb32d859e7b70e3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 20, 2026.
Transparency logRelease files / multiloop-0.1.1-cp314-cp314-macosx_10_12_x86_64.whl
| Download URL | multiloop-0.1.1-cp314-cp314-macosx_10_12_x86_64.whl |
|---|---|
| Size | 582.6 kB |
| Tags | CPython 3.14 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
59d3fa0d41abaf7b51d73bd506cb774767a2ddc7ea3d413d93e86445f606d7fd
|
|
BLAKE2b-256 checksum How to use checksums |
a72a8877326db096aa4e7f6156b04bdd2e1450129e6d300f548bbe086f735d08
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 20, 2026.
Transparency log