Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pysynchronizer-0.0.5.tar.gz (16.8 kB view hashes)

Uploaded Source

Built Distribution

pysynchronizer-0.0.5-py3-none-any.whl (17.8 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