Python functions agnostic towards being called with await or otherwise.
Project description
asyncgnostic
Python functions agnostic towards being called with await or otherwise.
Uses multiple dispatch to automatically call asynchronous or synchronous function based on calling context.
Example:
import asyncio
from asyncgnostic import awaitable
def handler() -> str:
return "Running Sync"
@awaitable(handler)
async def handler() -> str:
return "Running Async"
def sync_main():
print("sync context", handler())
async def async_main():
print("async context:", await handler())
sync_main()
asyncio.run(async_main())
Output:
sync context Running Sync
async context: Running Async
Credits:
Gratefully borrowed improvements from curio.
Reference:
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
asyncgnostic-0.1.0.tar.gz
(2.7 kB
view details)
Built Distribution
File details
Details for the file asyncgnostic-0.1.0.tar.gz
.
File metadata
- Download URL: asyncgnostic-0.1.0.tar.gz
- Upload date:
- Size: 2.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ef9d89caa0d7249a28d6b13a523927558f0add22df94d6a925ee7d7d66e6456 |
|
MD5 | 5ae136d88039826bbc027d7814ec3fae |
|
BLAKE2b-256 | 9fb50375534182e6fe43035ed08c5f4bb2bb0b5f64036646bac547a72db982eb |
File details
Details for the file asyncgnostic-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: asyncgnostic-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a45b89ed584be290bba313aa03c2fedfc7aedb89bd64cc4fec3f7c16ba371fb3 |
|
MD5 | 28045788deeeb18c1a0241917e296756 |
|
BLAKE2b-256 | 9de7eb5cbc557f810b85dbb80f207797d60ed00f29ddc1a75a692299eade7165 |