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

Uploaded CPython 3.14Windows x86-64

ayafileio-1.0.2-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (104.6 kB view details)

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

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

Uploaded CPython 3.14macOS 15.0+ ARM64

ayafileio-1.0.2-cp313-cp313-win_amd64.whl (82.2 kB view details)

Uploaded CPython 3.13Windows x86-64

ayafileio-1.0.2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (104.7 kB view details)

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

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

Uploaded CPython 3.13macOS 15.0+ ARM64

ayafileio-1.0.2-cp312-cp312-win_amd64.whl (82.2 kB view details)

Uploaded CPython 3.12Windows x86-64

ayafileio-1.0.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (104.8 kB view details)

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

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

Uploaded CPython 3.12macOS 15.0+ ARM64

ayafileio-1.0.2-cp311-cp311-win_amd64.whl (83.1 kB view details)

Uploaded CPython 3.11Windows x86-64

ayafileio-1.0.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (105.8 kB view details)

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

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

Uploaded CPython 3.11macOS 15.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

ayafileio-1.0.2-cp310-cp310-manylinux_2_28_x86_64.whl (105.3 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

ayafileio-1.0.2-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.2-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: ayafileio-1.0.2-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 84.4 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.2-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 8b1bfb67b6dffd95d9709817964a18b26e69267c1ba038459ff56409f8cb490f
MD5 1ef49c367e9468c912d39945d961f8d5
BLAKE2b-256 780ebd41cdc5fa190c2313544a09825f4c5ede2fe4c984f746b038b8491fefd1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.2-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9224061280aa98e38b468cc61b1edd7f6d01eecb3e7a0eb36a6090d5e98da124
MD5 ac2226105680a9d037c8d04c28d85ab4
BLAKE2b-256 a421a7a22cbb9fe17c82d7dbd2421b1d9f6f6052e436de2fa32a00f24c3cdb89

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.2-cp314-cp314-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 b23634b14e01e086681fea5befcee2315f8de90ad2fb52a27be590a6e0b28e9a
MD5 75fc17f144f9a18251d87ac4c6928f1c
BLAKE2b-256 8beaf4a2b8137fcb9188ad6f885ceb63c047db3a7eaf6a92a9659eb59c1aefc6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ayafileio-1.0.2-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 82.2 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.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 aeab207f0353768ade88a6a4fc77d6754019e2b551cd33e31d50dc191018ea41
MD5 969944cbeb6224bcb69d74e1d4dfc795
BLAKE2b-256 0a46c373a7558f5186493fa6e29dfdeffcf3ef03c5abbceafd8d0b6b78a01a4d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 870cf592c959d16d3b3a79f54d1bba0d6240eb4018541baaf81828d6fbe10ac6
MD5 582bec8df591812088a114c8ae5a959b
BLAKE2b-256 a26cd2ddf5714e2ab2acf72f509c60e4d692cd34eead3185850efc7d163fc22a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.2-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 4e7be7087741b54ea2dddb8b637f01294e0ed6742c42e1b02e646c5195180040
MD5 ba22f5c1a1b363e90bd2fa1a29a5aa19
BLAKE2b-256 80eff55b6fdfcd651bdab6f2cf8bbcd6f019567f8cead17391c7a467d87baa55

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ayafileio-1.0.2-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 82.2 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.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 ac552b382e0cb3140b57b62847ae6c66d90dfbc9136472b23341e42497ea44ad
MD5 64ad8fef8ba5b1fe72bfa395a8f21cf4
BLAKE2b-256 f5fd57cc978af288a3d93d9fae03e3193f51b112c05103c0b61a9b072c0fb455

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0b6f33686632fd4afcc4b9fed936d04f6b34d51c4caf3baa6cdface42b89ad0c
MD5 15e37c50153c092afecf43b6dbe1a879
BLAKE2b-256 6a4240154482c743726d60e0441288c6dfb739e1fbc618213927f934b26ce965

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.2-cp312-cp312-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 1da3a784a6cf42c9699848ac9995dc66481902055badaca6c833379caeaba6ad
MD5 ea03c19cbddfeb453473cb72b2210522
BLAKE2b-256 b4c7fce9c40f28cc58e075b0334a94fc5f341518659a0bb9678788f74e7adc19

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ayafileio-1.0.2-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 83.1 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.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 4b755c3bd2debf8cba69b8a4e99826e761c2ef2580fd1924d7b4809888a6b2bd
MD5 6d873e37f0064d06dc5373604def067b
BLAKE2b-256 5dd12781d570f910e245605b3a4b40f710769b3a00e3f0ea87dfc22162c714a8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7789148c531b6a7c876570dfdbf63ceffafc44e0ef5ec2ceed8ecca2861aa497
MD5 dfb64b46261688850c84d65b1f5230a6
BLAKE2b-256 6ce8de11f0e86a93fab7d629573886d4c36b462c7d69b9c035a952e91ac95389

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.2-cp311-cp311-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 ac5268b47ae99e4abff02aab32a2f873889ca8b73c1d2ae8c86306e5a3679221
MD5 3cf5ccf57758dde8441ab423cecc1d1f
BLAKE2b-256 abd89fde3195cbd0202111ef18ffb1275c90f1cbab64547f55546884d15f2746

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ayafileio-1.0.2-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 83.3 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.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 b49e88d9672c76f8b5e9cb5eb11d4b14d89149cb0e47bd550ac53cf43fc7078a
MD5 c921a2c7625d33481cf15e7b0e7b4017
BLAKE2b-256 5a26fbfcbf69a350eed7fe4e103a536b91cbc2a001428562ed8148c2adf3ee5f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.2-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 bf0f43115b8c9350b8fe2686b8a7cc6b023801d09a8a76317b982c5ec80ba739
MD5 bfdd580888dfac73b7b1627359aaf7f9
BLAKE2b-256 95ef9bccf3abd89b7b3c9222ee34fddfe6268ee0230b1ca2d247271e7c60eb7d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.2-cp310-cp310-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 7ee439b043d901a360197394389dbc6df97de1997b069f6bc5513b750979f224
MD5 6794375df6a9bd4c51b71565f3731c1a
BLAKE2b-256 018d890e9f166d59ccf7d2c52d81913a1c12858b1b4c22ca839c69f90c44fe31

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