skillfed

unasync

The async transformation code.

unasync v0.6.0 253.4K downloads/30d#8,520 on PyPI108
Permissive license MIT OR Apache-2.0 Active released

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 unasync

uv

uv add unasync

poetry

poetry add unasync

Installing 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

Framework :: TrioLicense :: OSI Approved :: Apache Software LicenseLicense :: OSI Approved :: MIT LicenseOperating System :: MacOS :: MacOS XOperating System :: Microsoft :: WindowsOperating System :: POSIX :: LinuxProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPy

Tags

async to sync code generationtransform async code synchronousdual async sync libraryasync code transformation toolgenerate sync from asyncbuild-time code transformationasync sync code duplication
code-generationasync-sync-bridge

More Build Tools packages