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.

🏆 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.1-cp314-cp314-win_amd64.whl (84.6 kB view details)

Uploaded CPython 3.14Windows x86-64

ayafileio-1.0.1-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (105.5 kB view details)

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

ayafileio-1.0.1-cp314-cp314-macosx_15_0_arm64.whl (71.0 kB view details)

Uploaded CPython 3.14macOS 15.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

ayafileio-1.0.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (105.6 kB view details)

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

ayafileio-1.0.1-cp313-cp313-macosx_15_0_arm64.whl (71.1 kB view details)

Uploaded CPython 3.13macOS 15.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

ayafileio-1.0.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (105.7 kB view details)

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

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

Uploaded CPython 3.12macOS 15.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

ayafileio-1.0.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (106.8 kB view details)

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

ayafileio-1.0.1-cp311-cp311-macosx_15_0_arm64.whl (72.1 kB view details)

Uploaded CPython 3.11macOS 15.0+ ARM64

ayafileio-1.0.1-cp310-cp310-win_amd64.whl (83.4 kB view details)

Uploaded CPython 3.10Windows x86-64

ayafileio-1.0.1-cp310-cp310-manylinux_2_28_x86_64.whl (106.2 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

ayafileio-1.0.1-cp310-cp310-macosx_15_0_arm64.whl (72.2 kB view details)

Uploaded CPython 3.10macOS 15.0+ ARM64

File details

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

File metadata

  • Download URL: ayafileio-1.0.1-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.1-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 75be3e14bb807445977eccaa3c8ceb1a9647967682d6a0885c7fcebd60b11c1c
MD5 df392ceb4d2a1caf9b9d28da98b1edf0
BLAKE2b-256 0c9f8b54f0107a0892d1ac8db38947b2b5301f858ff23e510dedc7b75a96d88b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.1-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d236fbe21675f4ceef808b549f543916f568f81223907234cb656b57bfb70811
MD5 0ad1703090d6a479d0f135bebc12ecbc
BLAKE2b-256 e4330a09534c55e4d0cfc58937359465425f0421203552bc44519783911233f5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.1-cp314-cp314-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 74e715dfc2dbe358166330da474b05b58879aa7a6ec30e496fc4bde21d99cf81
MD5 edabb9f51b0c2036278adb5b4c841dd3
BLAKE2b-256 952baea7d6fbd3892b3f4d1d95d401ce3b913fadeb50129b9873c042b7e05e89

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ayafileio-1.0.1-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.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 5a2776b15f8c550585fc6ae3c168a8637bec16d93d731a0c614086ad3e7b7075
MD5 d669943cadc09b524ed43072f4072bf7
BLAKE2b-256 d85cc9465b64fa1ac4f3ee3a6263b3360002ae13ae33c88487bab8d304b4b7d0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ea4a0f8384c0869bed18a0a323fa08568a0b930a38b0a70b4c25e37b953eae24
MD5 00d1969dfcf93eb753c8e193153c5510
BLAKE2b-256 8d6afad70302431dc4cc58c56a50a389acf9b6dbbb0d6dab27db8e7c016cb9ae

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.1-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 41bb65e575eb89e6eb3d414199f86bac17fabdf004cb40a0bb1e87a70e3479c9
MD5 694cf05c32b96a13417f02ec5ddad284
BLAKE2b-256 d6a0f4afb069f4ef601d581519b78d6900e82d55dcbb5d78b438a97fc9b84a67

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ayafileio-1.0.1-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.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 28609d7b118f6c1e75ae2a60f650fdf4e0dc5eb0965cb34c1cfee1339367a8b7
MD5 587bd39cda1cc7b1abe1f2a13821cc6b
BLAKE2b-256 df1b2a20f00305b45103b5e31866775e794c58530a5a4ede6dfa5a51fbc94104

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 94eb78159ab530cc4fb8f3c634d94f04a940d65d1b22a866522650ef8f4d0f5e
MD5 a0945590162102f30ca09629ce224429
BLAKE2b-256 2edf861a022f189808b621dd6744af0b87308da662c32e6a7a63c28711c2d206

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.1-cp312-cp312-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 d993daeb233b2fdfb2b228bc5b385f014734cc2ce7baa4e031c3ec42089f58ec
MD5 ef6e5acb2a43e3075b8d143777c75381
BLAKE2b-256 3367fd8571af3ea179e79d7bb6d0a98870a22b51382b6f6f71b5b095764a45f7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ayafileio-1.0.1-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.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 47d1d906a12b2e36868f65a45fb23dcdb6caa70118de3e0051c9f8651d498b9c
MD5 5162ac389e43a649bc580d7d4f273219
BLAKE2b-256 0860b6f1db95afe902e7889ffdbf6352c7cf2c622706d77b389b2387cc86ba52

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 cabec6710842815e9bd074d567de93587ddce9832d59d224a6a539d552f55bda
MD5 6c1c6af91e337d9083e26e04fb3f3ff9
BLAKE2b-256 321ab43ba4ca5100078985c33b234b734c4a47dea4ce35ea5142e3071c138a1b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.1-cp311-cp311-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 e710834a8f369b0b59910215dfd3fe4b9cf5e9330e04c022b629678488b9662e
MD5 f96bedd3e203fd09ece16d24665d4da0
BLAKE2b-256 1ef4baec54ba8f2942893aa523fed276ab9bfd6f4d09647ffdc5e57200e2a8d8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ayafileio-1.0.1-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 83.4 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.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 83dd0527dd0be5826edd3e3765f405b171526125998f935a9474dc86d4015280
MD5 fbaa1f2146cf967296593d71548c9f6e
BLAKE2b-256 c7beb4be6dbde1953dde929edf612a24c8e0f8f0cb3d99d86d3ade95f126cd71

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.1-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 49d82ffe47d49b5b38479b2e8588299cff9e85f96bc1d2310722a74d3a58490e
MD5 cb4eeceb23dbb6318ee92916d9c24eb5
BLAKE2b-256 8f55ae42a26052428f8405a5833da5422ec9c7cf702d0ba2bc0dbfa5afaae9a1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.1-cp310-cp310-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 9fd875a90fc19e9b59e065ef16998644fb8febfb7309700d501fea8326fb990b
MD5 3673ef9368b61d3017b52fc73b45351c
BLAKE2b-256 77539a9314ec52efe1782719d9f3a5345d966e0d15c9c8f1da7e0bb6d0de78f3

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