Skip to main content

Asynchronous file operations.

Project description

Travis CI Latest Version https://img.shields.io/pypi/wheel/aiofile.svg https://img.shields.io/pypi/pyversions/aiofile.svg https://img.shields.io/pypi/l/aiofile.svg

Real asynchronous file operations with asyncio support.

Status

Development - Stable

Features

  • AIOFile has no internal pointer. You should pass offset and chunk_size for each operation or use helpers (Reader or Writer).

  • For POSIX (MacOS X and Linux) using implementaion based on aio.h (with Cython).

  • For non-POSIX systems using thread-based implementation

Code examples

All code examples requires python 3.5+.

Write and Read

import asyncio
from aiofile import AIOFile, Reader, Writer


async def main():
    async with AIOFile("/tmp/hello.txt", 'w+') as afp:
        await afp.write("Hello ")
        await afp.write("world", offset=7)
        await afp.fsync()

        print(await afp.read())


loop = asyncio.get_event_loop()
loop.run_until_complete(main())

Write and read with helpers

import asyncio
from aiofile import AIOFile, Reader, Writer


async def main():
    async with AIOFile("/tmp/hello.txt", 'w+') as afp
        writer = Writer(afp)
        reader = Reader(afp, chunk_size=8)

        await writer("Hello")
        await writer(" ")
        await writer("World")
        await afp.flush()

        async for chunk in reader:
            print(chunk)


loop = asyncio.get_event_loop()
loop.run_until_complete(main())

Read file line by line

import asyncio
from aiofile import AIOFile, LineReader, Writer


async def main():
    async with AIOFile("/tmp/hello.txt", 'w+') as afp
        writer = Writer(afp)

        await writer("Hello")
        await writer(" ")
        await writer("World")
        await writer("\n")
        await writer("\n")
        await writer("From async world")
        await afp.flush()

        async for line in LineReader(afp):
            print(line)


loop = asyncio.get_event_loop()
loop.run_until_complete(main())

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

aiofile-1.2.5.tar.gz (75.4 kB view details)

Uploaded Source

Built Distributions

aiofile-1.2.5-cp36-cp36m-manylinux1_x86_64.whl (183.9 kB view details)

Uploaded CPython 3.6m

aiofile-1.2.5-cp36-cp36m-macosx_10_6_intel.whl (97.9 kB view details)

Uploaded CPython 3.6m macOS 10.6+ intel

aiofile-1.2.5-cp35-cp35m-manylinux1_x86_64.whl (184.5 kB view details)

Uploaded CPython 3.5m

aiofile-1.2.5-cp35-cp35m-macosx_10_6_intel.whl (96.7 kB view details)

Uploaded CPython 3.5m macOS 10.6+ intel

aiofile-1.2.5-cp34-cp34m-manylinux1_x86_64.whl (189.7 kB view details)

Uploaded CPython 3.4m

aiofile-1.2.5-cp34-cp34m-macosx_10_6_intel.whl (97.1 kB view details)

Uploaded CPython 3.4m macOS 10.6+ intel

File details

Details for the file aiofile-1.2.5.tar.gz.

File metadata

  • Download URL: aiofile-1.2.5.tar.gz
  • Upload date:
  • Size: 75.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for aiofile-1.2.5.tar.gz
Algorithm Hash digest
SHA256 854ba84fedbdb56cdc5d552d269435ee8b90ac02fabb7dfb48a9d09b6df11667
MD5 beccb95b33495a805f1db1e63e9f576d
BLAKE2b-256 22e28a5867f67b3e3d56164f68286cb5db9a2cd955f6ed0b172dfeedab4ce959

See more details on using hashes here.

File details

Details for the file aiofile-1.2.5-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for aiofile-1.2.5-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 b4a9f91efee1a5588fc1e8a31706d34ebfc2d7cbc29eb47d184505da952d0e36
MD5 09572286de66036439a9f366f026cd96
BLAKE2b-256 59cd6efc8807b292718deae7a90a0079c866be0f2a98fa097fc671e339350a71

See more details on using hashes here.

File details

Details for the file aiofile-1.2.5-cp36-cp36m-macosx_10_6_intel.whl.

File metadata

File hashes

Hashes for aiofile-1.2.5-cp36-cp36m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 f02412b6317d3f39adb4d65a0a1cf9937b92e675063de21c2bfc9f245b5814a5
MD5 d5a1bf705e500c706ddd8a87b1158560
BLAKE2b-256 c13e0edda1662b9170131dad09355e17b9997df5870dcc6c27a1d705b088aa13

See more details on using hashes here.

File details

Details for the file aiofile-1.2.5-cp35-cp35m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for aiofile-1.2.5-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 cfadcd3fc117e87f7038420feb08bd51fead4c46f897f379a50df1690f7d05ec
MD5 f812e129d56739c6498e942cb31d50ae
BLAKE2b-256 39471c82b16d8cb8350f9f942f7081c580bb992646574c17759ff7644a34e35e

See more details on using hashes here.

File details

Details for the file aiofile-1.2.5-cp35-cp35m-macosx_10_6_intel.whl.

File metadata

File hashes

Hashes for aiofile-1.2.5-cp35-cp35m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 c1c3b76fb4fece1742297ba1764f82701ef965a07c024d7e4837a9e669475b18
MD5 7927a3446c3688fc2f5cfc6de2807aa1
BLAKE2b-256 1ba39b52c19b625b8193b997abcea7e335915c3c03b9bf4648f87b79479692f1

See more details on using hashes here.

File details

Details for the file aiofile-1.2.5-cp34-cp34m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for aiofile-1.2.5-cp34-cp34m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 3317c957cf401305a1b2065a6c5389978ab4c9e2c1e2936a539510ac908aaf7e
MD5 c1a60570ed7a83dcf9c312b046309936
BLAKE2b-256 fb9b4e9fadf0e747e9b5c2ba77f62f7a13a0e0e6f43820ee892502fd93168ea3

See more details on using hashes here.

File details

Details for the file aiofile-1.2.5-cp34-cp34m-macosx_10_6_intel.whl.

File metadata

File hashes

Hashes for aiofile-1.2.5-cp34-cp34m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 71a0075767c64168b433af1566a1d62ce23e58fd47e4174c1082b2378ea06ee1
MD5 5d21cdbcafcbd4137e915a95aba3a03a
BLAKE2b-256 8d0f5fac336220315580d44d23bca8904fe36496939a98020fc675dff136d720

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page