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.4-cp314-cp314-win_amd64.whl (89.0 kB view details)

Uploaded CPython 3.14Windows x86-64

ayafileio-1.0.4-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (109.2 kB view details)

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

ayafileio-1.0.4-cp314-cp314-macosx_15_0_arm64.whl (74.8 kB view details)

Uploaded CPython 3.14macOS 15.0+ ARM64

ayafileio-1.0.4-cp313-cp313-win_amd64.whl (86.7 kB view details)

Uploaded CPython 3.13Windows x86-64

ayafileio-1.0.4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (109.4 kB view details)

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

ayafileio-1.0.4-cp313-cp313-macosx_15_0_arm64.whl (74.9 kB view details)

Uploaded CPython 3.13macOS 15.0+ ARM64

ayafileio-1.0.4-cp312-cp312-win_amd64.whl (86.8 kB view details)

Uploaded CPython 3.12Windows x86-64

ayafileio-1.0.4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (109.4 kB view details)

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

ayafileio-1.0.4-cp312-cp312-macosx_15_0_arm64.whl (74.9 kB view details)

Uploaded CPython 3.12macOS 15.0+ ARM64

ayafileio-1.0.4-cp311-cp311-win_amd64.whl (87.6 kB view details)

Uploaded CPython 3.11Windows x86-64

ayafileio-1.0.4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (110.5 kB view details)

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

ayafileio-1.0.4-cp311-cp311-macosx_15_0_arm64.whl (75.9 kB view details)

Uploaded CPython 3.11macOS 15.0+ ARM64

ayafileio-1.0.4-cp310-cp310-win_amd64.whl (87.8 kB view details)

Uploaded CPython 3.10Windows x86-64

ayafileio-1.0.4-cp310-cp310-manylinux_2_28_x86_64.whl (109.9 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

ayafileio-1.0.4-cp310-cp310-macosx_15_0_arm64.whl (76.0 kB view details)

Uploaded CPython 3.10macOS 15.0+ ARM64

File details

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

File metadata

  • Download URL: ayafileio-1.0.4-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 89.0 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.4-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 27b291b45cfc9cc532d5109b3065dee11ea150c494d5c3e2461947320d13b598
MD5 855b42d7c394e5f9bf5a6cc61e8ecb8d
BLAKE2b-256 58e16f5fa961bbc5d180c826fbc7f582626ed8c7ef2eb9379fe61c38efc7508b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.4-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 13af3fed82c4e1efd59acfd56c2c4daf65109ad8b128d35780df819fe0d50a2c
MD5 8cfb640b4f8005ec011e6e6a1263cfd6
BLAKE2b-256 3166d10aad2cda992ae3f0bc8a6b77d8a48860f643d7c87dfde9c308ab735f52

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.4-cp314-cp314-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 46081cf93dac543cc2a3e3b21854f29183716bb341be4c4fe807a6e6a156b4e8
MD5 b020869740bfad2314a1ac3da34be109
BLAKE2b-256 93b0fbb3b221acca10804ef5b84eb37855567e3e219131c74fa8975666eafa43

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ayafileio-1.0.4-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 86.7 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.4-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 60fe5bf85fcd7a5b56004a5d36403f472be03626e95365c92d0c1a2b915bbe5d
MD5 5e6fe0df051fb79badffc7a57baad3c1
BLAKE2b-256 7e8d88946eaeb7f42f78b0b530861cff0bbd3b1da49cecce1441625bd84f2c28

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e2dd957f28edf00db2cd809ada051e6f114e39f405300e627ff76f6b82483c89
MD5 6c67c354c2586121f524c457fae9d790
BLAKE2b-256 69585ce230807b557084d82005070f486e348f19862b2482ac0ed9407218a998

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.4-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 1bcd2cb15d7a1442f995d0fa5d4e6830e2251d2b1abb0af3c184d0446fed7f55
MD5 4f7e094a38590a9094194c8d8616d7ae
BLAKE2b-256 cfc81366434f2b617a9014f4724b46a52922d7dd131dcfc10af12efd5b7ff841

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ayafileio-1.0.4-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 86.8 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.4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 5c3342aa0a20e5ac305bf1bcf12bcb091b84526a9f6d448045e2383c7348b362
MD5 75684472840d1ba636064edbc62fb313
BLAKE2b-256 78f38dd6d2a5bbc0b7b1af2053ed1817cee688195340ba4081489bca3910d37e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 bbaa6a736aff6425338f1d6fa8cf983a112b971f4675d6ca722a17837ab851de
MD5 08fc5660c6247e22e0f9e0991e60a1ef
BLAKE2b-256 5ed23acb7587a9afd7ef59739744796a0de2440c34680164a4a861c4f5a42fcf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.4-cp312-cp312-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 31bac241fe62461472802016e9ee16628a03a8a77cfda8a1c57528bc8ec3fbdd
MD5 0be75f339c1390c85f4d3a366d92618a
BLAKE2b-256 66993aabcf30ae3a20b4ea26a62144eb7fa71ab6ab8ac3d2ec36dcaf1d05e71f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ayafileio-1.0.4-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 87.6 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.4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 ac8fccff553334271d1f38c29ef22ea60fdf9452430ac7da0051ee4b276be962
MD5 bdb0de17367cfd76026c5638ebb6189c
BLAKE2b-256 48fe3b440e63fec94f958bf00e3700c083c5df3874057e279a936cc637545e43

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c2bb3932c4cd3727e2ec6b28210d017f339f29d3c50de5abbe29b6dabaac226d
MD5 5c5b83460984b4b87d6501bbe02c7a69
BLAKE2b-256 cfc6897bae0c57ec5618c8077c04e99cf18c694b1465cb958f35cbe533f77429

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.4-cp311-cp311-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 72d88eb118ab16d3b37e732fbe55094239cd0c6d13a8fe44fc0a280456f0dd6f
MD5 8bd4e0ad32123bdba41ad2e6f8073082
BLAKE2b-256 a08e2941bf969e03b764d580e526d961b0252cf87342b039979cc13d4bdf7a20

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ayafileio-1.0.4-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 87.8 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.4-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 40f10942edc12bd14d98a0976e991776559595d2c87f9aab76ed5b339ca30703
MD5 b65e444c3775597c5debd9a5f6193312
BLAKE2b-256 6376585ddbbe242bfd7d044ed84210b27e35f47e01c7998e93fcd98e53deaf95

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.4-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 12d18456040c06893effad9a1fd7fecf9762c85fd1cc41b4f23d4b79163385b9
MD5 6e828717e35830aadffb92f81dacf788
BLAKE2b-256 25466e252b859337d76e8593f01ce1d3d9dcc4277c8bfffa1e9b9f6bd91d3f7b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.4-cp310-cp310-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 03e9937198d77e1356dd090554422ab3a65ec67511fbcd34f492a7f9a513f263
MD5 162fea62ad356004ad00d9a69dcc675b
BLAKE2b-256 15dc6eb0302f677b2cab8c24662378ede2094141e6a2379e334f8e884fd2c26b

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