Module wrapper Python library
Project description
module-wrapper - module wrapper Python library (maintenance mode)
Warning
Authors of aioify and module-wrapper decided to discontinue support of these libraries since the idea: "let's convert sync libraries to async ones" works only for some cases. Existing releases of libraries won't be removed, but don't expect any changes since today. Feel free to fork these libraries, however, we don't recommend using the automatic sync-to-async library conversion approach, as unreliable. Instead, it's better to run synchronous functions asynchronously using https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.loop.run_in_executor or https://anyio.readthedocs.io/en/stable/api.html#running-code-in-worker-threads.
Old documentation
module-wrapper contains wrap function, which is used to wrap module, class, function or another variable
recursively.
Installation
To install from PyPI run:
$ pip install module-wrapper
Usage
Example from aioify:
from functools import wraps, partial
import asyncio
import module_wrapper
__all__ = ['aioify']
def wrap(func):
@wraps(func)
async def run(*args, loop=None, executor=None, **kwargs):
if loop is None:
loop = asyncio.get_event_loop()
pfunc = partial(func, *args, **kwargs)
return await loop.run_in_executor(executor, pfunc)
return run
def aioify(obj, name=None):
def create(cls):
return 'create', wrap(cls)
return module_wrapper.wrap(obj=obj, wrapper=wrap, methods_to_add={create}, name=name)
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file module-wrapper-0.3.2.tar.gz.
File metadata
- Download URL: module-wrapper-0.3.2.tar.gz
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.12 CPython/3.9.7 Linux/5.16.15-1-default
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6fc9873df249cfc251b33328b35a3ec3c96d2d424576bc6a3ec5e8fd161bb418
|
|
| MD5 |
05fcaf3e3efb17349273f909c35889a4
|
|
| BLAKE2b-256 |
29bc8e0ebfbd903c18d40287b17452d30f09dd35d4001c9ccffed98068139c43
|
File details
Details for the file module_wrapper-0.3.2-py3-none-any.whl.
File metadata
- Download URL: module_wrapper-0.3.2-py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.12 CPython/3.9.7 Linux/5.16.15-1-default
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
28b52a8407123e727eb846bc9b12d1503988644374ff7b92ac328e874db9a054
|
|
| MD5 |
5f13dc09e0b45006e71b54758a6848fb
|
|
| BLAKE2b-256 |
3fd162abbf73ea06893059db0bc85b7cbd3593bfb5af07d4e1e8ccf05f0eae90
|