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: p50 per operation, median of three runs. On an Apple-silicon Mac (macOS 26.4, POSIX AIO backend, page-cache-hot files, mains power):

workload vs aiofiles
4 KiB read on an open file 55x
32 concurrent 4 KiB random reads 16x
200 small files read concurrently 3.9x
4 KiB whole-file read (read_bytes) 2.1x
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 does.

Reads whose pages are already resident never leave the event-loop thread: no submission, no driver-thread hop, no completion wakeup. 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. Data that is not resident takes the async path. make ladder isolates that read: its file_read rung is BinaryFile's positional read of a hot 4 KiB, its pread rung the blocking syscall for the same bytes.

platform file_read pread
Linux, ext4 1.3 us 1.1 us
macOS, APFS 1.1 us 0.6 us

On Linux read_bytes takes the same inline route for the whole file, open included, through openat2(RESOLVE_CACHED): 5.3 us for a hot 4 KiB file. macOS 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 read_bytes keeps its open and close on 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.2

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.2
File Size Uploaded
turbofile-0.1.2.tar.gz 46.6 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for turbofile 0.1.2
File Interpreter ABI Platform
turbofile-0.1.2-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.2-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.12 abi3 Linux glibc 2.17+ ARM64 Details
turbofile-0.1.2-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.2.tar.gz

Download URL turbofile-0.1.2.tar.gz
Size 46.6 kB
Tags Source
SHA-256 checksum
How to use checksums
17f776124a1aac6fdb719d60d37e675c0fbf1f5e3b43054a427fbab3d466ef81
BLAKE2b-256 checksum
How to use checksums
bc8003e47cdb268e0b75c123059d5412a8452201e3dbecd160bf60533091e9a3
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 2, 2026.

Transparency log

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

Download URL turbofile-0.1.2-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
61cf0985420813966cff1a3c7120d520a92f15374b5b01a110adcaf119865f8b
BLAKE2b-256 checksum
How to use checksums
c9f40b65963789437dca84862e2cc50a6b1538b98228aea25f8f3d5c7b9d1026
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 2, 2026.

Transparency log

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

Download URL turbofile-0.1.2-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 483.8 kB
Tags CPython 3.12 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
a6ae1c8bf592a26949b93bf27a04e276938ce7c2407a9b3a558ce778bb04bc7b
BLAKE2b-256 checksum
How to use checksums
b5fe8c663e0c367d025e8f6611e013d0ddba4e59aa310e0172d7a3e33e9556c3
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 2, 2026.

Transparency log

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

Download URL turbofile-0.1.2-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
515c78a272083107abfb0dc05da9e0d679a56269b5697e8d3f14e0eb0d796100
BLAKE2b-256 checksum
How to use checksums
10fa1cf7094008e5fea0b8a89c9c37d2a74b84b7d03b6af429899742709eaf60
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 2, 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

This release

0.1.2 This release

4 release files

0.1.1

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