asyncbridge
Call async functions from sync code. Call sync functions from async code. No drama.
The Problem
You have an async function but you're in sync code:
async def fetch_user(user_id: int) -> User:
...
# This doesn't work in sync code!
user = fetch_user(123) # Returns coroutine, not User
Or you have sync code but need to call it from async without blocking:
def expensive_computation(data: bytes) -> Result:
# CPU-intensive, blocks the event loop
...
The Solution
from asyncbridge import async_to_sync, sync_to_async
# Async → Sync
fetch_user_sync = async_to_sync(fetch_user)
user = fetch_user_sync(123) # Just works!
# Sync → Async (runs in thread pool)
compute_async = sync_to_async(expensive_computation)
result = await compute_async(data) # Doesn't block event loop
Installation
pip install asyncbridge
Features
- Zero dependencies - only stdlib
- Type-safe - full type hints, works with mypy
- Thread-safe - proper event loop handling
- Decorator support - use as decorator or wrapper
API
async_to_sync(func) → sync function
Converts an async function to sync. Handles event loop creation/reuse correctly.
from asyncbridge import async_to_sync
@async_to_sync
async def my_async_func():
await asyncio.sleep(1)
return "done"
result = my_async_func() # Blocks until complete
sync_to_async(func) → async function
Runs sync function in thread pool executor to avoid blocking event loop.
from asyncbridge import sync_to_async
@sync_to_async
def blocking_io():
time.sleep(1)
return "done"
result = await blocking_io() # Runs in thread, doesn't block loop
When to Use
| Situation | Solution |
|---|---|
| Calling async library from sync script | async_to_sync |
| Using async ORM in sync framework | async_to_sync |
| CPU-bound work in async server | sync_to_async |
| Blocking I/O in async code | sync_to_async |
Alternatives Comparison
| Package | Deps | Framework-agnostic | Maintained |
|---|---|---|---|
| asyncbridge | 0 | ✅ | ✅ |
| asgiref | 1 | Django-focused | ✅ |
| nest-asyncio | 0 | Different purpose | ✅ |
License
MIT
Metadata
Release files for asyncbridge 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| asyncbridge-1.0.0.tar.gz | 4.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| asyncbridge-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.3 kB
Release files / asyncbridge-1.0.0.tar.gz
| Download URL | asyncbridge-1.0.0.tar.gz |
|---|---|
| Size | 4.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9a49d56093a6f28919ecea9a515c61da2d0c829e4df680bbef07284537b5db03
|
|
BLAKE2b-256 checksum How to use checksums |
ec828594aa70f45e63a7eff863edb08027143941c045ed3affcc194df7c9a935
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.0
|
Release files / asyncbridge-1.0.0-py3-none-any.whl
| Download URL | asyncbridge-1.0.0-py3-none-any.whl |
|---|---|
| Size | 3.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ed0402aaacb1526033e130ba4ce512b1256711aed88ee6444e67eb95b5e24a88
|
|
BLAKE2b-256 checksum How to use checksums |
c9c431ba1b6bf7e24af15c8f9b46863378b98828f8e29fb806d23c39a4a25984
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.0
|
Security for asyncbridge 1.0.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.