A simple python library providing a function decorator to wap async functions for use in synchronous code
Project description
AsyncSyncWrap: A Library for Wrapping Synchronous Functions
AsyncSyncWrap is a Python library that simplifies the process of integrating Asynchronous functions into synchronous codebases. It provides a decorator, syncwrap, that allows you to seamlessly use asynchronous functions within synchronous environments. This library is particularly useful when you need to work with legacy code or external libraries where one requires async and the other does not.
Installation
You can easily install AsyncSyncWrap via pip:
pip install syncwrap
Usage
The core feature of AsyncSyncWrap is the syncwrap decorator:
from syncwrap import syncwrap
#wrap a given function
@syncwrap
async def my_sync_function():
# call asyncronous code etc.
await ...
return 1
#within standard syncrounous code use without needing to await
result = my_sync_function()
Option timeout:
@syncwrap(timeout=2.0)
def my_slow_sync_function():
...
Alternativly with an external library to avoid extra wrapper functions:
# Wrap and call the external asynchronous function inline for testing
result = syncwrap(external_async_function)(*args, **kwargs)
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
File details
Details for the file syncwrap-0.0.1.tar.gz
.
File metadata
- Download URL: syncwrap-0.0.1.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4028c8205b570d429004b7030021fb36fc502fa90b43c28b419d03a8fe30ecee |
|
MD5 | 67e211feed9768b6aa01a71a6cc01039 |
|
BLAKE2b-256 | 18ce3188cd6409e5cb191471e37cb84d57476be30b725ef5d6ba53f8505d6106 |
File details
Details for the file syncwrap-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: syncwrap-0.0.1-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cfc1a3707f416ce7e6db815f3eacb83b9c48eff59b3c15e343851b3badcbd0b3 |
|
MD5 | 65251947458cb3b1c2256b305b48a63a |
|
BLAKE2b-256 | d2b4b1057e916b9e79d52749a5037ad86890fa0c69df8e156586a0e22c0c5c2a |