A class or decorator to help with asynchronous programming in Python within synchronous contexts.
Project description
Asynchronizer
This repository contains a Python decorator and class that allow you to run asynchronous code from a synchronous context. This can be particularly useful when you need to perform IO-bound tasks such as making HTTP requests, reading from or writing to a database, or interacting with the file system, but you are working within a synchronous context.
Installation
You can install the asynchronizer
package using pip. Open your terminal and type:
pip install pysynchronizer
Usage
Here are some examples of how you can use the asynchronizer
package.
Using the decorator
from asynchronizer import asynchronize
@asynchronize
async def async_function():
# Your asynchronous code here
async_function()
In the above example, async_function
is an asynchronous function decorated with @async_to_sync
. This allows it to be called from a synchronous context.
Using the class
from asynchronizer import Asynchronizer
async def async_function():
# Your asynchronous code here
asynchronizer = Asynchronizer()
asynchronizer.run(async_function())
asynchronizer.run_async(async_function())
In this example, an instance of Asynchronizer
is created. The run
or run_async
method is then used to execute async_function
from a synchronous context.
Contributing
Contributions are welcome! Please read the CONTRIBUTING.md for details on how to contribute to this project.
License
This project is licensed under the MIT License - see the LICENSE.md file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pysynchronizer-0.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d088c774a8fb7cb82a7ab6cebf7d8ef942cea2b84d79892a89327a650a0f52a9 |
|
MD5 | c5295ee0cc788d1eb0ccb115c8ac5f7f |
|
BLAKE2b-256 | e0c8547c270df208d0e69936f35eaa3d9380a4481e801e58d1ff6d47a3c72813 |