Skip to main content

Run (some) coroutine functions synchronously.

Project description

noaio

Licensed under BSD-3-Clause-Clear

Run (some) coroutine functions synchronously.

Usage

Coroutine functions can be checked for syncifiability with can_syncify. Functions that contain any await, async with, or async for expression are not syncifiable. If they are, wrap them in syncify to run them as regular synchronous functions.

from noaio import syncify, can_syncify


async def func_without_await():
    return 1


can_syncify(func_without_await) == True
syncify(func_without_await)() == 1
async def func_with_await():
    await asyncio.sleep(0)
    return 1


can_syncify(func_with_await) == False
syncify(func_with_await)  ## ValueError

How can I break it?

can_syncify checks the AST of the function you provide it. If it contains any await, async with or async for opcodes at the root level (immediately executed), it will return False.

syncify wraps the provided async function in a synchronous one that drives the coroutine to completion using .send, catching the iteration error and returning the result.

The library is typed, and expects you to use it in compliance with its type signatures.

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

noaio-1.0.0.tar.gz (2.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

noaio-1.0.0-py3-none-any.whl (2.9 kB view details)

Uploaded Python 3

File details

Details for the file noaio-1.0.0.tar.gz.

File metadata

  • Download URL: noaio-1.0.0.tar.gz
  • Upload date:
  • Size: 2.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.13 {"installer":{"name":"uv","version":"0.9.13"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for noaio-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f4916adc504f9f7fac7edc377741c0c1ad637e10d4807688dd24c1f8fe9c6826
MD5 113fcab2a12b0eaaf2f58cf9a943e241
BLAKE2b-256 bafacfc62a90486cf12b3234946d73aa69af70978855a3e35cf74b4f79ef6cb5

See more details on using hashes here.

File details

Details for the file noaio-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: noaio-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 2.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.13 {"installer":{"name":"uv","version":"0.9.13"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for noaio-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 71da8d2f1e78993085c5a85e8e6e1c24a9bec80c6ac74e3de6f1e2d1d7819567
MD5 a351aeb822fff80cb3f5661d272f9f32
BLAKE2b-256 11e4e4a5047b361e56790865da539ad88cb550b096b1656e64632fbd6579253d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page