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

Uploaded CPython 3.14Windows x86-64

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

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

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

Uploaded CPython 3.14macOS 15.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

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

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

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

Uploaded CPython 3.13macOS 15.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

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

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

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

Uploaded CPython 3.12macOS 15.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

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

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

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

Uploaded CPython 3.11macOS 15.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.10macOS 15.0+ ARM64

File details

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

File metadata

  • Download URL: ayafileio-1.0.5-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 89.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.5-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 f4d6537e9bdab3fef5cc127ba8868817753a55e141535ab6f967549194518870
MD5 096eb8ca121c37faa7eac548c5b72868
BLAKE2b-256 ce1a6c8f4be4da29fe6b9d8bb534c73941b3cc3e143cbc138dd7a53a1b7fb1ef

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.5-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 afe48942400d191c19efcf558c6818fa847c7e3456bb8fb046c833ae6ae41bf1
MD5 9bb5418b955feb14614a2261128df8da
BLAKE2b-256 6e5f693fe8e1b8eeb29dda40676405eb606274836d83ed650eb07eb936f82cec

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.5-cp314-cp314-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 d80a056db2b63e4ac5c81f28e3fb5f188c60c2b562ee53caf4d0117a8335b05d
MD5 3f7e97760eb368ad481e58caf7eed60a
BLAKE2b-256 e2d99ca39a704ad091779e740c36bcd9ead515007be6dd1578b34386d9f6d9d6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ayafileio-1.0.5-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 87.1 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.5-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 2b47758577723d6c74beb562033e2c5c01736b74d6092864712e53f1d6d6d272
MD5 0868820ae4839f29b9bc11b327c5b632
BLAKE2b-256 f013c2bf3b3e1c9397aaf4cba62c36f00a80cfbbb1140ba0438b6a962a77e4e4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.5-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 852540fa0a4f71f99c01d736efe898c6ed86e7379a1d3c44bb27ae6f523f40d9
MD5 7bc9680f94018b1eb969219f75a1eb7f
BLAKE2b-256 9eaab10d9dcf1c8271ee43a48e3087156c1c9ec6eeb08af6eebd709bc38b9f86

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.5-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 947e7a646d3b9ff946e659f525a0ccc315a91af8de69aa9c6401c7bb535d370d
MD5 44928c8d437acde3fa54c9a5038f2159
BLAKE2b-256 8afccb2b63b7334ca372594384966a7a73b06e0800f88be8a4e25acee3bda84d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ayafileio-1.0.5-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 87.1 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.5-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 9c4ca8d928c25af45b2ccbb1cee89634ff616c7cc83f46c4b207c54155ded560
MD5 9eac78a589d757fd0558009b62b973a3
BLAKE2b-256 9020bf3185b09fc7d79e794b984c59db58a303e40449172612cf4809c8be3fd1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.5-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 fd9073401a87b4d0e88e07733ac40a4b5e0a693175f4ceb4ffe8c29a1822e106
MD5 37a55b5bd06e9325107cd606c0cbb8c2
BLAKE2b-256 30333081eccbc1c7f7410cee7e5aefaba17266646e7ada11924abb238980e30d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.5-cp312-cp312-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 8f7090d4e279120aae5fef229c10401c75aaa09e734d05a51d1f71f9c10ce71c
MD5 e4b0de24cda2259a98394ce3ffa94e2c
BLAKE2b-256 56d69f5eafcf0d4858e2a9155cece33c1f2cebd2931ceb1b8b94db27dcb33e79

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ayafileio-1.0.5-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 88.0 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.5-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 1f3e297f643f0f52d7f436036b5a2be64a7d76a7fbc45d47b4e5e8d9e51340d2
MD5 9681de679ed844613cbf70cf7f081945
BLAKE2b-256 8ce1b0f46b6a9c09d5488323628c7665b4a6819b2e244ebdcb5542623f9f83c3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.5-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 adabcf00ed89cf8c33559b12bfe9a1edc681fc68359381a3ac4dc742fdbf9acd
MD5 1e7b8b9b7fe1a3c905e7266b3b696fff
BLAKE2b-256 ff65cd35ed1f3542edc54177cd6e54a810d67fa95eddd049d0d6f07bff2323cb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.5-cp311-cp311-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 b19e0f33f051781700f4a2286015ebf90a9566b1041a1ec38357fd790e1986fc
MD5 85aea1ee0daf02409e964dee63766371
BLAKE2b-256 3953df417f1a9bbef5364687bfe52eb29c019c085b8eb5547284545d9de9bbbc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ayafileio-1.0.5-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 88.1 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.5-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 f238e550404e41c9142328e065a65a6e4a2ec9ff0b8cdbabf3b7714905336aa6
MD5 bd81f4d20fe0eb7803418c134d2370b2
BLAKE2b-256 fbbe837938f8d22061bd31e4d569b5c732ab73aae7be19a5d7fa24a4b40989e4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.5-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7c7902bbadd58811d24a703de41509b51b73b28ea60dc47ab57722d00c5dc89c
MD5 5a4db6737cbd5f7c2684bede2ae3d4aa
BLAKE2b-256 39ebde3a7d2860c4a623334dbde419620a4af28eaff15b855daf9c43f319914a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-1.0.5-cp310-cp310-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 2fd1f0bf508e94d1c8dec9bcdb2c6467150bbcca2f972da302c9e2123f9411db
MD5 9f20d58d495a6a95ea638b59ff2b3e4b
BLAKE2b-256 adfd8882ef04ce9afe6a7093e355a6d7564016878bcfb0b36d041103a34ae6b4

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