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

Uploaded CPython 3.14Windows x86-64

ayafileio-1.1.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (112.2 kB view details)

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

ayafileio-1.1.0-cp314-cp314-macosx_15_0_arm64.whl (76.7 kB view details)

Uploaded CPython 3.14macOS 15.0+ ARM64

ayafileio-1.1.0-cp313-cp313-win_amd64.whl (88.9 kB view details)

Uploaded CPython 3.13Windows x86-64

ayafileio-1.1.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (112.4 kB view details)

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

ayafileio-1.1.0-cp313-cp313-macosx_15_0_arm64.whl (76.7 kB view details)

Uploaded CPython 3.13macOS 15.0+ ARM64

ayafileio-1.1.0-cp312-cp312-win_amd64.whl (89.0 kB view details)

Uploaded CPython 3.12Windows x86-64

ayafileio-1.1.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (112.5 kB view details)

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

ayafileio-1.1.0-cp312-cp312-macosx_15_0_arm64.whl (76.8 kB view details)

Uploaded CPython 3.12macOS 15.0+ ARM64

ayafileio-1.1.0-cp311-cp311-win_amd64.whl (89.8 kB view details)

Uploaded CPython 3.11Windows x86-64

ayafileio-1.1.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (113.6 kB view details)

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

ayafileio-1.1.0-cp311-cp311-macosx_15_0_arm64.whl (77.7 kB view details)

Uploaded CPython 3.11macOS 15.0+ ARM64

ayafileio-1.1.0-cp310-cp310-win_amd64.whl (90.0 kB view details)

Uploaded CPython 3.10Windows x86-64

ayafileio-1.1.0-cp310-cp310-manylinux_2_28_x86_64.whl (113.1 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

ayafileio-1.1.0-cp310-cp310-macosx_15_0_arm64.whl (77.8 kB view details)

Uploaded CPython 3.10macOS 15.0+ ARM64

File details

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

File metadata

  • Download URL: ayafileio-1.1.0-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 91.3 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.1.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 241f6cc05b77cdab87285f035ef26ca23777af925f5eab2a567bc4d1641a3666
MD5 8902b83f0705c1965c1cd72348bfa7fb
BLAKE2b-256 0ff7aea82590dd4e522974c517c8e1803dc2ea09b92e0f7830ba1ba07a362a8c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.1.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4eac86a84a45ddb5e69ff308ce8529d15a74c00f83e44c25ea3e2041ef478ec3
MD5 080b4cd6ec51180ca7877d2a01953853
BLAKE2b-256 4cbc61038ffd586692ae5673cf9a3967cfc746dda0716063d8fec68b67a0d895

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.1.0-cp314-cp314-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 577bcd3283e32ae9b35ba0fbbb727992defdb55fa177b24ad2bbd37dd740b33f
MD5 b9066d2a2be9a54e9031c9ef21c0b3a4
BLAKE2b-256 bcb26efc9c20d84ee68db426afa9283c7648acce42171a1a7e81b5439c0eb954

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ayafileio-1.1.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 88.9 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.1.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 2502a9f3fe7fc92f50144f090052982c1b089b01103fffec6666075fa5c4e072
MD5 d7b54251db1b166e26a8c393f279e8b5
BLAKE2b-256 646281431c7313046c4c34154fbe0d2f5daf91d3324d1e554199c8032f65f864

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.1.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 05a398d9d8390708eac5c21871964b83a89ea2b8f85c25d03fb8607eee0828b1
MD5 3128cd85cace8d06d084930f9b81ec4e
BLAKE2b-256 08a92b89c48b5d6a6c272557a10458a8b8760dfc5aa27c28a04ac206ed7a1509

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.1.0-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 c461ad639b36b339df16698138b215b33a5353d4ed590381848f50e3d3fcd4a9
MD5 46c5dbe4bae7e1902df413dfa7f0b8d6
BLAKE2b-256 d87ee5791527237215d90423d9da882462d238ad4861235de613b2102746cb20

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ayafileio-1.1.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 89.0 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.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 ad0e127369ee8dc1aa9853c014ac8982f5c7a8c1ac8a0c7bcf36a095d8f255ae
MD5 3a73ec9b57b2f933b5a960af4171be54
BLAKE2b-256 e14266d33a3ab583a0f64de5cd7e3ef6f237e42091973b14cca834ebde32c554

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.1.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 bef1256fb816ffac37fb7df7fcd0c37d3c1381d16b13e9f59209c23ec20deda2
MD5 11f2057810457a9091d47c44322a05ba
BLAKE2b-256 d683e0e605d6eefa319a8362a0616d086904be96b29753dc7cf74e33e958816e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.1.0-cp312-cp312-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 de044b3f9cd46471c54aaed2a3ff8533584469615d7d13ba43cc5cdd3afdecdc
MD5 6b0b17aaf1ccf11854871747843b2526
BLAKE2b-256 95ab4514c01acdde8d488f24ee030de54775d2ecf180a2678608e948c91a7170

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ayafileio-1.1.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 89.8 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.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 7708deadcc40b1ca640545e79da9a2f6d8ab57f9db08c9eb69868bbd2478973b
MD5 ab1bb9abf1368d4547373f50a4d76d70
BLAKE2b-256 f15bc0d9439fd0e11d2cdbb1b36b3554ee9facb5c9e74fa827ce495e36000bd1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.1.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2385636ce3a56a737e7cf1557872b2c13e6b5eea0750d0c0d9f36c361302b5f3
MD5 294530eea028e3d8ee7556fcfb7b88d7
BLAKE2b-256 7e1fb77d16a2f4913607458258c8c3fb998e786f96db36e39f8285c0f55e7d48

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.1.0-cp311-cp311-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 1f990c885545da570d220403be96e0101f55dd8e5de313f8c8599e5f6f380b60
MD5 ef7b7abc181024c922fb065543dc2118
BLAKE2b-256 78004a3144ef0a4c221bbc06c323146ffd11522a66c4edfe46c8ed3c949d400d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ayafileio-1.1.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 90.0 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.1.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 c0b09ad734bfc5ef7086bd9fe9c0ae70d8104be74292f489d8be15ebab7ec8fa
MD5 2cbe1c2d0390e2ad4de47d249de75eaf
BLAKE2b-256 44c9981eeeec5247f24d10ed4f0e47c8813aff9cfb246a1345b0ffadec432966

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.1.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0b8d61606cde820ae3ec41a98557f79b12f92d8e1a9428e4ad7f6319fd97a12a
MD5 e03f180e8cec30f39e34171380365d89
BLAKE2b-256 ec1902f87d10500cb230ac2eef941a0d13c2498173b47e4d1d4c31184e5b8d5e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.1.0-cp310-cp310-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 195e1246e31acafa908c6ffe26cc473768ba73852855766e958a6eef5e757a32
MD5 aab72856eb950221d3faa129e95dae10
BLAKE2b-256 37ff300a4bbfdf1cd7dafcdb08036e9c144c4aa58860c9b1bbf30eddb23e072c

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