Skip to main content

aiofilepool

Async file-descriptor pool for Python. FilePool caps how many OS file descriptors are open at once, while your code can freely hold thousands of logical async file handles.

  • Async-native - built on asyncio; blocking I/O is offloaded to a thread pool.
  • Chunked I/O - large reads/writes split via pluggable chunkers; you can open streams with chunks().
  • Zero dependencies - pure standard library.

Install

pip install aiofilepool
# or
uv add aiofilepool

Requires Python 3.12+.

Usage

import asyncio
from aiofilepool import FilePool


async def main():
    # at most 128 real OS fds open at once
    async with FilePool(descriptor_pool_size=128) as pool:
        handle = await pool.open("data.bin", "w+")
        await handle.write(b"hello world")
        await handle.seek(0)
        print(await handle.read())  # b"hello world"
        await handle.fsync()

        # handles auto-close on exit from pool. Also you can do this manually:
        await handle.close()

        # or with a manager:
        async with pool.open("data.bin", "w+") as fd:
            ...


asyncio.run(main())

It bounds only the real fds and manages temporary closing and re-opening them, so this is completely fine:

async with FilePool(descriptor_pool_size=64) as pool:
    handles = [await pool.open(f"part-{i}.bin", "w+") for i in range(1000)]
    await asyncio.gather(*(h.write(payload) for h in handles))

Also you can read a large file in chunks:

handle = await pool.open("big.bin", "r")
async for chunk in handle.chunks():
    process(chunk)

Although, the handle.read uses chunking too, so chunks are there just for convenience

API

  • FilePool - the pool: open(path, mode), manage(binary_io), close(), and an async context manager.
  • FileHandle - an async file handle: read, write, seek, tell, size etc. A handler you use to talk to a file.
  • AsyncBinaryIO - the async binary-IO protocol FileHandle implements.
  • BinaryIOAdapter - allows to wrap an existing synchronous BinaryIO as an AsyncBinaryIO.
  • ModeSpec - a parsed file open-mode.
  • Chunker, FixedChunker, BalancedChunker - chunking strategies. You can use them with AsyncBinaryIO.chunks or as a default for the FilePool.
  • aiofilepool.errors - the exception hierarchy.

License

MIT — see LICENSE.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiofilepool-0.1.0.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aiofilepool-0.1.0-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file aiofilepool-0.1.0.tar.gz.

File metadata

  • Download URL: aiofilepool-0.1.0.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for aiofilepool-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5530a5d13461d17d5d23404e53c743d66467412e31b66efc7b491a2bf0c3d987
MD5 044c759aef1faf879a25b164b453a15b
BLAKE2b-256 4ec12c95940c8c403055358b6f42f53c4fa8cf90dad51b3fe9c447793c30701e

See more details on using hashes here.

Provenance

The following attestation bundles were made for aiofilepool-0.1.0.tar.gz:

Publisher: release.yml on MiloLug/aiofilepool

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file aiofilepool-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: aiofilepool-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for aiofilepool-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dac56765ff57c86de1c00a864789ee116fc8b9e40c5d7b97a423eb82f3d08595
MD5 b5071df1ce277625c78eccc4f473c36c
BLAKE2b-256 0d531decffde6e18d4edfc53194cfbda0b8798ba295d2d779f296ce015fe7b4d

See more details on using hashes here.

Provenance

The following attestation bundles were made for aiofilepool-0.1.0-py3-none-any.whl:

Publisher: release.yml on MiloLug/aiofilepool

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page