unasync
The async transformation code.
What it is and what it does
Unasync is a build-time code transformation tool that converts asynchronous Python code into synchronous equivalents. It works by scanning a designated async source directory (typically named _async), applying token-level transformations to remove async/await keywords and replace async-specific patterns with their synchronous counterparts, then writing the result to a sync directory (typically _sync). This allows library maintainers to maintain a single async codebase while automatically generating a synchronous API variant during the build process.
The tool integrates directly into setuptools as a custom build command, making it transparent to the build pipeline. It supports customizable transformation rules via unasync.Rule instances, allowing you to specify different source and target directories and add custom token replacements beyond the defaults. This approach is used by production libraries like the official Elasticsearch Python client and other HTTP clients that need to support both async and sync calling conventions.
Use it for:
- Generate synchronous client libraries from async code to support users who cannot use async/await.
- Maintain dual async/sync APIs in a single package without duplicating source code manually.
- Provide backward-compatible synchronous interfaces alongside modern async implementations.
- Reduce maintenance burden when supporting both async and sync calling patterns in HTTP clients or network libraries.
- Automate code generation during package builds to keep sync and async versions in sync.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Transforms asynchronous Python code into synchronous code during package build, enabling maintainers to generate both async and sync APIs from a single async source.
Yes, if you are building a library that needs to offer both async and sync APIs. It solves a real maintenance problem by automating code duplication at build time. Install it as a build dependency in your setup.py, not as a runtime dependency. No known vulnerabilities and permissive licensing make it low-risk.
Install
unasync on PyPI
pip
pip install unasyncuv
uv add unasyncpoetry
poetry add unasyncInstalling unasync
Before you install
Low friction install with only two runtime dependencies (tokenize-rt and setuptools). Actively maintained as of 2026-07-31 with 108 repository stars.
License in practice
Licensed under MIT OR Apache-2.0 (your choice), both permissive licenses with no restrictions on commercial use or redistribution.
Quickstart
pip install unasync
# In setup.py:
import unasync
import setuptools
setuptools.setup(
...,
cmdclass={'build_py': unasync.cmdclass_build_py()},
...
)
Requires setuptools to be available; intended for use during package build, not runtime.
Verify before relying
- Whether the transformation handles all async patterns or has known limitations with specific syntax.
- Performance characteristics of the generated synchronous code compared to hand-written sync implementations.
- How well the tool handles complex async patterns like context managers, generators, or exception handling.
Package facts
| License | MIT OR Apache-2.0 (permissive) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — tokenize-rt, setuptools |
| Maintenance | actively maintained — 833 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 253,396/month — #8,520 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: unasync-0.6.0-py3-none-any.whl
Keywords: async
Tags
More Build Tools packages
Provides reusable utilities for Python…
permissive · top 100 on PyPI
tqdmWraps any iterable to display a real-time…
copyleft · top 100 on PyPI
pippip is the standard installer for Python…
permissive · top 100 on PyPI
hatchlingHatchling is a standards-compliant Python build…
permissive · top 100 on PyPI
grpcio-toolsGenerates Python gRPC service stubs and message…
permissive · top 1,000 on PyPI
pre-commitpre-commit is a framework for installing and…
permissive · top 1,000 on PyPI
synchronicityWraps async functions, generators, and classes…
permissive · top 1,000 on PyPI
async_generatorProvides async generators and async context…
permissive · top 5,000 on PyPI
asgirefProvides ASGI base libraries including…
permissive · top 1,000 on PyPI
async-stripeProvides an asynchronous wrapper around the…
permissive · top 15,000 on PyPI
pytest-trioA pytest plugin that enables testing of async…
permissive · top 15,000 on PyPI
httpxHTTPX is a fully featured HTTP client library…
permissive · top 100 on PyPI
janusProvides a thread-safe queue with both…
permissive · top 5,000 on PyPI
trioTrio is an async I/O library that lets you…
permissive · top 1,000 on PyPI
greenbackAllows you to call async functions from…
permissive · top 5,000 on PyPI
python-ffmpegProvides a Python binding for FFmpeg with both…
permissive · top 15,000 on PyPI