Skip to main content

universalasync

CI Codecov PyPI version Read the Docs

A library to help automate the creation of universal python libraries

Overview

Have you ever been frustrated that you need to maintain both sync and async versions of your library, even thought their code differs by just async and await? You might have came up to rewriting your code before release or other unreliable solutions.

This library helps you to focus only on the main async implementation of your library: sync one will be created automatically

Via decorating all your public methods, the wrapped functions automatically detect different conditions and run the functions accordingly.

If user uses your library in async context, minimal overhead is added, it just returns the coroutine right away.

Otherwise the library calls the coroutine via various loop methods, like as if you did it manually.

There should be no issues at all, the only limitation is that signals and async subprocesses are supported only when running in the main thread.

Also note that when run from a different os thread, the library will create a new event loop there and run coroutines.

This means that you might need to adapt your code a bit in case you use some resources bound to a certain event loop (like aiohttp.ClientSession).

You can see an example of how this could be solved here

For API reference see the docs

Installation

pip install universalasync

Example of usage

# wrap needed methods one by one
class Client:
    @async_to_sync_wraps
    async def help():
        ...

    @async_to_sync_wraps
    @property
    async def async_property():
        ...

# or wrap whole classes
@wrap
class Client:
    async def help(self):
        ...

    @property
    async def async_property():
        ...

client = Client()

def sync_call():
    client.help()
    client.async_property

async def async_call():
    await client.help()
    await client.async_property

# works in all cases
sync_call()
asyncio.run(async_call())
threading.Thread(target=sync_call).start()
threading.Thread(target=asyncio.run, args=(async_call(),)).start()

Copyright and License

Copyright (C) 2021 MrNaif2018

Universal async-sync wrapper initially based on this implementation

Licensed under the MIT license

Metadata

Release files for universalasync 0.5.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for universalasync 0.5.1.0
File Size Uploaded
universalasync-0.5.1.0.tar.gz 77.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for universalasync 0.5.1.0
File Interpreter ABI Platform
universalasync-0.5.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 83.7 kB

Release files / universalasync-0.5.1.0.tar.gz

Download URL universalasync-0.5.1.0.tar.gz
Size 77.7 kB
Tags Source
SHA-256 checksum
How to use checksums
6f84e602709df1f22484593a3a334b428b8d8ad15fc25d4a70a1dfab68a86d4d
BLAKE2b-256 checksum
How to use checksums
a75e6714ec7dff29969dae6095bd291f004cc6605701a8274bd658e3069d5da4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 17, 2026.

Transparency log

Release files / universalasync-0.5.1.0-py3-none-any.whl

Download URL universalasync-0.5.1.0-py3-none-any.whl
Size 6.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
595f917012419a3b9f1131de168158b20d98fbb49b9ebfb7d6bbddf3c894a02b
BLAKE2b-256 checksum
How to use checksums
2b85b6ede5d78b35281408ecf4db687659d6a4f9132d2e16f8e9e429a84bb0f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 17, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.5.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page