Skip to main content

Make every Python function async/await

Project description

aioify (maintenance mode)

Authors of aioify and module-wrapper decided to discontinue support of these libraries since the idea: "let's convert sync libraries to async ones" works only for some cases. Existing releases of libraries won't be removed, but don't expect any changes since today. Feel free to fork these libraries, however, we don't recommend using the automatic sync-to-async library conversion approach, as unreliable. Instead, it's better to run synchronous functions asynchronously using https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.loop.run_in_executor or https://anyio.readthedocs.io/en/stable/api.html#running-code-in-worker-threads.

Old documentation

Make every function async and await-able.

Usage

pip install aioify

For example, make os, shutil and user defined function await-able.

#!/usr/bin/env python
###########
# Warning #
###########
# This code should be executed only on POSIX OS with at least 1 GiB free space in /tmp/ directory and RAM!

from aioify import aioify
import os
import shutil


def generate_big_file(filename, file_size):
    with open(file=filename, mode='wb') as f:
        f.write(os.urandom(file_size))


aiogenerate_big_file = aioify(obj=generate_big_file)
aios = aioify(obj=os, name='aios')
aioshutil = aioify(obj=shutil, name='aishutil')


async def main():
    dir_path = '/tmp/big-files/'
    await aios.makedirs(name=dir_path, exist_ok=True)
    filename = os.path.join(dir_path, 'original')
    copy_filename = os.path.join(dir_path, 'copy')
    file_size = 1024 * 1024 * 1024
    await aiogenerate_big_file(filename=filename, file_size=file_size)
    await aioshutil.copy(src=filename, dst=copy_filename)
    await aioshutil.rmtree(path=dir_path)


if __name__ == '__main__':
    import asyncio as aio
    loop = aio.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

aioify-0.4.1.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aioify-0.4.1-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file aioify-0.4.1.tar.gz.

File metadata

  • Download URL: aioify-0.4.1.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.8.13 Linux/5.16.15-1-default

File hashes

Hashes for aioify-0.4.1.tar.gz
Algorithm Hash digest
SHA256 433b869662108649f8c263694c12cb93bc80d2d9ba715f17b0f03017aa56c721
MD5 bfb8d39c6c23eb346d6a8d49a66a574d
BLAKE2b-256 d57d406950e7ad66518372baa1e44921791266f700ab9cea88e76917488c6ceb

See more details on using hashes here.

File details

Details for the file aioify-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: aioify-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.8.13 Linux/5.16.15-1-default

File hashes

Hashes for aioify-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fd862a4a936608336d36e81aeca6219414cef1a7a383831c6d8863102ff3b323
MD5 4e23fd798b8006cd0500f14d161bba72
BLAKE2b-256 bb4a6daf82516a579ba9be029469acfb46e567a743a30218118383f90194d281

See more details on using hashes here.

Supported by

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