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
asyncifyentry point for functions, methods, and classes, with anexecutorparameter ("thread","process", or anExecutorinstance).@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_propertyandasync_cached_propertyredesigned 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 anatexithook. - Asynchronous tasks still start in the background when a loop is running; you
awaitonly 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aa3d00cfa9724c44e6098ab3203c43d9ba9d0a0b47f0bab4cea91fef677d0dd0
|
|
| MD5 |
94336e13c5bab61b0fbc3d194d64c375
|
|
| BLAKE2b-256 |
00642b26023a61d5c43b7a2aafe9bc955a1029f3e9016f518cb8f3e65bcbd2c6
|
Provenance
The following attestation bundles were made for get_unblock-0.1.1.tar.gz:
Publisher:
publish.yml on abranjith/unblock
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
get_unblock-0.1.1.tar.gz -
Subject digest:
aa3d00cfa9724c44e6098ab3203c43d9ba9d0a0b47f0bab4cea91fef677d0dd0 - Sigstore transparency entry: 2052962935
- Sigstore integration time:
-
Permalink:
abranjith/unblock@fe6d4ec18308dcb47b9299132de17942dbf0720c -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/abranjith
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@fe6d4ec18308dcb47b9299132de17942dbf0720c -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4797eb032c822beff32c8107ac201e2351fee6c4bdb851bd5be09a53c1e2aee0
|
|
| MD5 |
fc75c5d3aecda631cfd1861dff4e418c
|
|
| BLAKE2b-256 |
91367cd4265e9a7eef50361cf1a9df1eca7dadad39a5e36682368d42ca8c0ad2
|
Provenance
The following attestation bundles were made for get_unblock-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on abranjith/unblock
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
get_unblock-0.1.1-py3-none-any.whl -
Subject digest:
4797eb032c822beff32c8107ac201e2351fee6c4bdb851bd5be09a53c1e2aee0 - Sigstore transparency entry: 2052963350
- Sigstore integration time:
-
Permalink:
abranjith/unblock@fe6d4ec18308dcb47b9299132de17942dbf0720c -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/abranjith
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@fe6d4ec18308dcb47b9299132de17942dbf0720c -
Trigger Event:
push
-
Statement type: