Skip to main content

asyncify-codemod

asyncify-codemod is a codemod that converts synchronous Python code into async where possible. It focuses on a few common patterns (like requests, time.sleep, and file I/O) and rewrites them to async equivalents.

Usage

Run with pipx

pipx run asyncify-codemod [files you wish to transform ...]

E.g. if your python source files are located in src/:

pipx run asyncify-codemod src/**/*.py
pipx run asyncify-codemod --stdout path/to/file.py path/to/another.py

Comparison: asyncio.to_thread() vs async rewrites

Because “real async I/O” and “sync I/O in a thread” solve different problems, and they behave very differently at scale and under cancellation.

Where to_thread is great

Fast migration / compatibility shim: you can call existing blocking code from an async app without freezing the event loop. No behavioral rewrite: minimal code churn; good for legacy code you don’t want to touch yet. Sync-only dependencies: if there is no solid async alternative, threads are the pragmatic choice.

Where to_thread breaks down (and why a codemod helps)

  • Concurrency limits: to_thread is bounded by a thread pool. You can run thousands of concurrent await httpx/... calls; you generally can’t run thousands of threads. Under load, this becomes queueing/latency rather than throughput.
  • Cancellation semantics: cancelling an await to_thread(...) usually does not stop the underlying blocking call; it just stops waiting for it. With real async libs, cancellation is often propagated more cleanly (still not perfect everywhere, but materially better).
  • Resource efficiency: threads cost memory + scheduling overhead; async sockets/file ops can be much lighter per in-flight operation. You can’t “mix in” async behavior inside: if a function is wrapped, everything inside it stays sync. A codemod can turn the internals into await points (time.sleep → anyio.sleep, requests → httpx, open() → anyio.open_file), enabling cooperative scheduling throughout the call graph.
  • Observability/context: thread offloading can complicate tracing/log context propagation and debugging (it’s doable, just another layer). Pure async tends to integrate more directly with async frameworks’ middleware/instrumentation.

Use a codemod when you want the codebase to become natively async so it scales better, cancels better, and composes naturally with async frameworks—without hand-editing hundreds of mechanical changes.

Caveats

Sync-only dependencies

Currently, this codemod only rewrites commonly used I/O-bound operations with async alternatives (as mentioned above). If you're using custom libraries where there are no solid async alternatives, they will in your new async functions after a codemod. This is a huge performance blocker and the only way to resolve this right now is to manually update its usages (i.e. send it to asyncio.to_thread).

Metadata

Release files for asyncify-codemod 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for asyncify-codemod 0.5.0
File Size Uploaded Provenance
asyncify_codemod-0.5.0.tar.gz 42.9 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for asyncify-codemod 0.5.0
File Interpreter ABI Platform
asyncify_codemod-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 75.7 kB

Release files / asyncify_codemod-0.5.0.tar.gz

Download URL asyncify_codemod-0.5.0.tar.gz
Size 42.9 kB
Tags Source
SHA-256 checksum
How to use checksums
281dd0b21a97dd44b74beb41918bb6714d1c3e6802c0507c04e4e84108d692bd
BLAKE2b-256 checksum
How to use checksums
5c157885f3969544baa9d273d6a47c191af3721968b174528711dbce9cb1256a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 10, 2026.

Transparency log

Release files / asyncify_codemod-0.5.0-py3-none-any.whl

Download URL asyncify_codemod-0.5.0-py3-none-any.whl
Size 32.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a298956ac277608224819761c5fcd9bde97ab4278fb92ff0842cdb3eeeabec1d
BLAKE2b-256 checksum
How to use checksums
7d9b1e38eff7311be547f8915f85b01600236400e9b45e0fdd9994ab9eb3659f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 10, 2026.

Transparency log

Security for asyncify-codemod 0.5.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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for asyncify_codemod-0.5.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 10, 2026.

Transparency log

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page