aiomegfile is asyncio implementation of megfile.
- fs(local filesystem)
- s3
Support more in the future.
pip3 install aiomegfileSmart methods and SmartPath are the same as megfile, but all methods are async. You can use aiomegfile to do file operations in an async way.
import asyncio
from aiomegfile import smart_open
async def main():
async with smart_open('s3://bucket/key', 'r') as f:
content = await f.read()
print(content)
if __name__ == '__main__':
asyncio.run(main())SmartPath has a similar interface with pathlib.Path, but async.
import asyncio
from aiomegfile import SmartPath
async def main():
path = SmartPath('s3://bucket/key')
content = await path.read_text()
print(content)
if __name__ == '__main__':
asyncio.run(main())Smart methods and SmartPath are the same as megfile, but all methods are async. You can use aiomegfile to do file operations in an async way.
import asyncio
from aiomegfile import smart_open
async def main():
async with smart_open('s3://bucket/key', 'r') as f:
content = await f.read()
print(content)
if __name__ == '__main__':
asyncio.run(main())SmartPath has a similar interface with pathlib.Path, but async.
import asyncio
from aiomegfile import SmartPath
async def main():
path = SmartPath('s3://bucket/key')
content = await path.read_text()
print(content)
if __name__ == '__main__':
asyncio.run(main())Install the CLI extras:
pip3 install "aiomegfile[cli]"Example usage:
amf ls ./data
amf ls s3://bucket/prefix -l
amf cp -r ./data s3://bucket/backup
amf sync ./data s3://bucket/backup --progress-barFor a wider protocol matrix and advanced configuration, see the megfile docs:
http://megvii-research.github.io/megfile
-
We welcome everyone to contribute code to the
aiomegfileproject, but the contributed code needs to meet the following conditions as much as possible: You can submit code even if the code doesn't meet conditions. The project members will evaluate and assist you in making code changes- Code format: Your code needs to pass code format check.
aiomegfileusesruffas lint tool - Static check: Your code needs complete type hint.
aiomegfileusespytypeas static check tool. Ifpytypefailed in static check, use# pytype: disable=XXXto disable the error and please tell us why you disable it. - Test: Your code needs complete unit test coverage.
aiomegfileusespyfakefsandmotoas local file system and s3 virtual environment in unit tests. The newly added code should have a complete unit test to ensure the correctness
- Code format: Your code needs to pass code format check.
-
You can help to improve
aiomegfilein many ways:- Write code.
- Improve documentation.
- Report or investigate bugs and issues.
- If you find any problem or have any improving suggestion, submit a new issue as well. We will reply as soon as possible and evaluate whether to adopt.
- Review pull requests.
- Star
aiomegfilerepo. - Recommend
aiomegfileto your friends. - Any other form of contribution is welcomed.