High-Performance Asynchronous File I/O for Python, powered by Rust
Project description
aerofs: High-Performance Asynchronous File I/O for Python
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:
closeflushisattyreadreadallread1readintoreadlinereadlinesseekseekabletelltruncatewritablewritewritelines
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.stderraerofs.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,sendfilerename,renames,replace,remove,unlinkmkdir,makedirs,rmdir,removedirslink,symlink,readlinklistdir,scandir,access,getcwdpath.abspath,path.exists,path.isfile,path.isdirpath.islink,path.ismount,path.getsizepath.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:
TemporaryFileNamedTemporaryFileSpooledTemporaryFileTemporaryDirectory
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
- Clone the repository:
git clone https://github.com/ohmyarthur/aerofs.git
cd aerofs
- Install development dependencies:
uv pip install -e ".[dev]"
- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aerofs-0.3.0.tar.gz.
File metadata
- Download URL: aerofs-0.3.0.tar.gz
- Upload date:
- Size: 37.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ef215fdef61eb6032cf2eceac35100417a40b0a9f0386073609574ef89f06a45
|
|
| MD5 |
c1631cdec234f3a6ad4f278f7a4d2b5c
|
|
| BLAKE2b-256 |
46c20992b7890e84956a3e23c28cb926c69d292d67cff9e49a6d0d317469e8ad
|
Provenance
The following attestation bundles were made for aerofs-0.3.0.tar.gz:
Publisher:
main.yml on ohmyarthur/aerofs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aerofs-0.3.0.tar.gz -
Subject digest:
ef215fdef61eb6032cf2eceac35100417a40b0a9f0386073609574ef89f06a45 - Sigstore transparency entry: 726795865
- Sigstore integration time:
-
Permalink:
ohmyarthur/aerofs@f10d8c5f945c9d20d34349cca4fc3efd115797f0 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/ohmyarthur
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
main.yml@f10d8c5f945c9d20d34349cca4fc3efd115797f0 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file aerofs-0.3.0-cp39-abi3-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: aerofs-0.3.0-cp39-abi3-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 1.0 MB
- Tags: CPython 3.9+, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2f21d5824c6b3dff24adea6ccb80d59149e6513e77b8c94653b0e5fd2fb67812
|
|
| MD5 |
35f1dcaf011d88ba5f39e8b0bcc6e465
|
|
| BLAKE2b-256 |
08c2e224b15cd2a00e40bcbeea9ea66c97dc2d4274119df0fa793ea3f1d4ea43
|
Provenance
The following attestation bundles were made for aerofs-0.3.0-cp39-abi3-manylinux_2_34_x86_64.whl:
Publisher:
main.yml on ohmyarthur/aerofs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aerofs-0.3.0-cp39-abi3-manylinux_2_34_x86_64.whl -
Subject digest:
2f21d5824c6b3dff24adea6ccb80d59149e6513e77b8c94653b0e5fd2fb67812 - Sigstore transparency entry: 726795869
- Sigstore integration time:
-
Permalink:
ohmyarthur/aerofs@f10d8c5f945c9d20d34349cca4fc3efd115797f0 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/ohmyarthur
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
main.yml@f10d8c5f945c9d20d34349cca4fc3efd115797f0 -
Trigger Event:
workflow_dispatch
-
Statement type: