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

Uploaded CPython 3.14Windows x86-64

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

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

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

Uploaded CPython 3.14macOS 15.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

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

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

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

Uploaded CPython 3.13macOS 15.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

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

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

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

Uploaded CPython 3.12macOS 15.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

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

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

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

Uploaded CPython 3.11macOS 15.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

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

File metadata

File hashes

Hashes for ayafileio-1.0.2.post1-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 20c29c1ef0f03ae00210fb78dd3a6f14586cb751c894618e4f8acd947bec8bb7
MD5 fbbeee8066ec4ff4bbfaf67f0b46e01d
BLAKE2b-256 8fa2a4a99cbc59ffd89ae829ff926a2d7433818bb2f59292aa36229e9eda2994

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.2.post1-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f0296915ac99593724e28217d73241f1386aad3f243eb3242786858cacc4a2bc
MD5 d02e4b7643ce6762879e799f69207d75
BLAKE2b-256 ad2c3c647c56f71ce0e36660b82583bb9e8e89d70ddcdd068a500874712b2367

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.2.post1-cp314-cp314-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 d756639f413675ca393cd83551a23472bcbacf550ed24423b28d6357867a260b
MD5 108ee2df560a2b5ad7de85e4dff23ced
BLAKE2b-256 09a5267885e9a2b0841c0114377ca5a1fbb1f14a8ba7763fc8c59ebb9d982871

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.2.post1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 4d2a8ea7e2f8dd0e451384e153b2a1675d8dbbda050ceff690e99b760218afff
MD5 9b465f26b9458bc051ca3807cc07e79d
BLAKE2b-256 8f9cf3970534fb40996e312a988e7f245bd3ed8ac926874c9a57eb2dead58cb0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.2.post1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 efa8679ad5fde7c4bbe3c0d9754ae175bf855f9c8d111bc26344e571606b10ed
MD5 f91a63c39d5a462def813506b364ae5e
BLAKE2b-256 ec052854d23b4c22db89b62348d68e7f02be0c8cb49e730be86d246ac4edb356

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.2.post1-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 4f89942dab79c2380723f0969cd6c4785004c8e557c8b598c19ecd75feec7daf
MD5 1d820960d74972731c5bea2b9cb2922f
BLAKE2b-256 12c69c3d377261b9900271adb63535fe8f4c8d312488c894fe960147ff95a02d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.2.post1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 2f53c737f136784d1bf20aeb2a12f5d9656245dd75c463cf92d98989210d641e
MD5 8311470fdf74b0b2b7d8e1e47b4c6ddc
BLAKE2b-256 a7de0465f9f94e6e0f1afc9f7fdbb389e08a2394a863a80218549cc5ba0c0f10

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.2.post1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f28f2d9e5c091d806b905b406321d2b2b41c16f18cb9aebdbbe884217e58152a
MD5 7eae5135aa397ded26aa336743640f66
BLAKE2b-256 ebadbdf32cd62effbc274cb4286d21fb28105811da414181fb8c9874d7e55456

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.2.post1-cp312-cp312-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 52117112dfcb672fc1d1f7b0e0a9309f4ba38fd0b1b8593fa0c0c307cc87f378
MD5 8038f21c10082077f09cc5661d6b5389
BLAKE2b-256 3c987f222e3fcc0213bde6fa821c9b0235b3536adf0b6d6693b689367e6ef88e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.2.post1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 b3a7aa6bc6012eeb04ce12c92d38b9bded898e6c74c286f0906c465c77145d4b
MD5 bb0066e2272d69ed8dd6fced405e49cf
BLAKE2b-256 dd343e9f6c011bf04dabee1b22f89f699298a1f2ef20f356e29812453900db26

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.2.post1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 aab9f1970e00c5c0e2ac946b52263a1ac5bdad0ebc22f878121b87e770063cd4
MD5 482a897d150eb20a1d85e33029b25c9f
BLAKE2b-256 a199ad49cc59c77eb0983a79d296b2544ad708d91bc497e3a67e4feb96c9028c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.2.post1-cp311-cp311-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 e0ddd01d4870fbbc40a6ad0502d5fc41ced2716789a5f91306bec4f40bac52ef
MD5 24e214ce51b81987afff6378f8f29c96
BLAKE2b-256 5866df83a12e31e988d3b6023ba5effca596473891e1bd2435e2205ddccfe29b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.2.post1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 1755483b5f71e292ceb12ada141cd70376a2b430e12b03ee3546f137fc3550db
MD5 f5f775bcff4da90e4e9a5ba9802028d7
BLAKE2b-256 784fe7b9db617e1e991ff793d4ea8d80e7b5f9e01443613ab91968a9014beda6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.2.post1-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 dfb4c25271afabb63ff1defa3a37eb981443454869d8faa295e21220db4e92c4
MD5 f58b641899d8910a58ef157f5e77ab51
BLAKE2b-256 ca7e6315067686b8030c837279b58ce17bf9d07870ab27f48487d83635b62bcf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.2.post1-cp310-cp310-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 0d65da588f50662eff6feb2ba12c83594c2cf47555c079280d118e3e7ba7c34d
MD5 6c5e4e97968755d82aeaf63883bc29a6
BLAKE2b-256 438892e46ede6bc915e04d168eb89746578b756290e5c2ac8e46e1d5ba005867

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