Skip to main content

turbofile

Real async file I/O for Python. A Rust core drives the best completion mechanism each OS has — io_uring on Linux, POSIX AIO on macOS — behind an aiofiles-compatible asyncio API.

Existing Python async-file libraries dispatch every call to a thread pool. turbofile submits the I/O to the kernel and completes your await when the kernel says the data moved:

  • Zero-copy reads and writes. The kernel fills the bytes object your await f.read(n) returns; writes pin your buffer and hand the kernel its pointer. No intermediate copies on the hot paths.
  • Completion batching. A burst of completions costs one event-loop wakeup (one call_soon_threadsafe doorbell per burst, drained entirely in Rust).
  • Parallel large reads. Read-all on a large file is split into chunks filled concurrently into one buffer.
  • Whole-file ops. read_bytes/write_bytes do open+read/write+close as a single submission — one round trip per file.
import turbofile

async def main() -> None:
    async with turbofile.open("data.bin", "rb") as f:
        payload = await f.read()

    async with turbofile.open("log.txt", "a", encoding="utf-8") as f:
        await f.write("one line\n")

    data = await turbofile.read_bytes("data.bin")   # whole file, one op
    text = await turbofile.read_text("notes.md")

turbofile.open mirrors aiofiles.open: binary and text modes, buffering, encoding/errors/newline with full universal-newline semantics, seek/tell (text cookies follow CPython's _pyio scheme), readline, async iteration, readinto, truncate, fsync via sync. Migration is import turbofile as aiofiles for the open API.

Benchmarks

make bench compares against aiofiles on your machine. On an Apple-silicon Mac (macOS 26.4, POSIX AIO backend, page-cache-hot files):

workload vs aiofiles
4 KiB whole-file read (read_bytes) 2.5x
32 concurrent 4 KiB random reads 15x
200 small files read concurrently 3.6x
8 MiB whole-file read (open + read) 1.0x
8 MiB sequential write (1 MiB chunks) 1.0x

Large sequential transfers are memory-bandwidth-bound in the page cache, so every implementation converges there; turbofile wins where per-op overhead and concurrency dominate, which is what an asyncio application actually does.

Reads whose pages are already resident are served inline on the event-loop thread — no submission, no driver-thread hop, no completion wakeup — falling back to async submission when the data is not resident. On Linux the kernel decides, through preadv2(RWF_NOWAIT); on macOS mincore on a mapping of the file reports which pages the buffer cache holds, and a plain pread copies them. Page-cache-hot 4 KiB reads:

Linux, ext4 before after
open + read(n) 44.3 us 1.30 us 34x
read_bytes 73.1 us 5.28 us 14x
blocking pread (floor) 1.08 us
macOS, APFS before after
read(n) on an open file 38.0 us 1.12 us 34x
blocking pread (floor) 0.59 us

read_bytes keeps the async path on macOS. Darwin has no cached-only open, and an inline open there stalls on cold paths and endpoint-security scans (about 300 us for the first open of a file on a machine running Jamf Protect), so its open and close still cross the driver thread.

Benchmark on a real filesystem: tmpfs sets no FMODE_NOWAIT, which disables the fast path and makes io_uring punt every read to a kernel worker, so /tmp numbers are not comparable. make bench and make ladder take FS=<dir> and print which filesystem they measured. See perf/README.md for the analysis harness.

Backends

OS backend mechanism
Linux compio (fusion driver) io_uring, automatic polling fallback under seccomp/old kernels
macOS darwin-aio POSIX AIO (aio_read/aio_write/aio_fsync in XNU)
macOS compio (opt-in) kqueue polling driver with thread dispatch

TURBOFILE_BACKEND=compio selects the compio driver on macOS (benchmarking, or as an escape hatch). Windows (IOCP via compio) is planned.

Limitations

  • opener= and integer file descriptors are not supported.
  • read_bytes on very large files pays one buffer copy; prefer open(...).read() for multi-megabyte files.
  • Cancelling an await detaches the future; the kernel op still completes (and, for readinto, may still write into the buffer) — standard completion-model semantics.

Development

make develop   # build the extension into the venv (uv + maturin)
make test      # cargo test + pytest
make lint      # clippy -D warnings
make bench     # benchmark against aiofiles

License

MIT OR Apache-2.0

Metadata

Release files for turbofile 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for turbofile 0.1.1
File Size Uploaded
turbofile-0.1.1.tar.gz 46.5 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for turbofile 0.1.1
File Interpreter ABI Platform
turbofile-0.1.1-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.12 abi3 Linux glibc 2.17+ x86-64 Details
turbofile-0.1.1-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.12 abi3 Linux glibc 2.17+ ARM64 Details
turbofile-0.1.1-cp312-abi3-macosx_11_0_arm64.whl CPython 3.12 abi3 macOS 11.0+ ARM64 Details

Total release size: 1.5 MB

Release files / turbofile-0.1.1.tar.gz

Download URL turbofile-0.1.1.tar.gz
Size 46.5 kB
Tags Source
SHA-256 checksum
How to use checksums
60e31896d0eb637be7a4dcdb43ce81179eaa9829d67b2f8e285c6e6a3fcb71ce
BLAKE2b-256 checksum
How to use checksums
3344098eab11f74a0d098b2c160f65cabc17743cdbdc87b33709093fc930c4d7
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 Sep 1, 2026.

Transparency log

Release files / turbofile-0.1.1-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL turbofile-0.1.1-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 487.3 kB
Tags CPython 3.12 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
ea714e968057cced0d66ec2c05ff05705bd6f21bbbf78cbfa1e6a1690bbb9458
BLAKE2b-256 checksum
How to use checksums
864385f1d14aa4eb0f196604c3a3d59db27937db1eccc4c26c64a139b2e68b7b
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 Sep 1, 2026.

Transparency log

Release files / turbofile-0.1.1-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL turbofile-0.1.1-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 483.7 kB
Tags CPython 3.12 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
4ac826b993682ffa942101c6b4383a477851bc2a227c52eb69f210395f31c777
BLAKE2b-256 checksum
How to use checksums
5c3dcb59727b9d8aca4d4c6fe66f2123d3da01b045042b955fafb2d6bc4f2875
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 Sep 1, 2026.

Transparency log

Release files / turbofile-0.1.1-cp312-abi3-macosx_11_0_arm64.whl

Download URL turbofile-0.1.1-cp312-abi3-macosx_11_0_arm64.whl
Size 435.8 kB
Tags CPython 3.12 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
0a6d72e7896da5f1a67ea034a2ea4c695b1b3abc35bf43c0899d7a88cc2674ee
BLAKE2b-256 checksum
How to use checksums
5b3c05d21e9026beeea19c47e9be7e72030840f401094bef3dd819209ba86ae9
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 Sep 1, 2026.

Transparency log

Release history Release notifications | RSS feed

0.1.5

4 release files

0.1.4

4 release files

0.1.3

4 release files

0.1.2

4 release files

This release

0.1.1 This release

4 release files

0.1.0

4 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page