Skip to main content

High-Performance Asynchronous File I/O for Python, powered by Rust

Project description

aerofs: High-Performance Asynchronous File I/O for Python

PyPI Build Python Versions License

aerofs is an Apache 2.0 licensed library for handling local disk files in asyncio applications, written in Rust and powered by PyO3 and Tokio for maximum performance.

Ordinary local file I/O is blocking and cannot easily be made asynchronous. This means doing file I/O may interfere with asyncio applications, which shouldn't block the executing thread. aerofs solves this by providing asynchronous file operations with superior performance compared to pure Python alternatives like aiofiles.

import aerofs

async with aerofs.open('filename', mode='r') as f:
    contents = await f.read()
print(contents)

Asynchronous iteration is also supported:

async with aerofs.open('filename') as f:
    async for line in f:
        print(line)

Asynchronous interface to tempfile module:

async with aerofs.tempfile.TemporaryFile('wb') as f:
    await f.write(b'Hello, World!')

Installation

To install aerofs, simply:

uv pip install aerofs

Note: Currently supports Linux only. macOS and Windows support is planned.

Usage

Basic File Operations

Files are opened using the aerofs.open() coroutine, which mirrors Python's builtin open():

import aerofs

async def read_file():
    async with aerofs.open('example.txt', 'r') as f:
        content = await f.read()
        return content

async def write_file():
    async with aerofs.open('example.txt', 'w') as f:
        await f.write('Hello, World!')

The following methods are async and available on file objects:

  • close
  • flush
  • isatty
  • read
  • readall
  • read1
  • readinto
  • readline
  • readlines
  • seek
  • seekable
  • tell
  • truncate
  • writable
  • write
  • writelines

Standard I/O

Async access to standard streams:

import aerofs

async def read_stdin():
    async for line in aerofs.stdin:
        print(f"You typed: {line}")

async def write_stdout():
    await aerofs.stdout.write("Hello from async stdout!\n")
    await aerofs.stdout.flush()

Available streams:

  • aerofs.stdin, aerofs.stdout, aerofs.stderr
  • aerofs.stdin_bytes, aerofs.stdout_bytes, aerofs.stderr_bytes

OS Operations

The aerofs.os module contains async versions of useful os functions:

import aerofs.os

async def os_operations():
    # Check if file exists
    exists = await aerofs.os.path.exists('myfile.txt')
    
    # List directory
    files = await aerofs.os.listdir('.')
    
    # Get file stats
    stats = await aerofs.os.stat('myfile.txt')
    
    # File operations
    await aerofs.os.rename('old.txt', 'new.txt')
    await aerofs.os.remove('unwanted.txt')
    await aerofs.os.mkdir('newdir')

Available operations:

  • stat, statvfs, sendfile
  • rename, renames, replace, remove, unlink
  • mkdir, makedirs, rmdir, removedirs
  • link, symlink, readlink
  • listdir, scandir, access, getcwd
  • path.abspath, path.exists, path.isfile, path.isdir
  • path.islink, path.ismount, path.getsize
  • path.getatime, path.getctime, path.samefile, path.sameopenfile

Tempfile

aerofs.tempfile implements async interfaces for temporary files:

import aerofs.tempfile
import os

async def use_tempfile():
    # Named temporary file
    async with aerofs.tempfile.NamedTemporaryFile('wb+') as f:
        await f.write(b'Line1\nLine2')
        await f.seek(0)
        async for line in f:
            print(line)
    
    # Temporary directory
    async with aerofs.tempfile.TemporaryDirectory() as d:
        filename = os.path.join(d, "file.ext")
        async with aerofs.open(filename, 'w') as f:
            await f.write("temporary data")

Available interfaces:

  • TemporaryFile
  • NamedTemporaryFile
  • SpooledTemporaryFile
  • TemporaryDirectory

Performance

aerofs is built with Rust and Tokio, providing significant performance improvements over pure Python async file I/O libraries. Benchmarks show substantial speed improvements for common file operations.

Requirements

  • Python 3.9 or higher
  • Linux only (macOS and Windows support coming soon - see issue)

Contributing

Contributions are very welcome! Please feel free to submit a Pull Request.

Development Setup

  1. Clone the repository:
git clone https://github.com/ohmyarthur/aerofs.git
cd aerofs
  1. Install development dependencies:
uv pip install -e ".[dev]"
  1. Run tests:
pytest

Building from Source

# Install maturin
uv pip install maturin

# Build the package
maturin develop

# Or build a wheel
maturin build --release

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Acknowledgments

Inspired by aiofiles, but built from the ground up with Rust .

Project details


Download files

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

Source Distribution

aerofs-0.2.0.tar.gz (37.7 kB view details)

Uploaded Source

Built Distribution

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

aerofs-0.2.0-cp39-abi3-manylinux_2_34_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.34+ x86-64

File details

Details for the file aerofs-0.2.0.tar.gz.

File metadata

  • Download URL: aerofs-0.2.0.tar.gz
  • Upload date:
  • Size: 37.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for aerofs-0.2.0.tar.gz
Algorithm Hash digest
SHA256 9b7d2d29791283c83ef19aa4c4a2d732d86322773b4e2a00d5a3286476d8f465
MD5 6738f346fd12f8d8ccee64590b0a434c
BLAKE2b-256 c5b616dc5cabfa0927501a2c24c2845152acbb2c05568abc394eb92c0a4a61f1

See more details on using hashes here.

Provenance

The following attestation bundles were made for aerofs-0.2.0.tar.gz:

Publisher: main.yml on ohmyarthur/aerofs

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

File details

Details for the file aerofs-0.2.0-cp39-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for aerofs-0.2.0-cp39-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 961f5675dcb32d4b964918e18617eaf100e5fa7e47c172e09b3459ab4749105d
MD5 1a07f55e6f1466954945c95a64964ace
BLAKE2b-256 1c03f686f65524d4b830120dba5e17810d3cfbb860162b2c8a6810e88e1ce905

See more details on using hashes here.

Provenance

The following attestation bundles were made for aerofs-0.2.0-cp39-abi3-manylinux_2_34_x86_64.whl:

Publisher: main.yml on ohmyarthur/aerofs

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

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