Skip to main content

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


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 hashes)

Uploaded Source

Built Distribution

asyncgnostic-0.1.0-py3-none-any.whl (3.3 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