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

Uploaded CPython 3.14Windows x86-64

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

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

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

Uploaded CPython 3.14macOS 15.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

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

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

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

Uploaded CPython 3.13macOS 15.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

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

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

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

Uploaded CPython 3.12macOS 15.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

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

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

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

Uploaded CPython 3.11macOS 15.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.10macOS 15.0+ ARM64

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.1.post1-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 6099fc0968fe1dda3a57119d2a1f3e2f22dab49eb6b5ad53f5e942e8ca5f1eec
MD5 a0e9063b3160d94e303e640807dc3d85
BLAKE2b-256 a47f7593b2deb9ae3181d50c0266cf1c75b0600d74ca2c924cdc4d5257285387

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.1.post1-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 940a14afebec4bf011695b9fceb413f249cc894c3740778c6706ec979abdae0b
MD5 da586a8de978f8f7e6f646ab3877e9c3
BLAKE2b-256 50e7ea93ab4a73ff3675025c2da635d61584159aa01c5218948ffd148b4c6bd6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.1.post1-cp314-cp314-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 e6da90ad64807a6dba5d7a3fad7124c0fa2a38b344f57c0a1698894f359813a4
MD5 511228770151a608fe30fcee11d6e237
BLAKE2b-256 bd82dfb3d1a366f02469b642988554a87779bef2efee1a62c21d8fb14bd8f1b4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.1.post1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 5a212db05a8433892775992b0a1f950f1edcca04057a689c5e73f7d6cbac956c
MD5 54a42f09954c51ef94268aeed3fd0346
BLAKE2b-256 03a68832615018dcca89d1cc54b4d01c6077c8499ea7954b5ab6b7f79651e078

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.1.post1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b339f2717f461988ee430a13bf0023724a4115cacfb6637419aaf4319ccc8c84
MD5 808c9f2e62e36f227f807cba3dd24c17
BLAKE2b-256 68d1076e14990ede54c6d0b9db52f543114c445525a4107b63e75d364b2df9c4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.1.post1-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 afc3c7eba6be76fe154d512cd69462a87545657df7b30822a7094733cfd27f9b
MD5 af0420e5e734c259350e01c66d2b1c74
BLAKE2b-256 2ffb4df1d3c7ffdb02377a62b9ef4267b105b60ee27dd88be9d7579a16773329

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.1.post1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 cf246bea74f7c57d8857f5cff10115503a7ccedd63c058982b3484c67b530654
MD5 9f50c39939211c7eff9de65b8e9ae404
BLAKE2b-256 220870ca487f43518ed5e3fb700ab14f0ee28f28663f5f238dbd9ddef31f8d02

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.1.post1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5847684b5c44ce302913ad1dd124ff5e707b1a6cc17cb62cc2b7e6bf5cb4d582
MD5 862b80ded4480d04e1f54eee369e5dec
BLAKE2b-256 337248dfce17e74d2461b81505ea8961028b2bc1635762e1465ab71a3cb2c3e1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.1.post1-cp312-cp312-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 35eb1d538caf5ce5f852fc36acc685a786284bc20c666bcd3d2271d72ca04d2c
MD5 023b74b8962861c8a307466598defeaf
BLAKE2b-256 b17329f921ae18a4ae44f5c6802c621c291d77e04ff3dea2dc63055cdabee121

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.1.post1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 a467441a98a9898c9347ad4cc4295f9a0214eaefa47d4647025a944dec7c1f3e
MD5 0074f7d35216484100327503969b4d53
BLAKE2b-256 e4c6536045300636bc994bffd339bbc476f914ec7d8cdeda3bc673a93c03c79c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.1.post1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8363fe62f18874d215ef9881c7ce20e183c9d881e9b4faca051a65b5043daf3b
MD5 5f571fc97e047e3d1000335d215a95b2
BLAKE2b-256 25490b585264d1be20457e46d111b37959a5c1ab02e0f5dbd9181d3c6e829770

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.1.post1-cp311-cp311-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 6f471dbd00ea23f24c2042bb847ea8c6ac72a7fba2db887bf3126d02ca51f775
MD5 bb8848f672fc5b6616cbd645460954b9
BLAKE2b-256 a37836dbf44273a7e1f8ce3f7ad1e7df9015e1f926ce1d98863e2a7e8a7ab21b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.1.post1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 dc7ea2999a70225b224c57016edbcfe67e97b7ddf1ad1aa084ca08b2570d81ff
MD5 09826ed5a072065e28497b98a03abd83
BLAKE2b-256 be7bc4808e7ef89947bb445996b5b64380a185ab03e078c565bb7e6c023cd161

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.1.post1-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6aa8258aa62d2c8d186efa82452db4d624641ea55cf7b9eb521716a9423947cf
MD5 3fdbb014ea2bc9467c5ba049a92841a3
BLAKE2b-256 b5ffa3449e9ce2e9e19af83e757c01a408502b2df98a6ea7e84412fb711e1bd3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.1.post1-cp310-cp310-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 212412a7ff385c8eaf86fdf66efbe3471f2e90fd8027dc55f0a45de1b42e4443
MD5 46f0edebcfca35b257d949a2fc78c269
BLAKE2b-256 4a60221ec12d3d7722c4456465937619e19628987e8618d1276a23b0aa0e8265

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