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 上支持 io_uring(内核 5.1+)或线程池降级,实现真正无阻塞的文件操作。

📸 核心特性

特性 说明
🍃 零线程开销 无需 run_in_executor,真异步平台无后台线程
📰 内核级完成 IOCP / io_uring 直达内核,无用户态调度延迟
高并发友好 数千并发文件操作,文文团扇一挥间
🎴 标准 API 熟悉的文件接口,支持 async/await
📖 文本二进制支持 文本模式自动编解码
🔧 统一配置系统 运行时动态调整所有参数
🌍 跨平台 Windows / Linux / macOS 皆可翱翔

🛠️ 安装

pip install ayafileio

系统要求:

  • Python 3.10+
  • Windows 7 / Server 2008 R2 或更高版本,或 Linux (内核 5.1+ 可启用 io_uring)
  • 无其他依赖

🚀 快速开始

import asyncio
import ayafileio

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

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

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

asyncio.run(main())

⚙️ 统一配置

ayafileio 提供统一的配置系统,所有参数可在运行时动态调整:

import ayafileio

# 查看当前配置
config = ayafileio.get_config()
print(config)
# {
#     "handle_pool_max_per_key": 64,
#     "handle_pool_max_total": 2048,
#     "io_worker_count": 0,
#     "buffer_pool_max": 512,
#     "buffer_size": 65536,
#     "close_timeout_ms": 4000,
#     "io_uring_queue_depth": 256,
#     "io_uring_sqpoll": False,
#     "enable_debug_log": False
# }

# 修改配置——风势加强!
ayafileio.configure({
    "io_worker_count": 8,
    "buffer_size": 131072,      # 128KB 缓冲区
    "close_timeout_ms": 2000,
})

# 重置为默认值
ayafileio.reset_config()

配置项说明

配置项 默认值 说明
handle_pool_max_per_key 64 每个文件最大缓存句柄数 (Windows)
handle_pool_max_total 2048 全局最大缓存句柄数 (Windows)
io_worker_count 0 I/O 工作线程数,0=自动
buffer_pool_max 512 最大缓存缓冲区数
buffer_size 65536 单个缓冲区大小 (字节)
close_timeout_ms 4000 关闭时等待 pending I/O 的超时 (ms)
io_uring_queue_depth 256 io_uring 队列深度 (Linux)
io_uring_sqpoll False 是否启用 SQPOLL 模式 (Linux)
enable_debug_log False 是否启用调试日志

🔍 后端信息

查看当前使用的后端:

info = ayafileio.get_backend_info()
print(info)
# Windows: {'platform': 'windows', 'backend': 'iocp', 'is_truly_async': True, ...}
# Linux (io_uring): {'platform': 'linux', 'backend': 'io_uring', 'is_truly_async': True, ...}
# Linux (fallback): {'platform': 'linux', 'backend': 'thread_pool', 'is_truly_async': False, ...}
# macOS: {'platform': 'macos', 'backend': 'thread_pool', 'is_truly_async': False, ...}

📚 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 configure(options: dict) -> None: ...      # 统一配置
def get_config() -> dict: ...                   # 获取当前配置
def reset_config() -> None: ...                 # 重置为默认值
def get_backend_info() -> dict: ...             # 获取后端信息

# 向后兼容(推荐使用上面的统一配置)
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 + 机械硬盘实测——即使是即将报废的硬件,文文依然能跑出速度。

🤝 贡献

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

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

📄 许可证

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


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

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

Uploaded CPython 3.14Windows x86-64

ayafileio-0.2.2-cp314-cp314-musllinux_1_2_x86_64.whl (542.2 kB view details)

Uploaded CPython 3.14musllinux: musl 1.2+ x86-64

ayafileio-0.2.2-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (81.1 kB view details)

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

ayafileio-0.2.2-cp314-cp314-macosx_15_0_arm64.whl (61.3 kB view details)

Uploaded CPython 3.14macOS 15.0+ ARM64

ayafileio-0.2.2-cp313-cp313-win_amd64.whl (78.8 kB view details)

Uploaded CPython 3.13Windows x86-64

ayafileio-0.2.2-cp313-cp313-musllinux_1_2_x86_64.whl (542.2 kB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

ayafileio-0.2.2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (81.2 kB view details)

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

ayafileio-0.2.2-cp313-cp313-macosx_15_0_arm64.whl (61.4 kB view details)

Uploaded CPython 3.13macOS 15.0+ ARM64

ayafileio-0.2.2-cp312-cp312-win_amd64.whl (78.8 kB view details)

Uploaded CPython 3.12Windows x86-64

ayafileio-0.2.2-cp312-cp312-musllinux_1_2_x86_64.whl (542.3 kB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

ayafileio-0.2.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (81.2 kB view details)

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

ayafileio-0.2.2-cp312-cp312-macosx_15_0_arm64.whl (61.4 kB view details)

Uploaded CPython 3.12macOS 15.0+ ARM64

ayafileio-0.2.2-cp311-cp311-win_amd64.whl (79.8 kB view details)

Uploaded CPython 3.11Windows x86-64

ayafileio-0.2.2-cp311-cp311-musllinux_1_2_x86_64.whl (543.4 kB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

ayafileio-0.2.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (82.3 kB view details)

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

ayafileio-0.2.2-cp311-cp311-macosx_15_0_arm64.whl (62.5 kB view details)

Uploaded CPython 3.11macOS 15.0+ ARM64

ayafileio-0.2.2-cp310-cp310-win_amd64.whl (80.0 kB view details)

Uploaded CPython 3.10Windows x86-64

ayafileio-0.2.2-cp310-cp310-musllinux_1_2_x86_64.whl (543.4 kB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ x86-64

ayafileio-0.2.2-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (82.4 kB view details)

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

ayafileio-0.2.2-cp310-cp310-macosx_15_0_arm64.whl (62.6 kB view details)

Uploaded CPython 3.10macOS 15.0+ ARM64

File details

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

File metadata

  • Download URL: ayafileio-0.2.2-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 81.1 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.2.2-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 fa39c567f198939a09a742da6a5b5a4ad892e48a5473c014bd1eae25cad79bb5
MD5 227a4a46e658147938f5977416da15fc
BLAKE2b-256 f1d7b48413a860c4674e51fc3d1e59f270bda725acd4b1ea0d0788a15f377d45

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-0.2.2-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 6c102469b084ab31bb7381b81c7d75a7432aae4f3365efafc4653d06f4aa604d
MD5 10fda5ecc9eb56b35c418b58b92aceb2
BLAKE2b-256 15858fc8f67f76f3fab730937472da9c1bb54f1fe9afd8741695a30568193e86

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-0.2.2-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 edcb252bea4e41d9f1463bc49ae25c9ac93970bdb26fbbce5d563cf5941c4453
MD5 efb8f2465282fface4781270f50bef97
BLAKE2b-256 dd6becc0a49323aa054544502af788a9d6bf270d9d641a7259683c7ff4b31df6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-0.2.2-cp314-cp314-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 c96ee73b5533f4cc4fd9af9703bc9cdd2ebd020b223410fa60236f7fd9ea6fdd
MD5 e1b9bc414ced9aa0822b5b4e576e7c26
BLAKE2b-256 1d7ee0d999f45ee780611aa6f631639beff76115b6ed29eeddedda9c150a84e4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ayafileio-0.2.2-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 78.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.2.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 81946ae829ee29d7dc2248c1875139e01176c1bb40155761d95498abc97e0a2c
MD5 d341e26e818bab9eaad361506aa796cc
BLAKE2b-256 f4756ffc1bfb3f52f2899de8a6dfb42acdf7409f8780efbb8541ce2fabbbd512

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-0.2.2-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 ff9c3edfc4311735c0d1106992b562fe24cab4594df7e7036790b4ac8ef2da01
MD5 8f11d1cf98dfd180da245f5af3cc79f5
BLAKE2b-256 8ac0bb35df0e619e4ca06ca7f5580370f07194cdf65873ed3c0a748739f6bceb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-0.2.2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 100a8b1ad365f4882c77c9bf75506492f2ea99c33a3b55dc35a604fbc722edcd
MD5 054556674dbdf23df733bab1f912bbac
BLAKE2b-256 dcfe73c748bda5791fa23a5984f0ddeacd8a6d58593d7ed2168b65f28097eb97

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-0.2.2-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 50dc541582347b7d8abe91f965b4f7d63f5ee5db94f66244de7ff08cb6f68642
MD5 e3fffd24d19a11d6d20900225e684825
BLAKE2b-256 b854f9286784dee4ced4b0ca1470ed1ea26806dc9c76f74b83548526afb99403

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ayafileio-0.2.2-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 78.8 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.2.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 c252205afb7e4a16eba4527744716f469bce14baba1399f211e559bce4c0ded4
MD5 b739c990a9f6c7d3b812f035fa2841bd
BLAKE2b-256 59b4f7584c1e924ea289eb3b7a4eea8fea23afeda0cecb21f5e24adecbc2df8b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-0.2.2-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5d34b19c3c846bd6f20858f9270fa18eeddb5d6d8a76961a474626ddad058b17
MD5 0c705ebcd522e47c85548bbe13ce41c4
BLAKE2b-256 d899941a9d56b719bde2ea2ae4900a68299d5fd90172323316c8f42836371253

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-0.2.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 89fe31289354a582027c9dba990025fcb98120065877027bfa03b114823c09b4
MD5 f137e974f061761669224165ffc6bf2a
BLAKE2b-256 90255a0610a98e05c9e52f3b7cb3086402913f03be97aff000756c8915288baf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-0.2.2-cp312-cp312-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 fa447058b99fb9935548bc76066509c57211096e99b788d28079bd65566082a7
MD5 dc4bfb8ce912f1564514e514d17b220b
BLAKE2b-256 88cc34514dc66fea882a8a7c964d821372d199dfa3664191a44373cff2adcefe

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ayafileio-0.2.2-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 79.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.2.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 00ecb1488a545aa24769b8922433aa12034bd5e4c531977f6db171f211a56407
MD5 8d2c8f3fb9f45ea479af702231041dce
BLAKE2b-256 d5aade8fc4f546c16f241a21347374e1f7bcc547ef2de6271ae0102ec733c190

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-0.2.2-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 6dd6b35f20d687afbaba4cce6c1b99194a50920495ad8c44a7c8d96e34367ae8
MD5 54b9bf6962bf5c44a4f907440b98624c
BLAKE2b-256 cdea8ac844d0ea6a5101e42c265dde728ab179cd04240191493c6acb20f64cc1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-0.2.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c1ac6ed16a5cd82e9858a4134b43432a2794525c36cf0a8c759e7903c48afa10
MD5 fc30ccc27772c10f01d0c4d2d32f98e5
BLAKE2b-256 a96c810524a8fcd25d2afa1d268bb18caec95fc8a3ea3c9d4fbc4606964e6926

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-0.2.2-cp311-cp311-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 9b7cae99a0e68445c6d7577028497fe4ca14ab304242e26ede746690c095010b
MD5 969aec8da8faa2f0fa15ab2fca64889d
BLAKE2b-256 4223bf1d1d3f8e05ac33a6d9eeedd41df0fed9c4bf0794914060149423eded26

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ayafileio-0.2.2-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 80.0 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.2.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 b77b389655dbcaf2c4b9db90e190b139e4afa3f426d1f04994c98bfd3d3a9c51
MD5 7a7ecd29df4d7fdc22650d5955bf37c7
BLAKE2b-256 6ba498c4af8b71d72c47261ae510c0783912729540035da46842df8e1b9a2c7f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-0.2.2-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 df33f463e8cf3bfda639d806830e2fe8aa67c0ca0087f14b4a092fd0f9a16567
MD5 546cc631c2e476330091446f308d5559
BLAKE2b-256 f789a11998a436be1e38f13530a6d3ff06d8e1bebae02b3a3d83c30907e3c124

See more details on using hashes here.

File details

Details for the file ayafileio-0.2.2-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for ayafileio-0.2.2-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 139dd4aae737ae3df576b8be68e198d1119d9957643f8259d2ddabae7c1298ee
MD5 792b8d2b946b0c9c5a28985d81e38158
BLAKE2b-256 3b8596f913490d3a27d529d56bcaf94241bf31afe0a0aa5ec65cd5bb1bc46754

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ayafileio-0.2.2-cp310-cp310-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 8871d3bfe418aff21dd6f84e51196b2c9054cf6a5b9d16841555a73e9273cc7b
MD5 53319f449d5292012ecd797feac943a3
BLAKE2b-256 942d8dd4b7d0caae44c33d438993a2e9b8dd431ee39a030f45a817377d15dda3

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