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

Uploaded CPython 3.14Windows x86-64

ayafileio-0.1.8-cp314-cp314-musllinux_1_2_x86_64.whl (534.9 kB view details)

Uploaded CPython 3.14musllinux: musl 1.2+ x86-64

ayafileio-0.1.8-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (88.4 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

ayafileio-0.1.8-cp314-cp314-macosx_15_0_arm64.whl (54.3 kB view details)

Uploaded CPython 3.14macOS 15.0+ ARM64

ayafileio-0.1.8-cp313-cp313-win_amd64.whl (67.1 kB view details)

Uploaded CPython 3.13Windows x86-64

ayafileio-0.1.8-cp313-cp313-musllinux_1_2_x86_64.whl (534.9 kB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

ayafileio-0.1.8-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (88.4 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

ayafileio-0.1.8-cp313-cp313-macosx_15_0_arm64.whl (54.4 kB view details)

Uploaded CPython 3.13macOS 15.0+ ARM64

ayafileio-0.1.8-cp312-cp312-win_amd64.whl (67.1 kB view details)

Uploaded CPython 3.12Windows x86-64

ayafileio-0.1.8-cp312-cp312-musllinux_1_2_x86_64.whl (534.8 kB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

ayafileio-0.1.8-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (88.5 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

ayafileio-0.1.8-cp312-cp312-macosx_15_0_arm64.whl (54.4 kB view details)

Uploaded CPython 3.12macOS 15.0+ ARM64

ayafileio-0.1.8-cp311-cp311-win_amd64.whl (68.0 kB view details)

Uploaded CPython 3.11Windows x86-64

ayafileio-0.1.8-cp311-cp311-musllinux_1_2_x86_64.whl (535.9 kB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

ayafileio-0.1.8-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (89.6 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

ayafileio-0.1.8-cp311-cp311-macosx_15_0_arm64.whl (55.5 kB view details)

Uploaded CPython 3.11macOS 15.0+ ARM64

ayafileio-0.1.8-cp310-cp310-win_amd64.whl (68.1 kB view details)

Uploaded CPython 3.10Windows x86-64

ayafileio-0.1.8-cp310-cp310-musllinux_1_2_x86_64.whl (535.8 kB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ x86-64

ayafileio-0.1.8-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (89.7 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

ayafileio-0.1.8-cp310-cp310-macosx_15_0_arm64.whl (55.6 kB view details)

Uploaded CPython 3.10macOS 15.0+ ARM64

File details

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

File metadata

  • Download URL: ayafileio-0.1.8-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 68.7 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.8-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 3a36e05542993cf1f1ba5aa2bbd9eb333ea0f418cbdfacfee467bee26273cc87
MD5 fb2c5c8fb95b098a9408697b83424190
BLAKE2b-256 e3f9fae34a4da2da2d3e6afcc31580a3d57a054e88058b3c93f0506a2ce147a3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-0.1.8-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 def2aa17633ca6a53e568a1345d1cafadae8f289200d90b0e1c41333e6f65f2f
MD5 8a6da1da51569b851e9e5eae78f691d8
BLAKE2b-256 f99c4f9f033965824618c01c9abf2edcab5c88fed5d8b9867e2c1e0bd7797ef8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-0.1.8-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 cf923bdad92d54ffef4fd8432eb78998b1e94a0146775e2f251cf8eeee88f69b
MD5 79473837c7421dfbbfd326e57a91f508
BLAKE2b-256 dfbe8feecd8f538f5600cdfe2051ae06c1ea77edfbb32bd92bbd06314c38c5ef

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-0.1.8-cp314-cp314-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 4fd0980a771b4670b1443081dfdb738a2b3354843b5d5926d7d6bdb067e1c22a
MD5 f1014aae75a38f19e3b5305d6132bdef
BLAKE2b-256 53599dd93518d60fdc80830201962b90c5dda73eaa5591c50cc6398ec65d1aad

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ayafileio-0.1.8-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 67.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-0.1.8-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 264e97d02f24bbbbe9eebb7b2ecf811d33534094bd2b95b4aa365984c8eacb07
MD5 92e8c6aa734e614a3458489a917039f6
BLAKE2b-256 eacab37fdd16b10858849b3c42f084b61bccb5c785af6c9b479149760d9b4d51

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-0.1.8-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 e7ffa596128ecea3e2be099e3e7432c176f92d39ed4ed24886984093f8951a05
MD5 b96f376208322d874085da1f0c1c9f3f
BLAKE2b-256 9dd6d8a070c304f30d824bcbdf628acd2e855774e53734aad86f8861fb7aa369

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-0.1.8-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 953ead09a486fd29501068bef3b1941cf380e2429d617e5a8c538c9fbe196bef
MD5 b9e54ce444715bc66fb015be89451d3f
BLAKE2b-256 1f77ffe60004201ba9bba9c1ced6f7270b1283ee40094f8716db9888e2ee1383

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-0.1.8-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 d321c4537414a63be45b39788011ff34a3ab8fb8de7bbfb3e358f9b29d649f25
MD5 c97aa0bf09e35a8048beece4e178a2da
BLAKE2b-256 793f3cc78b404f21773cb7465d33e639687243cbd5254a2754d3304f1cb3f48c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ayafileio-0.1.8-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 67.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-0.1.8-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 84cd22550fd269239c3aeb047a66f993ab5c60732f062011d91d7034f8cb652a
MD5 6795e066707cc590476b688a458a8a49
BLAKE2b-256 dce96f3ba3d30bb55639d41a681387c7be66b5aa7faf7c1355b438b44878ae4c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-0.1.8-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 39e069d86d125fe519fd4221d4050e826ed57f6001f2bb00c5880d70402dd496
MD5 57be41af429b9f083fdc5624a9746c1f
BLAKE2b-256 5b427179cd228d479839a9fd1dacabfc5f0b8018883a689e713b67b7ebf0d255

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-0.1.8-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 f5d9b33ebe9e16ca7ae9c4efada878de34fd1d9ee2dcd8e51a20240da7fd7a80
MD5 36a19d926975f1dff91bab67021465a3
BLAKE2b-256 9365b254e7c53992f08ddcd1b8166587e1dbb059c35acfa44cb8de4401ce7818

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-0.1.8-cp312-cp312-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 aa6d7db6149a399fe9d4554181c1f06f64102c5175f5546e24b0e00ec3544758
MD5 efe1e1a324951297e9768f13546bd985
BLAKE2b-256 7a6d9c6f9033b1bc79bbbde1e35a3b6eb899a84dbd71b453965907574de350c3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ayafileio-0.1.8-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 68.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-0.1.8-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 3920067cdaae69408a9bb7f260c7b57b243e35ea0a5b54080486976856d97ed5
MD5 9e8282b55a65a43ff42a953b498236a4
BLAKE2b-256 8a9370938bd3d670b7f70c0aea02d0de2b28d6c84e363ec87aa3e52bf0ee7553

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-0.1.8-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 a23c97558f3b4d3bf192fcb1a146084de019c7943df02951f0c32024a73ce21b
MD5 b6f9c12e8575ee11f4f34e502509d2c6
BLAKE2b-256 39c903f62152d073aa21a59a69d508eeae0c765e10ec88a58908af0b8cdf6119

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-0.1.8-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 10c5b3f05453d4bd36fdee48881120212f80eee99a6ddfddb1c376f628da63ec
MD5 f324b82200754dee5d2ccdee0c545478
BLAKE2b-256 eb116c6e9239968e0909a1e363603181976ca841f85ee35d1ddc37847c975cfb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-0.1.8-cp311-cp311-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 817a5722c1619cd84a6c0c169a9c25747f0cc4f09211bd7e3e3278a75f91faaa
MD5 8d09c5439bb566883d636875313924af
BLAKE2b-256 3450507472417000485751870c90addac5ce0cfdf009fea3c684ffc1f4401cd6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ayafileio-0.1.8-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 68.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-0.1.8-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 9d7422125d6127d7c708ef6a356a8461a19115caf1f39e8c16eade65f8e05eb3
MD5 1ebc25667d69dc62a0670a106e8b48dc
BLAKE2b-256 f9d1f8038b2041ed55ed2c69b209566d5d0b55be50fbc1b7b24477178cc6d7f8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-0.1.8-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 dba9b19619c825847cc704b1dc58b69650846b91f9c3cd79f7e5d0748eaf4b8d
MD5 ba34f4e883e1653e700e53bdcf340a39
BLAKE2b-256 518b1ce808d51d7c9bb446043ee9670219a5c27fefcc71624cee5eb85ada6237

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-0.1.8-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3603383b4a50fc087a5d79b60583c00da8887b4b34610ff019108ec6a2789754
MD5 23d32f1391c7617915bb014549e2569e
BLAKE2b-256 b796e525f74c5619b46b9285691563fc74ed0c408d5ab435e6164319fef7bc32

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-0.1.8-cp310-cp310-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 9855f357d79795f09201c08588de1157f113e5748c5ddc449291d62b6051259c
MD5 e6273c09538707d38d5d1396225cc755
BLAKE2b-256 6592ce5f3fc5815ecd52d1c76c3a235544ef2c6c592a13eaceb3bae7650e1172

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