Skip to main content

Multi-core async runtime for Python, backed by Tokio. Drop-in asyncio replacement.

Project description

ferro_io

Multi-core async runtime for Python, backed by Tokio. Ships with ferro_io, a 100% drop-in replacement for asyncio (every public symbol resolves; 313 tests verify it, including real asyncpg / SQLAlchemy / FastAPI integration).

# Mode 1 — library-level
import ferro_io as asyncio
asyncio.run(main())
# Mode 2 — process-wide (third-party libs also benefit)
import ferro_io
ferro_io.install()
import aiofiles            # now uses ferro_io under the hood

Why

CPython's GIL serializes asyncio onto one core. ferro_io moves the scheduler into Tokio with a multi-thread runtime, so:

  • IO workloads stay at the theoretical sleep floor (no slower than stdlib).
  • CPU workloads that go through ferro_io.AsyncRuntime.map_blocking use tokio::task::spawn_blocking and bypass the GIL entirely.

Benchmarks (M-series Mac, 14 cores)

Best of 5 trials. Full matrix with uvloop in benchmarks/RESULTS.md.

Workload stdlib asyncio uvloop ferro_io vs stdlib
50 × 50ms IO sleep 51.62 ms 51.57 ms 51.44 ms ~1× (sleep floor)
200 × 20ms IO sleep 22.94 ms 22.00 ms 21.23 ms ~1× (sleep floor)
14 CPU chains × 5M LCG iters 6036 ms 5578 ms 6.37 ms 🔥 947×

IO workloads: ferro_io and uvloop are both pinned at the theoretical sleep floor — neither beats physics. CPU workloads: uvloop (libuv) stays GIL-bound like stdlib because it optimizes the event loop, not CPU parallelism. ferro_io's map_blocking routes through tokio::task::spawn_blocking, which releases the GIL and saturates all worker threads.

Coverage

  • Symbol-level: 119/119 asyncio public symbols resolve through ferro_io.
  • Real-world programs verified: TaskGroup, subprocess pipelines, TCP client/server with streams, to_thread, Queue producer/consumer, gather with return_exceptions, wait_for, timeout, Runner with contextvars.
  • Third-party library smoke test: aiofiles works under ferro_io.install().
  • Heavyweight libraries verified against real services under ferro_io.install(): asyncpg (Cython records, prepared statements, transactions, pools), SQLAlchemy async (greenlet sync→async bridge over asyncpg), FastAPI / Starlette (anyio, contextvars middleware, to_thread). See tests/test_heavyweights.py.
  • 307 unit tests + 6 heavyweight integration tests, 0 skipped, 0 failed.

Compatibility matrix

stdlib uvloop trio ferro_io
Drop-in asyncio replacement
asyncio symbol coverage 100% ~98% 0% 100% (119/119)
asyncio.TaskGroup (3.11+) n/a (nurseries)
Multi-core CPU workloads ❌ GIL ❌ GIL ❌ GIL ✅ (via spawn_blocking)
Windows support
httpx / aiohttp / websockets partial ✅ (tested)
asyncpg (Cython records) ✅ (tested — see test_heavyweights.py)
SQLAlchemy async (greenlets) ✅ (tested)
FastAPI / Starlette partial ✅ (tested)

All "tested" cells are backed by tests/test_heavyweights.py, which runs in the integration CI job against a real Postgres service container and also executes a matching stdlib-control run so a test-script bug can't masquerade as a ferro_io incompatibility.

Heavyweight compat tests run in the integration CI job against a real Postgres service container. To run them locally:

docker compose -f tests/docker-compose.yml up -d
FERRO_IO_INTEGRATION=1 pytest tests/test_heavyweights.py -v

Benchmark matrix vs uvloop

Generate the full matrix (runs each column in a subprocess so uvloop.install() can't contaminate the others):

pip install uvloop     # optional
python benchmarks/bench_matrix.py    # writes benchmarks/RESULTS.md

See benchmarks/RESULTS.md for the latest numbers. TL;DR: uvloop and ferro_io both sit at the IO sleep floor (within noise of each other). On workload C, ferro_io's spawn_blocking path bypasses the GIL while uvloop — like stdlib — remains serialized.

Caveat for process-wide mode

Code that does from asyncio import sleep at module top-level captures the stdlib reference at import time, before ferro_io.install() can run. To work around it, call ferro_io.install() as the very first statement in your entry point — before any third-party import.

Build

python -m venv .venv && source .venv/bin/activate
pip install maturin pytest pytest-asyncio
maturin develop --release
pytest tests/ -v
python benchmarks/bench.py

Built with PyO3 0.28 + pyo3-async-runtimes 0.28 + Tokio + maturin. ABI3 wheels cover Python 3.9+.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

ferro_io-0.2.0-cp39-abi3-win_amd64.whl (379.8 kB view details)

Uploaded CPython 3.9+Windows x86-64

ferro_io-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (457.8 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64

ferro_io-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (446.0 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

ferro_io-0.2.0-cp39-abi3-macosx_11_0_arm64.whl (405.8 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

ferro_io-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl (421.3 kB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

Details for the file ferro_io-0.2.0-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: ferro_io-0.2.0-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 379.8 kB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.13.1

File hashes

Hashes for ferro_io-0.2.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 71686fdc8efb95e36182b5b5f8edd19409e540f34f30fdbef738591c50b86191
MD5 b0880a5e0f2b6954ce3792f9f7cd95dc
BLAKE2b-256 d4e3d476d89c393995954c4bb946dabb870225a5b08b8f8d2ceed45899b30830

See more details on using hashes here.

File details

Details for the file ferro_io-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ferro_io-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 14d5e2e96f0e7d0c018f81d036a6e558fffca008196dbeca8197de4a51a3d21b
MD5 c5181803b636c40411550834707f4be7
BLAKE2b-256 039ed8c8a2e32cb64c6e0d5f4f2a7b76a1790346760cd1e1fd94160c03f3a1a1

See more details on using hashes here.

File details

Details for the file ferro_io-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for ferro_io-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c6a8b826c9ceb6622e9ec5cf55bde578a4c28fa58134974949490d8f59d539b6
MD5 a4b387df61a6600701f1c602572cd89b
BLAKE2b-256 5004863a4b7eddbae6700edb3e3831bdaa701414e9d15f2fb599e344d9f2c37c

See more details on using hashes here.

File details

Details for the file ferro_io-0.2.0-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ferro_io-0.2.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 241edc97aed9ff75c37f4956cc0b977fc8e9bade28194f454309f60276562cc5
MD5 ec83b2b51f8a65598e6fba384be165c2
BLAKE2b-256 4153c1047bce9063ee12c9560c28aadefbc08e4dc70e623e296f1d91a2836b6d

See more details on using hashes here.

File details

Details for the file ferro_io-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for ferro_io-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 2e9fb91743b186372be7ecf251e59bcde2a2f8bed6d18f490ade564ea54bc47b
MD5 a47a692357074ad880c56ebf10c8c9ad
BLAKE2b-256 119b3bc4c23f8809ac45f042d02e0b1a73b699264ebc1948c581b6f8759d7696

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page