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

Uploaded CPython 3.14Windows x86-64

ayafileio-1.0.5.post1-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (109.7 kB view details)

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

ayafileio-1.0.5.post1-cp314-cp314-macosx_15_0_arm64.whl (74.7 kB view details)

Uploaded CPython 3.14macOS 15.0+ ARM64

ayafileio-1.0.5.post1-cp313-cp313-win_amd64.whl (87.1 kB view details)

Uploaded CPython 3.13Windows x86-64

ayafileio-1.0.5.post1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (109.8 kB view details)

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

ayafileio-1.0.5.post1-cp313-cp313-macosx_15_0_arm64.whl (74.7 kB view details)

Uploaded CPython 3.13macOS 15.0+ ARM64

ayafileio-1.0.5.post1-cp312-cp312-win_amd64.whl (87.2 kB view details)

Uploaded CPython 3.12Windows x86-64

ayafileio-1.0.5.post1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (109.9 kB view details)

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

ayafileio-1.0.5.post1-cp312-cp312-macosx_15_0_arm64.whl (74.8 kB view details)

Uploaded CPython 3.12macOS 15.0+ ARM64

ayafileio-1.0.5.post1-cp311-cp311-win_amd64.whl (88.0 kB view details)

Uploaded CPython 3.11Windows x86-64

ayafileio-1.0.5.post1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (111.0 kB view details)

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

ayafileio-1.0.5.post1-cp311-cp311-macosx_15_0_arm64.whl (75.8 kB view details)

Uploaded CPython 3.11macOS 15.0+ ARM64

ayafileio-1.0.5.post1-cp310-cp310-win_amd64.whl (88.2 kB view details)

Uploaded CPython 3.10Windows x86-64

ayafileio-1.0.5.post1-cp310-cp310-manylinux_2_28_x86_64.whl (110.4 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

ayafileio-1.0.5.post1-cp310-cp310-macosx_15_0_arm64.whl (75.9 kB view details)

Uploaded CPython 3.10macOS 15.0+ ARM64

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.5.post1-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 43fead0e340c9ffee9469e2698227ba1e93f88a2e5c2ac1de7e710a9e1df4a1c
MD5 a4aa05f61081aa1290bf1fd33bda5c7a
BLAKE2b-256 b504ec99f3712fdc740fb3d04b4b91ae991ff95bc324c915b3565125e416f584

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.5.post1-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 14616220181d08104afdde778c702ff6dcaecb0f4951b2b9d82a98d148212dc2
MD5 7eef1594b9d616bc05a87ead8a659697
BLAKE2b-256 c32f3f0ba0134ff7ae99ac2b5a4ec1f13fe29f675d34087f641f2afff3130ded

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.5.post1-cp314-cp314-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 920d3e661ac387705f232882e66b3590254ce2301952735ae970f9d041b7ffbd
MD5 3424aa68136a76d2b5404171cf2a9d20
BLAKE2b-256 dee2aad8df247694aac44b312f9b21097d76b0f565736a5150a45f50e357fd35

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.5.post1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 c22a4248e5414f3f7d3e3b998d505e26bf31a9738be286d8a3e743ea3325bebb
MD5 abd4403c3ea4cd4c522535823fe9fb4b
BLAKE2b-256 cb51c3ed09c5d12434fcd3191a3f7522e5226d223f97b6b20a6c477431138933

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.5.post1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7da38f011b9c40ba7b0ed67828e9abe0bcb07c6c2e628743d996f91d20a4fed5
MD5 b9021722b2b8e24fc32cb0fa4171f26d
BLAKE2b-256 d85903cffdea7a5f9eec46d814163ef6b389ad7d349360e3d7869e0b78c684c5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.5.post1-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 8c70c889ac5919cfb61ab50bc4ad9612cc92b8418ed217ab73f83e250d0314a5
MD5 f0c6e67d6a75510750d47bf1f526773e
BLAKE2b-256 b241da0da7ec809612e3351c4a8f006d6ef0651d13e5f747b068f11e04658994

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.5.post1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 c32e9916f77610b9f7a07053c513a53d60b970e0db68c1e963881e4879cbd8c1
MD5 2724a1d4940b5e0052e2f5aaa12e5ce4
BLAKE2b-256 1f7dfe862a06de8c63bc5b6aab94fc61fd8baa5515113a25dbd252b2d5593d21

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.5.post1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 04c44b24598216f4f5d21985f4d836209dd44f7a9ff871c310e3f4c5124be414
MD5 eb4f81d24b4fb870fbb374940c35f0bc
BLAKE2b-256 b83441af2c15b96d9f3b997baeb0ff61d22e97a99183d097cede3f2f9ef9fb5c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.5.post1-cp312-cp312-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 cad7529c0f54a6f410e3c13eeb8395f050888b54ce468d4c830495bb89bb28f3
MD5 69caeee968381e079795c2b5bebc0092
BLAKE2b-256 7bdb17f3d803e036a5b33cb96bc5f6ae543e972735eef5f383d18bc5c3b6957c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.5.post1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 cc707179d9f5e5647fe88fe46def2a26fe213f00d6f94dc62fbf967c44d25bf2
MD5 7923b59a93795a4dc689502edd150087
BLAKE2b-256 6d092da381501e1d42cca6123ef18182b68f4f24e7c163403080974522f1a58c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.5.post1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 58aa5c3ee6e76c670a56138a2d4a248ecffe8253e462af9f0acf604aa14582e1
MD5 beeab2eb8bdcb5e1d70ba5ca2c41da75
BLAKE2b-256 9f5494a00b965b74f85f1432503dd9b8bf542104208eb107afc16b3cb48f2a62

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.5.post1-cp311-cp311-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 3ae4e5949e65bf0d387f5bb5d3a5b78fb427591ea668233ebb652e68242efe62
MD5 96711e14ac3a21b28152cb6c05070782
BLAKE2b-256 0be8548c0fdd47db88ec129c8bd38710d6b580518be2ef27b5557d331d9726ff

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.5.post1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 374264759e9a5b98dc273f3a431b15ab05abc226fd59abd67250ec5f23c36f4e
MD5 0ff5cd5c314a1abd7164ec4dd2b3e262
BLAKE2b-256 03930abc9ee00f6b51e00e05ce7303a5486a1a758381d73b5f9aaec671b6bd1c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.5.post1-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 48efbc6678520750286cbe0a3e4c9f2cc47d3917e28b86223868ec71d08c2a08
MD5 7b90016f77225a92894752a0c2f627ac
BLAKE2b-256 9acecc060cb263a63158633cd9b1fd2530e55c2dd5e0fc0ae80fd4be2eaeb35f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.5.post1-cp310-cp310-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 1dfbca0021688dc99729077275f549c50eeff883c4d413091cebf64c921c5a97
MD5 c0f66fc2d1e5830937503bf55db8a829
BLAKE2b-256 d32430fbdbf135fb46c0e30c19a973dbdeadf6c58980e7240a46239fc498c41c

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