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

Uploaded CPython 3.14Windows x86-64

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

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

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

Uploaded CPython 3.14macOS 15.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

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

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

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

Uploaded CPython 3.13macOS 15.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

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

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

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

Uploaded CPython 3.12macOS 15.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

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

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

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

Uploaded CPython 3.11macOS 15.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.10macOS 15.0+ ARM64

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.1.post2-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 51cd7761f548cfa3a7fd87291338634750bc8de6723812325ea667d9bab00a9b
MD5 9d58b2e8608248ba4edac69cd42cb77e
BLAKE2b-256 a0b281af50dc81942c79fc9dfd5c0a8f7a155215557eace88d9b9b291a5aa646

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.1.post2-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e27e73e18c93458e346827b614e7e6b9e05365e48e75affdb8e70edd545cb6f5
MD5 2387dae59df5ae957f4bdf0d86ddad65
BLAKE2b-256 a33f80ebda0bc649c193d9a9124735c0772322e336ccf5b9f0683043ffe85a1e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.1.post2-cp314-cp314-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 636778485b2f1ce5fddaa07d93c9a72308639b4888abc46b393f5ff1b22a87e3
MD5 5fcf93207ef9529d5961f382b6133062
BLAKE2b-256 8a238da20b026b850bf839b3fdc78b7fd1372db39e2d784bf53a02db1085ffa8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.1.post2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 9617ebc0c0ea973de8697107abe2b35e6da9bb51e4f521828c212038a5c3e50d
MD5 244bcefed2ccf4b0356fa3c86d676ed1
BLAKE2b-256 9a4a19336b53f35ed8a353baa9c287d4b76de52cd4810c826aac841e66fa5371

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.1.post2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f277f002d8ec9a6083bf48c15e075a370700ec38a6bc52c779c0c69754fb85be
MD5 78a7f9745528f149d0c8653abd2b0df1
BLAKE2b-256 5da79673d2a4c4b942c3928813a519666361224e129c8024a15a47c6fe0b1743

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.1.post2-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 3b76dcd262b8ed241145809de710588f117e566f482b11faa847861b9075fe74
MD5 8af9a464939386788a8537fd0f2b1945
BLAKE2b-256 847ab63e4a40f5cfb8b8538ff5a94f958726150c69b134bc1567d43b806994c2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.1.post2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 66820c93ce752af5a37a729318093f3f1ee660619e8be225d5d9e5dfe53891d7
MD5 3089f53e232cca379605264c4bcd8646
BLAKE2b-256 90d0d0e1d486eaea4292e15ac0a03b2c57f6ed678a852c45a1f2308b7e20c699

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.1.post2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0c11e60abcd3a7de93e7feb09e22307580ff1a72d1591f584f8b5034f944d5fe
MD5 bde900244b87be5d13bd934febe926ce
BLAKE2b-256 e436303691ec46c1b5b9a4d64d2fd83ced690bcfc819e977d119d1ff3ae9f847

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.1.post2-cp312-cp312-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 6bad97279f2621a1ccecd741aaeb9bcf10fac0b486b0bc7859d5473f3a1ae10c
MD5 38bbb0cc932083d42ab574a7e1874e79
BLAKE2b-256 dadaf88e5a84f87aa0f9d410aa779293e98cf843a8bdbaf48f9a1aaecea3181f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.1.post2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 79f4a26b93c217424cdfed8cab07887f5e02bda1bcbd651d066bcaf403403a9f
MD5 e5824a8941b21f9aacaa7c2a13a44e4c
BLAKE2b-256 59464a95dc0728dcaf323a51a80074c64d8ae6fa0429de4001f096965919b558

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.1.post2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a7a776eb077316a413244bd732fb525b74b1cf54ceba26fdb07945ebbe915acb
MD5 981b9676f8a81fb2467d9c12e666bd2c
BLAKE2b-256 6c9b9d753a11a7f3d73c41bd3a4bb56418a7dcbcab3688c1cb27e000f840ec33

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.1.post2-cp311-cp311-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 14daace5a5ba22512733f9ca83499183eab5fcd51766390695a1b7fad6198fa8
MD5 02305d70b94250dc5eff9ddf43c5e538
BLAKE2b-256 95430e59eed1e4a865a8e9f5fecd8fc03c378f4a35d03c3756c195aebf8e3e58

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.1.post2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 3338664e56317814aaa43f3d1722880be8bc2a003a2a91c2183ac3ce0eaf448c
MD5 76bcb394f6308003993ee4c7b812a9e6
BLAKE2b-256 57d58e33d29115758b37862d38dbd1b00612668b2037b3a6509f6e20a10ba2fa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.1.post2-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 61875526f47a66d43e9811b2a11283fee1791e4337f0b3b591c2b5270696209b
MD5 a2a59ab3a3501792b5f71bfafa03205e
BLAKE2b-256 22ae37b50eeb7285f9860d2230725922846bb0697bc6b8384218d010c2613992

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.1.post2-cp310-cp310-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 71cd5b2373b0f2bcaf9b98469b67f76423325012ed84cebc5140c1f9099e0734
MD5 ed0c801e4a545e7496f511b0160794a0
BLAKE2b-256 5bf101e3332d7bee606dd8b0a1826f9c0c194cd366a4431211ffc779469bddca

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