Asyncio implementation of megfile
Project description
aiomegfile - Asyncio implementation of megfile
aiomegfile brings the megfile programming model to asyncio applications.
It provides:
- Async smart functions such as
smart_open,smart_copy, andsmart_sync - An async
SmartPathabstraction with apathlib-style interface - A CLI named
amffor listing, copying, syncing, streaming, and inspecting files
The public API mirrors megfile where possible, but operations are async-first.
Supported Protocols
Current backends in this repository include:
- Local filesystem with plain paths or
file:// s3://http://andhttps://for async read-oriented accesssftp://stdio://for stdin/stdout/stderr bridginghdfs://with thehdfsextrawebdav://andwebdavs://with thewebdavextra
Installation
Install the core package:
pip install aiomegfile
Install optional extras when you need them:
pip install "aiomegfile[cli]"
pip install "aiomegfile[hdfs]"
pip install "aiomegfile[webdav]"
Quick Start
Functional API
import asyncio
from aiomegfile import smart_exists, smart_open
async def main() -> None:
async with smart_open("/tmp/aiomegfile-demo.txt", "w") as writer:
await writer.write("hello from aiomegfile\n")
async with smart_open("/tmp/aiomegfile-demo.txt", "r") as reader:
content = await reader.read()
print(content.strip())
print(await smart_exists("/tmp/aiomegfile-demo.txt"))
if __name__ == "__main__":
asyncio.run(main())
SmartPath
import asyncio
from aiomegfile import SmartPath
async def main() -> None:
root = SmartPath("s3://example-bucket/demo")
file_path = root / "message.txt"
await file_path.write_text("hello from SmartPath\n")
print(await file_path.read_text())
async for child in root.iterdir():
print(await child.as_uri())
if __name__ == "__main__":
asyncio.run(main())
Syncing Data
import asyncio
from aiomegfile import smart_sync
async def main() -> None:
await smart_sync("./data", "s3://example-bucket/backup")
if __name__ == "__main__":
asyncio.run(main())
CLI
Install the CLI extra first:
pip install "aiomegfile[cli]"
Common commands:
amf ls ./data
amf ls s3://my-bucket/prefix -l
amf cp -r ./data s3://my-bucket/archive
amf sync ./data s3://my-bucket/archive --progress-bar
amf cat https://example.com/data.txt
printf 'payload' | amf to s3://my-bucket/stdin-demo.txt
Shell completion can be enabled with:
amf completion bash
amf completion zsh
amf completion fish
Configuration
Runtime configuration is loaded from ~/.config/megfile/megfile.conf.
The file supports at least two useful sections:
[env]for environment variables loaded during import[alias]for custom protocol aliases
Example:
[env]
MEGFILE_MAX_WORKERS = 16
MEGFILE_READER_BLOCK_SIZE = 16MB
MEGFILE_HTTP_MAX_RETRY_TIMES = 6
[alias]
datasets = s3://company-datasets/
public = https://static.example.com/
With the alias above, datasets://images/cat.jpg resolves to
s3://company-datasets/images/cat.jpg.
The CLI also provides helpers for common configuration tasks:
amf config s3 <access_key> <secret_key> --profile-name default
amf config hdfs http://namenode:9870 --profile-name prod
amf config alias datasets s3://company-datasets/
amf config env MEGFILE_MAX_WORKERS=16
Documentation
The full documentation site includes installation notes, protocol details, CLI reference, and API reference:
https://megvii-research.github.io/aiomegfile
How to Contribute
We welcome contributions in code, tests, and documentation.
- Run lint checks with
ruff - Keep type hints complete
- Add or update tests for behavior changes
- Improve docs when public behavior changes
Issues and pull requests are welcome:
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
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 aiomegfile-0.0.3-py3-none-any.whl.
File metadata
- Download URL: aiomegfile-0.0.3-py3-none-any.whl
- Upload date:
- Size: 167.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3cb24814b353edf147e017ef6b67aa3e0e19c345dbaea0e4afdc27a9995a3872
|
|
| MD5 |
8465d7cbacd9c82eb5ac65fea4225d42
|
|
| BLAKE2b-256 |
7c2bf0feaa77e85db7da2b17f8f60aeef1bba3e0ee2d551a4bb25d3f2a945146
|