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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file asyncr-0.1.0.tar.gz.

File metadata

  • Download URL: asyncr-0.1.0.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.7

File hashes

Hashes for asyncr-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ba574de42bafefa5b0d9113a7e976e799288cf7cc06c48c7472264030b68756e
MD5 52d08d35026b267dbbad1c21850647a6
BLAKE2b-256 37927843222e56322df85c244cf7845a131321421ef60c09caf26891e2ef3e40

See more details on using hashes here.

File details

Details for the file asyncr-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: asyncr-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.7

File hashes

Hashes for asyncr-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dca1f698c678fb17d0f2cdfd4e37780c55fa4f1bbba490fda2e12eef216fb9a4
MD5 55be3f20cbf2f260219a2a990bcd50d6
BLAKE2b-256 9369cc01149e7ebd9576cc0d1f09f4a09b66a9e596b30ac1bd6f6c116dfb4538

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