Skip to main content

Cross-platform async file API for Python. Blazing fast like Shameimaru Aya.

Project description

ayafileio

License Python Version Platform Speed

「幻想郷最速のファイルI/O、風神少女の如く」
—— 射命丸文,今日も全力で翔ける

跨平台异步文件 I/O 库,使用原生异步 I/O 机制。
Windows 上借 IOCP(I/O 完成端口)之力,Linux 上以线程池模拟异步,实现真正无阻塞的文件操作。

📸 核心特性

特性 说明
🍃 零线程开销 无需 run_in_executor,无后台线程 (Windows)
📰 内核级完成 无用户态调度延迟,直达内核
高并发友好 数千并发文件操作,文文团扇一挥间
🎴 标准 API 熟悉的文件接口,支持 async/await
📖 文本二进制支持 文本模式自动编解码
🔧 可配置句柄池 根据工作负载调整性能 (Windows)
🌍 跨平台 Windows / Linux 皆可翱翔

🛠️ 安装

pip install ayafileio

系统要求:

  • Python 3.10+(幻想郷的科技也要与时俱进)
  • Windows 7 / Server 2008 R2 或更高版本,或 Linux
  • 无其他依赖(自带团扇,无需外援)

🚀 快速开始

import asyncio
import ayafileio

async def main():
    # 写入文件——像风一样快
    async with ayafileio.open("example.txt", "w") as f:
        await f.write("Hello, async world!\n")
        await f.flush()

    # 读取并自动解码——文文新闻,一触即达
    async with ayafileio.open("example.txt", "r", encoding="utf-8") as f:
        content = await f.read()
        print(content)  # "Hello, async world!\n"

    # 二进制操作——数据如风,来去无痕
    async with ayafileio.open("data.bin", "rb") as f:
        data = await f.read(1024)
        await f.seek(0, 0)  # 风神少女,回首即原点

asyncio.run(main())

⚙️ 高级配置

句柄池调优(Windows)

高并发工作负载时,调整句柄池大小,让文件句柄如天狗之羽,收放自如:

import ayafileio

# 查看当前限制
max_per_key, max_total = ayafileio.get_handle_pool_limits()
print(f"当前: 每键 {max_per_key},总计 {max_total}")

# 增加以提升多文件性能——风势加强!
ayafileio.set_handle_pool_limits(128, 4096)

这会在打开/关闭周期中重用文件句柄,减少昂贵的 CreateFile 调用——毕竟,天狗从不做无谓的起落。

I/O 工作线程数(跨平台)

# 设置 I/O worker 数量(Windows 上为 IOCP 线程数)
ayafileio.set_io_worker_count(8)  # 0 = 自动,1-128 = 手动
# Linux 上调用此方法也不会报错——优雅降级,是风神的风格

📚 API 参考

AsyncFile 类

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: ...

支持的模式

模式 说明
"r", "rb" 读取(文本/二进制)
"w", "wb" 写入(文本/二进制)
"a", "ab" 追加(文本/二进制)
"x", "xb" 独占创建(文本/二进制)
加上 "+" 读写组合,风神双持

函数

def set_handle_pool_limits(max_per_key: int, max_total: int) -> None: ...
def get_handle_pool_limits() -> tuple[int, int]: ...
def set_io_worker_count(count: int = 0) -> None: ...  # 跨平台通用

🧪 性能对比

在同等环境下(测试时长 10 秒,随机读写混合),ayafileio 展现出了天狗般的速度:

并发数 ayafileio aiofiles 优势
50 2,043 ops/s 1,657 ops/s +23%
100 770 ops/s 405 ops/s +90%
500 1,130 ops/s 1,032 ops/s +9.5%

P99 延迟对比(越低越好):

  • 100 并发:ayafileio 33ms vs aiofiles 562ms
  • 200 并发:ayafileio 35ms vs aiofiles 155ms

数据基于 Windows 10 + 机械硬盘(C5=12, C6=45)实测——即使是即将报废的硬件,文文依然能跑出速度。

运行基准测试:

git clone https://github.com/your-repo/ayafileio.git
cd ayafileio
python run_benchmark.py

🤝 贡献

欢迎投稿「文文。新闻」!请:

  1. Fork 本仓库
  2. 创建功能分支(git checkout -b feature/amazing-feature
  3. 添加测试(天狗也要认真对待)
  4. 确保基准测试仍通过
  5. 提交拉取请求

📄 许可证

MIT 许可证 —— 最速最自由,详见 LICENSE

🙏 致谢

  • 感谢 Windows IOCP 提供的真异步之力
  • 感谢射命丸文带来的「最速」精神
  • 感谢所有在坏盘上测试的勇者们

「遅いのは罪だぜ?」
—— 射命丸文,『文文。新闻』主编

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

Uploaded CPython 3.14Windows x86-64

ayafileio-0.1.9-cp314-cp314-musllinux_1_2_x86_64.whl (536.3 kB view details)

Uploaded CPython 3.14musllinux: musl 1.2+ x86-64

ayafileio-0.1.9-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (89.8 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

ayafileio-0.1.9-cp314-cp314-macosx_15_0_arm64.whl (55.6 kB view details)

Uploaded CPython 3.14macOS 15.0+ ARM64

ayafileio-0.1.9-cp313-cp313-win_amd64.whl (72.8 kB view details)

Uploaded CPython 3.13Windows x86-64

ayafileio-0.1.9-cp313-cp313-musllinux_1_2_x86_64.whl (536.3 kB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

ayafileio-0.1.9-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (89.8 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

ayafileio-0.1.9-cp313-cp313-macosx_15_0_arm64.whl (55.6 kB view details)

Uploaded CPython 3.13macOS 15.0+ ARM64

ayafileio-0.1.9-cp312-cp312-win_amd64.whl (72.9 kB view details)

Uploaded CPython 3.12Windows x86-64

ayafileio-0.1.9-cp312-cp312-musllinux_1_2_x86_64.whl (536.3 kB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

ayafileio-0.1.9-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (89.9 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

ayafileio-0.1.9-cp312-cp312-macosx_15_0_arm64.whl (55.7 kB view details)

Uploaded CPython 3.12macOS 15.0+ ARM64

ayafileio-0.1.9-cp311-cp311-win_amd64.whl (73.8 kB view details)

Uploaded CPython 3.11Windows x86-64

ayafileio-0.1.9-cp311-cp311-musllinux_1_2_x86_64.whl (537.3 kB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

ayafileio-0.1.9-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (91.0 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

ayafileio-0.1.9-cp311-cp311-macosx_15_0_arm64.whl (56.7 kB view details)

Uploaded CPython 3.11macOS 15.0+ ARM64

ayafileio-0.1.9-cp310-cp310-win_amd64.whl (73.9 kB view details)

Uploaded CPython 3.10Windows x86-64

ayafileio-0.1.9-cp310-cp310-musllinux_1_2_x86_64.whl (537.2 kB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ x86-64

ayafileio-0.1.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (91.1 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

ayafileio-0.1.9-cp310-cp310-macosx_15_0_arm64.whl (56.9 kB view details)

Uploaded CPython 3.10macOS 15.0+ ARM64

File details

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

File metadata

  • Download URL: ayafileio-0.1.9-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 74.9 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-0.1.9-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 701591a7d61d3fc2e24de2b38df782b13b53a5ae542e7f389cba5d2cd5999bb6
MD5 4f2014b3cc5df64c7f8d852234987bbb
BLAKE2b-256 9f7251b88091e5c08753e21a0e990543b48506ff57736a8fd2343e340cb15d00

See more details on using hashes here.

File details

Details for the file ayafileio-0.1.9-cp314-cp314-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for ayafileio-0.1.9-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 3327afcd1ee61be8cbb17c7b60335a8acd335706be1766d534c2a6efc2689fd5
MD5 844c8c37fc1d97f323f8dbc614b23f0a
BLAKE2b-256 80b0423b437be5b510a1fb991bd9867e895d3f75883f2150cab12dd4a8636792

See more details on using hashes here.

File details

Details for the file ayafileio-0.1.9-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for ayafileio-0.1.9-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 9d956f3233f6c9945dfe568a9fffdaa6b83fcb97880af372dd23e652e063284b
MD5 fc0ca69723002036678e32881a6f8834
BLAKE2b-256 2ecf7b7bcecd1c882d8a1ec6960a23d03797e624b52d5c46837f11c0dae870a3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-0.1.9-cp314-cp314-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 8e185c3f892551fd3deea8b56abeeb2d4048a498c057f036061a4d0f1a04f86c
MD5 38448b0da7d269a690006559acda662d
BLAKE2b-256 9e34e4b131e43f515ec6ea88c474a50fb8b4886d1bd2ffd968dbf0fb307c66da

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ayafileio-0.1.9-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 72.8 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-0.1.9-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 affd630b83617175bc53a43bdffdb4764f0437fa1135be55fb67deab3719414a
MD5 d0f015d8c950251995c5753931a1127f
BLAKE2b-256 f17bf65daf982aae95930b94e6580cafd334edcc625f5d30b99b0937caf9b13d

See more details on using hashes here.

File details

Details for the file ayafileio-0.1.9-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for ayafileio-0.1.9-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 8d1fa281eb0c29d6e2bdf7acabfa8fecdbf47326b129af5396d9831cc46f5bc9
MD5 f7b17332ef6f7bd33190bc7b777cb688
BLAKE2b-256 73210a850a2fbb0543a2461943f375b095c85a46febac6561b81470ad7ee0847

See more details on using hashes here.

File details

Details for the file ayafileio-0.1.9-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for ayafileio-0.1.9-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 0bbcbf9a1531f648d34f08290212c3d5ba59f612d7f940a1a77b4518d909fec3
MD5 f826172f47d687f75ea2ed0c4418de0f
BLAKE2b-256 7034e01805394f6e665572c9a3680fbf026677a531e23c14dc212af3577d63db

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-0.1.9-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 2b720c8700aa8b4a393919bb963c545c605e3dfad0eb5c7174c0e34ced33dc9c
MD5 1c23435c70b9d5877d36469674247ccc
BLAKE2b-256 3098c77e57f54011afdf7430056d4d231b0c3adc61e5bd26b49506aa36806af9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ayafileio-0.1.9-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 72.9 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-0.1.9-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 17b90fd1c348fae49c6e5774194bfa567b4f7973b26e7b11c031c8119a9a6811
MD5 0d4d344106039e93f769de1288448b4d
BLAKE2b-256 82e01e1172ab587604b1c92aa1c4713451f1d6e7aba83408c4af419621aa820b

See more details on using hashes here.

File details

Details for the file ayafileio-0.1.9-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for ayafileio-0.1.9-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 30d3227b8f6cc3981074b14033e9cf73545a207660b8a38222bb737e0b506583
MD5 f212e276d22a32a2ba8b99cf3df7af2d
BLAKE2b-256 a5405254038e4ed6278b432a28c9fa42ad4ccabcad5e5a083333b4a2d236164d

See more details on using hashes here.

File details

Details for the file ayafileio-0.1.9-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for ayafileio-0.1.9-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 3719fb050d2db2a154d6fd38ec1049f505c7edb7e693cf85bc69dd5a5b451b60
MD5 5b9db368b629d4080499b2b42f8254b8
BLAKE2b-256 7f3b205c68a6ad0866062c8c9f9d39e3a4c5c378ea37a510218e9fdab2c7d6e8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-0.1.9-cp312-cp312-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 9c12cbf546a4104a24cbb24d15cefa359844583cad82a10b27d40305f0575716
MD5 c3a576ced446c108a2a0ba468082e33c
BLAKE2b-256 caac8f3679b5400ac3bb6959e85551a4c94576edd3493cb54c4f6638dd58531d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ayafileio-0.1.9-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 73.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-0.1.9-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 f1717619c961613be67e04d6f07b57fa29aa4d1299c70493c9c80aef4b9a01ab
MD5 3b55a7af851fdaf620ba913d6bb430e4
BLAKE2b-256 5388b207eb92353fc24ff220fd59867245b986d26782b71a032e9449f0e0bd28

See more details on using hashes here.

File details

Details for the file ayafileio-0.1.9-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for ayafileio-0.1.9-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 671206307f4fd3b72bfe71f78da06852b088b212039e5570f78eeb0d5fd90e49
MD5 150a46b2d0d22d34fc0a2b56da429bb4
BLAKE2b-256 3cf5996882fdc2bac15f3754ba6ce88a80d5173aa29bb39940fc09c55f360e03

See more details on using hashes here.

File details

Details for the file ayafileio-0.1.9-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for ayafileio-0.1.9-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 141e5b4aa318e1073408e7549b79a72b7836a113aae2f55792f125686cbefb9e
MD5 b965df8597032474cf94532a51368d09
BLAKE2b-256 e335794881b7d1591094af62ffc1239ab5517e05958e6b9e9b2b2a33b3bdea18

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-0.1.9-cp311-cp311-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 b8b690c846586708aef0af7a718bcaed1452c84794c322b8035555d5996a40bf
MD5 ccf9f868baba332b1a6e2e257144ec31
BLAKE2b-256 0cefb4eec89751c99347145f5d4e383bb95fc654dbcaa77bea64c38ffea25eaa

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ayafileio-0.1.9-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 73.9 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-0.1.9-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 84b203e867971cfd0a7266345d44d9d382e15fe73c6adb02307001d8d8bff54e
MD5 f28be5345263a8b1fbd6c7566b0b54cb
BLAKE2b-256 9d3a8cc3bdfe2caef31f7bf0b40bc6927e33032eedc59ea22d6f82220398481e

See more details on using hashes here.

File details

Details for the file ayafileio-0.1.9-cp310-cp310-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for ayafileio-0.1.9-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 72f40d12a750ae963d5280999e56ef4ff3206d4c50d633629774f60eefdb1838
MD5 6ea1d33fd9f67bcc19952f1f951aaca7
BLAKE2b-256 254a89e7c08df7443c6211ff375724381e9db4f645c062b11f83e72e87fce5ff

See more details on using hashes here.

File details

Details for the file ayafileio-0.1.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ayafileio-0.1.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6e66c650396eed1642949e37f5b89c02b5f03aba74143ae0ebaf1cac2102c34f
MD5 c0a2434be726cdbd77bc5753ac6aad6e
BLAKE2b-256 f5a1ee365b412693ed76752cf576b2949ae779a276d6b136cb08dfca4ecf9a39

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-0.1.9-cp310-cp310-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 445c1bc763fe6959dbea38972622ad387b43283aca527e2389780712a1affac2
MD5 2dd86f1023a6b222535c1e324aa43203
BLAKE2b-256 99131e44fbf5f85650845c7688f5328e27a0ff157dbb8d619f2ddc7590b8d98e

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