Skip to main content

A python utility for running async functions.

Project description

asyncr

PyPI PyPI - Downloads

asyncr is a Python library for helping you handle those pesky async functions with ease! With asyncr you can easily run your async functions in a synchronous way or run your synchronous functions in an async way.

[!IMPORTANT] This library simply runs the functions is the event loop without changing the function code or optimizing it. If your code is not async safe, it may not work as expected.

Installation

Use the package manager pip to install asyncr.

pip install asyncr

Usage

from asyncio import get_event_loop

from asyncr import as_sync, as_async


# Create a new async function and wrap it with as_sync, now it will be a sync function.
@as_sync
async def async_function():
    return "Hello, Sync World!"


print(async_function())


# Create a new sync function and wrap it with as_async, now it will be an async function.
@as_async
def sync_function():
    return "Hello, Async World!"


print(get_event_loop().run_until_complete(sync_function()))

You can also pass a the loop for running the functions as the parameter for the decorator. If no loop is provided, the default loop will be used.

from asyncio import get_event_loop, new_event_loop

from asyncr import as_sync, as_async


# Create a new async function and wrap it with as_sync, now it will be a sync function.
@as_sync(new_event_loop())
async def async_function():
    return "Hello, Sync World!"

print(async_function())

Contributing

Please open an issue first to discuss what you would like to change. I welcome any and all criticism, feedback, and suggestions even if I may not agree.

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

asyncr-0.1.0.tar.gz (7.3 kB view hashes)

Uploaded Source

Built Distribution

asyncr-0.1.0-py3-none-any.whl (6.6 kB view hashes)

Uploaded Python 3

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