Skip to main content

unblock

unblock provides small utilities that convert synchronous functions, methods, and classes into asynchronous ones for use inside an asyncio event loop. It offloads blocking work to a thread or process pool so it does not block the loop.

For full documentation, see https://unblock.readthedocs.io/en/latest/

Install (distribution name is get-unblock, import name is unblock):

pip install get-unblock

Quick example:

import asyncio
from unblock import asyncify


@asyncify
def my_sync_func():
    ...  # do something blocking


if __name__ == "__main__":
    asyncio.run(my_sync_func())

Run on a process pool instead of threads:

@asyncify(executor="process")
def cpu_bound(n):
    return sum(i * i for i in range(n))

Development

Requires Python 3.10+.

python -m venv .venv
. .venv/Scripts/activate        # or: source .venv/bin/activate
pip install -e ".[dev]"

ruff check .
ruff format --check .
mypy
pytest --cov=unblock --cov-branch

Release Notes

0.1.0

A ground-up refactor of the library. There is no compatibility with 0.0.1.

  • One unified asyncify entry point for functions, methods, and classes, with an executor parameter ("thread", "process", or an Executor instance). @asyncify(executor="process") now works as a decorator on importable functions.
  • A single executor-configurable mixin family (AsyncMixin, AsyncIterMixin, AsyncContextMixin, AsyncContextIterMixin) replaces the previous eight base classes; method names no longer need to be listed as strings.
  • async_property and async_cached_property redesigned as proper descriptors; the cached variant now computes exactly once even under concurrent awaits.
  • Work always binds to the running event loop (fixes cross-loop errors); the return-type duality (started future when a loop runs, coroutine otherwise) is documented.
  • Thread/process pools are bounded, created thread-safely, and shut down cleanly via shutdown() and an atexit hook.
  • Asynchronous tasks still start in the background when a loop is running; you await only to collect the result.
  • Works with asyncio-compatible event loops (asyncio, uvloop). It does not support trio/curio, which are not asyncio compatible natively.
  • Ships type information (PEP 561). Supports Python 3.10 and above.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

get_unblock-0.1.1.tar.gz (134.8 kB view details)

Uploaded Source

Built Distribution

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

get_unblock-0.1.1-py3-none-any.whl (19.2 kB view details)

Uploaded Python 3

File details

Details for the file get_unblock-0.1.1.tar.gz.

File metadata

  • Download URL: get_unblock-0.1.1.tar.gz
  • Upload date:
  • Size: 134.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for get_unblock-0.1.1.tar.gz
Algorithm Hash digest
SHA256 aa3d00cfa9724c44e6098ab3203c43d9ba9d0a0b47f0bab4cea91fef677d0dd0
MD5 94336e13c5bab61b0fbc3d194d64c375
BLAKE2b-256 00642b26023a61d5c43b7a2aafe9bc955a1029f3e9016f518cb8f3e65bcbd2c6

See more details on using hashes here.

Provenance

The following attestation bundles were made for get_unblock-0.1.1.tar.gz:

Publisher: publish.yml on abranjith/unblock

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file get_unblock-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: get_unblock-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 19.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for get_unblock-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4797eb032c822beff32c8107ac201e2351fee6c4bdb851bd5be09a53c1e2aee0
MD5 fc75c5d3aecda631cfd1861dff4e418c
BLAKE2b-256 91367cd4265e9a7eef50361cf1a9df1eca7dadad39a5e36682368d42ca8c0ad2

See more details on using hashes here.

Provenance

The following attestation bundles were made for get_unblock-0.1.1-py3-none-any.whl:

Publisher: publish.yml on abranjith/unblock

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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