API Reference

universalasync.async_to_sync_wraps(function: Callable) Callable

Wrap an async method/property to universal method.

This allows to run wrapped methods in both async and sync contexts transparently without any additional code

When run from another thread, it runs coroutines in new thread’s event loop

See Example for full example

Parameters:

function (Callable) – function/property to wrap

Returns:

Callable – modified function

universalasync.get_event_loop() AbstractEventLoop

Useful utility for getting event loop. Acts like get_event_loop(), but also creates new event loop if needed

This will return a working event loop in 100% of cases.

Returns:

asyncio.AbstractEventLoop – event loop

universalasync.idle() None

Useful for making event loop idle in the main thread for other threads to work

universalasync.wrap(source: object) object

Convert all public async methods/properties of an object to universal methods.

See async_to_sync_wraps() for more info

Parameters:

source (object) – object to convert

Returns:

object – converted object. Note that parameter passed is being modified anyway