Skip to main content
Help us improve Python packaging – donate today!

Async wrappers for standard Python io streams.

Project Description


*Async wrappers for standard Python io streams.*

Example Usage

For simple use cases this package provides the same high level utilities as
the Python `io` module:

.. code-block:: python

import apyio

string_buff = apyio.StringIO()
bytes_buff = apyio.BytesIO()
file_handle ='somefile.txt', 'r')

The `write`, `writelines`, and `close` methods are left as normal functions
just as they are for the asyncio streams. However, any function which might
result in a read operation, such as `read`, `readline`, `readlines`, `read1`,
`seek`, `tell`, and `truncate`, are now `async def` functions that must be

.. code-block:: python

import apyio

async with'somefile.txt', 'w') as file_handle:

file_handle.write('some data')
await file_handle.drain() # Same as flush().

async with'somefile.txt', 'r') as file_handle:

data = await

file_handle ='somefile.txt', 'r')
async for line in file_handle:


For more advanced use cases, this package also contains async wrappers for all
classes defined in the Python `io` module. The wrappers are named using the
pattern `Async<>Wrapper`. For example, `BufferedReader` becomes
`AsyncBufferedReaderWrapper` and `FileIO` becomes `AsyncFileIOWrapper`. All
wrapper classes accept one argument in the constructor which must be the
original, synchronous stream.

.. code-block:: python

import io
import apyio

sync_stream = io.FileIO('somefile.txt', 'r')
async_stream = apyio.AsyncFileIOWrapper(sync_stream)
print((await async_stream.readline()))

If a file was opened using the built-in `open()` function it may not be an
instance of `io.FileIO`. Depending on the options given to `open()` different
kinds of streams may be returned. To help with wrapping arbitrary `open()`
return values use the `apyio.wrap_file()` helper.

.. code-block:: python

import apyio
file_handle = open('somefile.bin', 'r+b')
async_handle = apyio.wrap_file(file_handle)


All tests are stored in the '/tests' subdirectory. All tests are expected to
pass for Python 3.5 and above. To run tests create a virtualenv and install
the test-requirements.txt list. After that using the `tox` command will launch
the test suite.


Copyright 2015 Kevin Conway

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
See the License for the specific language governing permissions and
limitations under the License.


Firstly, if you're putting in a patch then thank you! Here are some tips for
getting your patch merged:


As long as the code passes the PEP8 and PyFlakes gates then the style is


The PEP257 gate will check that all public methods have docstrings. If you're
adding additional wrappers from the `io` module try to preserve the original
docstrings if possible. If you're adding something new, like a helper function,
try out the
`napoleon style of docstrings <>`_.


Make sure the patch passes all the tests. If you're adding a new feature don't
forget to throw in a test or two. If you're fixing a bug then definitely add
at least one test to prevent regressions.

Release history Release notifications

This version
History Node


History Node


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
apyio-0.2.0.tar.gz (14.4 kB) Copy SHA256 hash SHA256 Source None Oct 18, 2015

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