Skip to main content

Cross-platform async file API for Python. Blazing fast like Shameimaru Aya.

Project description


ayafileio

License Python Version Platform Version

当前是英文 | chinese version

"The fastest file I/O in Gensokyo, swift as the Wind God Maiden."
— Aya Shameimaru, always flying at full speed

Cross-platform asynchronous file I/O library using native async I/O where available.
Windows leverages IOCP (I/O Completion Ports), Linux uses io_uring (kernel 5.1+), and macOS uses Dispatch I/O (GCD) for truly non-blocking file operations.

changes

see -> CHANGES

🏆 The Only True Async on All Three Major Platforms

Platform Backend True Async Description
Windows IOCP NT kernel native I/O Completion Ports
Linux io_uring Next-gen async I/O (kernel 5.1+)
macOS Dispatch I/O GCD kernel-level async I/O

ayafileio is the only Python library providing true async file I/O on Windows, Linux, and macOS.

📸 Key Features

Feature Description
🍃 Zero thread overhead No background threads on true async platforms
📰 Kernel-level completion IOCP / io_uring / Dispatch I/O direct to kernel
High concurrency Handles thousands of concurrent file operations
🎴 Familiar API aiofiles-compatible, supports async/await
📖 Text & binary support Automatic encoding/decoding in text modes
🔧 Unified configuration Runtime tunable parameters for all backends
🌍 Cross-platform Windows, Linux, and macOS
🐍 Latest Python Supports 3.10, 3.11, 3.12, 3.13, 3.14

🛠️ Installation

pip install ayafileio

System requirements:

  • Python 3.10+
  • Windows 7+ / Linux (kernel 5.1+ for io_uring) / macOS 10.10+
  • No external dependencies, precompiled wheels available

🚀 Quick Start

import asyncio
import ayafileio

async def main():
    # Write to a file — fast as the wind
    async with ayafileio.open("example.txt", "w") as f:
        await f.write("Hello, async world!\n")

    # Read with automatic decoding
    async with ayafileio.open("example.txt", "r", encoding="utf-8") as f:
        content = await f.read()
        print(content)

    # Binary operations
    async with ayafileio.open("data.bin", "rb") as f:
        data = await f.read(1024)
        await f.seek(0, 0)

asyncio.run(main())

⚡ Performance Best Practice

ayafileio's file open/close overhead is already in the microsecond range, but for maximum performance, avoid reopening the same file in a loop.

# ❌ DO NOT DO THIS: repeated open/close in a loop
for i in range(10000):
    async with ayafileio.open("data.bin", "rb") as f:
        data = await f.read()

# ✅ DO THIS: open once, operate many times
async with ayafileio.open("data.bin", "rb") as f:
    for i in range(10000):
        await f.seek(0)
        data = await f.read()

The latter is ~6x faster — it eliminates 9999 unnecessary coroutine scheduling round-trips.

🔍 Backend Information

Check which backend is currently in use:

import ayafileio

info = ayafileio.get_backend_info()
print(info)
# Windows: {'platform': 'windows', 'backend': 'iocp', 'is_truly_async': True}
# Linux:   {'platform': 'linux', 'backend': 'io_uring', 'is_truly_async': True}
# macOS:   {'platform': 'macos', 'backend': 'dispatch_io', 'is_truly_async': True}

⚙️ Unified Configuration

ayafileio provides a unified configuration system that allows runtime tuning:

import ayafileio

# View current configuration
config = ayafileio.get_config()
print(config)

# Update configuration
ayafileio.configure({
    "io_worker_count": 8,
    "buffer_size": 131072,      # 128KB buffer
    "close_timeout_ms": 2000,
})

# Reset to defaults
ayafileio.reset_config()

Configuration Options

Option Default Description
handle_pool_max_per_key 64 Max cached handles per file (Windows)
handle_pool_max_total 2048 Max total cached handles (Windows)
io_worker_count 0 IO worker threads, 0=auto
buffer_pool_max 512 Max cached buffers
buffer_size 65536 Buffer size in bytes
close_timeout_ms 4000 Close timeout for pending I/O (ms)
io_uring_queue_depth 256 io_uring queue depth (Linux)
io_uring_sqpoll False Enable SQPOLL mode (Linux)
enable_debug_log False Enable debug logging

📚 API Reference

AsyncFile class

class AsyncFile:
    def __init__(self, path: str | Path, mode: str = "rb", encoding: str | None = None): ...
    async def read(self, size: int = -1) -> str | bytes: ...
    async def write(self, data: str | bytes) -> int: ...
    async def seek(self, offset: int, whence: int = 0) -> int: ...
    async def flush(self) -> None: ...
    async def close(self) -> None: ...
    async def readline(self) -> str | bytes: ...
    def __aiter__(self) -> AsyncFile: ...
    async def __anext__(self) -> str | bytes: ...

Supported Modes

Mode Description
"r", "rb" Read (text/binary)
"w", "wb" Write (text/binary)
"a", "ab" Append (text/binary)
"x", "xb" Exclusive create (text/binary)
+ added Read/write combinations

Configuration Functions

def configure(options: dict) -> None: ...      # Unified configuration
def get_config() -> dict: ...                   # Get current configuration
def reset_config() -> None: ...                 # Reset to defaults
def get_backend_info() -> dict: ...             # Get backend information

🧪 Performance Comparison

Simulating Crawlee's Dataset append pattern (5,000 records, 50 concurrent):

Platform ayafileio aiofiles Speedup
Windows (NVMe SSD) 41,336 items/s 9,658 items/s 4.28x
Linux (NVMe SSD) 17,688 items/s 11,455 items/s 1.54x
macOS (NVMe SSD) 29,837 items/s 25,522 items/s 1.17x
Windows (6yr old HDD) 20,251 items/s 13,011 items/s 1.56x

Key findings:

  • On Windows enterprise SSD, ayafileio achieves 42x lower P99 latency (0.044ms vs 1.854ms)
  • aiofiles shows 96.7% jitter under load; ayafileio only 16.2%
  • Even on degraded hardware, ayafileio maintains predictable performance

Test environment: Windows 10/11, Ubuntu 22.04, macOS 14; GitHub Actions enterprise NVMe SSD

🤝 Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Add tests
  4. Ensure benchmarks pass
  5. Open a pull request

📄 License

MIT License — see LICENSE for details.


"Slow is a crime, right?"
— Aya Shameimaru, editor-in-chief of Bunbunmaru News


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.

ayafileio-1.0.3-cp314-cp314-win_amd64.whl (84.6 kB view details)

Uploaded CPython 3.14Windows x86-64

ayafileio-1.0.3-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (104.8 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

ayafileio-1.0.3-cp314-cp314-macosx_15_0_arm64.whl (71.1 kB view details)

Uploaded CPython 3.14macOS 15.0+ ARM64

ayafileio-1.0.3-cp313-cp313-win_amd64.whl (82.4 kB view details)

Uploaded CPython 3.13Windows x86-64

ayafileio-1.0.3-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (105.0 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

ayafileio-1.0.3-cp313-cp313-macosx_15_0_arm64.whl (71.2 kB view details)

Uploaded CPython 3.13macOS 15.0+ ARM64

ayafileio-1.0.3-cp312-cp312-win_amd64.whl (82.4 kB view details)

Uploaded CPython 3.12Windows x86-64

ayafileio-1.0.3-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (105.0 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

ayafileio-1.0.3-cp312-cp312-macosx_15_0_arm64.whl (71.2 kB view details)

Uploaded CPython 3.12macOS 15.0+ ARM64

ayafileio-1.0.3-cp311-cp311-win_amd64.whl (83.3 kB view details)

Uploaded CPython 3.11Windows x86-64

ayafileio-1.0.3-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (106.0 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

ayafileio-1.0.3-cp311-cp311-macosx_15_0_arm64.whl (72.2 kB view details)

Uploaded CPython 3.11macOS 15.0+ ARM64

ayafileio-1.0.3-cp310-cp310-win_amd64.whl (83.5 kB view details)

Uploaded CPython 3.10Windows x86-64

ayafileio-1.0.3-cp310-cp310-manylinux_2_28_x86_64.whl (105.5 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

ayafileio-1.0.3-cp310-cp310-macosx_15_0_arm64.whl (72.3 kB view details)

Uploaded CPython 3.10macOS 15.0+ ARM64

File details

Details for the file ayafileio-1.0.3-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: ayafileio-1.0.3-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 84.6 kB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for ayafileio-1.0.3-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 1978927c3035c563d4b56b3649051e6a96f92cfff86db41800281d17f9a8c52d
MD5 3db4da53b44a1aec59f323d8a221857c
BLAKE2b-256 57d444e55d4eba6341bb71b62212dc13ff60481ca61526c35d0f4179b4222246

See more details on using hashes here.

File details

Details for the file ayafileio-1.0.3-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for ayafileio-1.0.3-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f5bb6c6b54a5990f8d841720b379fb2674f13c17a825f7b1202b5f21c25f1fbd
MD5 e3ff6611377013983b1c3b2921c5f7f9
BLAKE2b-256 7af2de967c071bf2c27f671f3dcef15a28bf24b3f8983c48a8890bd4bd641405

See more details on using hashes here.

File details

Details for the file ayafileio-1.0.3-cp314-cp314-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for ayafileio-1.0.3-cp314-cp314-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 61349e1edfacb03395e6bf52672506b957ef0f18406b133c48db9da61c30db24
MD5 78eb134bb53ec464d65ebb39927f88ae
BLAKE2b-256 fe68290415be951b21d4b931296be1b6750e0b4a009aeb080619663a601a5da1

See more details on using hashes here.

File details

Details for the file ayafileio-1.0.3-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: ayafileio-1.0.3-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 82.4 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for ayafileio-1.0.3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 dd7116ad59ca973a5d9f280c7f22f9ea5b5e09bf49c0ba9a20db9063b9afb435
MD5 8f3135997fd1012351ef6721ac2c30da
BLAKE2b-256 f4e5f274804f9467926e486c62bace1845f79b1aa01606da7fa20aab419489ee

See more details on using hashes here.

File details

Details for the file ayafileio-1.0.3-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for ayafileio-1.0.3-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0876952271afbdc54d4d08e49005a424a3e48c6c2060a61c67c9536cc9088e29
MD5 9c4a35a2cb8c021fa9f280dc6879d613
BLAKE2b-256 dd46cee03d57297099306b2c3fb5ccd6cf3dcfda76da96fcdf3763480b7c3213

See more details on using hashes here.

File details

Details for the file ayafileio-1.0.3-cp313-cp313-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for ayafileio-1.0.3-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 80a4f7a3e36dfcfe72922bc49f7249ef8def1d618d0d48d2262616a4df84bf3b
MD5 08ade482839509e0ee856e60e392a98d
BLAKE2b-256 1599b5b4f7ea94c8a15057ad63c54c08cf86c13b82a5ab2d3f48e1eb1b59745e

See more details on using hashes here.

File details

Details for the file ayafileio-1.0.3-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: ayafileio-1.0.3-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 82.4 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for ayafileio-1.0.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 95c0ab75eeb7020d7b9d3b611a3f8dc3b3d8ffdba9aae39edfa781b6fdaf1264
MD5 067efe4dddc36284dbe04f6bbe24cf28
BLAKE2b-256 325ad13c7c3022804ab7ad76ddb31bbb4d85c0d6e84d6c99e9c535414916bc30

See more details on using hashes here.

File details

Details for the file ayafileio-1.0.3-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for ayafileio-1.0.3-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 25f2f3c7bd65c0d95f4c566881bbac554f790a81b198d1ceb235b37a722f9c39
MD5 2d825bb837b0a4d39ed14cf4e60ba462
BLAKE2b-256 e193da21939f3a6a22cf713459a1edd02a19e465ee93a526e889824c47b44ca5

See more details on using hashes here.

File details

Details for the file ayafileio-1.0.3-cp312-cp312-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for ayafileio-1.0.3-cp312-cp312-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 65eb8945f6bc0fe7bad0c9e88b0ba4c200768d06295a0a960251dc29a691a725
MD5 d7ad41321ecab73816cd1d868159632a
BLAKE2b-256 607550f0518d272e78aa6a5db49d56970ae5b804c9c52fb5a940cbaa8bb62eae

See more details on using hashes here.

File details

Details for the file ayafileio-1.0.3-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: ayafileio-1.0.3-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 83.3 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for ayafileio-1.0.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 b8f26246402bf1ec3784171334af55d5bdf7b6eb5051547abd8722094c588af8
MD5 7892b1e06859ec3782bd3dce7dc25619
BLAKE2b-256 586bf01ec902077842e39970f3b0627fac521081ad6a0b65c80a795abc000cce

See more details on using hashes here.

File details

Details for the file ayafileio-1.0.3-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for ayafileio-1.0.3-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 79617fbf73710411cf48b6e305e56a2ddeaab70781179e228f9a18417137d30a
MD5 3564f8c681f86d58fd94cc6190a0b6c3
BLAKE2b-256 4a2382541cc292fee4a0421bbbe8d9448385b3b2f5f53f5d0ac200d6008b114b

See more details on using hashes here.

File details

Details for the file ayafileio-1.0.3-cp311-cp311-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for ayafileio-1.0.3-cp311-cp311-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 5120bf0c7ca7f359357d0502524abd42d4f6787097fb2eac5f3254026f4aede2
MD5 d3c8b9a908ce9608984ebf6a52d08efa
BLAKE2b-256 f4c81cacae41000b45a0015440cabaad6c6a34e41b89ad87772236c2469c278a

See more details on using hashes here.

File details

Details for the file ayafileio-1.0.3-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: ayafileio-1.0.3-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 83.5 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for ayafileio-1.0.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 6b75b15b31fe3a3769237099fc7c532576908810883d03c665f76cf0b691b7b1
MD5 99e919d42df0210e9edf97be96f32d25
BLAKE2b-256 34764f03d34228fe4570c89509c80b92fc09a5861e8a6b2f1adf3dd1eeafae7c

See more details on using hashes here.

File details

Details for the file ayafileio-1.0.3-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for ayafileio-1.0.3-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 284f33aab95a70df466b074705d867c5fa65051c5fe396c3b623e49f1ad4aa79
MD5 bc407da536a8f71393ff496a8c0f0439
BLAKE2b-256 caa3b5a8fa4fae875512d7a1cdb086bb7beab1407134ff9c7d002bfc2a27da00

See more details on using hashes here.

File details

Details for the file ayafileio-1.0.3-cp310-cp310-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for ayafileio-1.0.3-cp310-cp310-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 fea0997f152cfd93e111ad7f877971207726be44e836f3b289e08d682053c1ac
MD5 80dac7132f1d2fe1dd5c98fcb1e38bce
BLAKE2b-256 75ad2f2e7d8d64be460952b2ac00b53c72f4e5c4da20d5ebf4462113e8208f27

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