Skip to main content
Help us improve PyPI by participating in user testing. All experience levels needed!

Asynchronous file operations.

Project description

Travis CI Latest Version

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


Release history Release notifications

This version
History Node

1.4.0

History Node

1.3.0

History Node

1.2.6

History Node

1.2.5

History Node

1.2.2

History Node

1.2.1

History Node

1.2.0

History Node

0.5.3

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
aiofile-1.4.0-cp34-cp34m-macosx_10_6_intel.whl (95.7 kB) Copy SHA256 hash SHA256 Wheel cp34 Jun 20, 2018
aiofile-1.4.0-cp34-cp34m-manylinux1_x86_64.whl (186.5 kB) Copy SHA256 hash SHA256 Wheel cp34 Jun 20, 2018
aiofile-1.4.0-cp35-cp35m-macosx_10_6_intel.whl (95.4 kB) Copy SHA256 hash SHA256 Wheel cp35 Jun 20, 2018
aiofile-1.4.0-cp35-cp35m-manylinux1_x86_64.whl (182.4 kB) Copy SHA256 hash SHA256 Wheel cp35 Jun 20, 2018
aiofile-1.4.0-cp36-cp36m-macosx_10_6_intel.whl (96.4 kB) Copy SHA256 hash SHA256 Wheel cp36 Jun 20, 2018
aiofile-1.4.0-cp36-cp36m-manylinux1_x86_64.whl (180.5 kB) Copy SHA256 hash SHA256 Wheel cp36 Jun 20, 2018
aiofile-1.4.0.tar.gz (75.0 kB) Copy SHA256 hash SHA256 Source None Jun 20, 2018

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page