Skip to main content

Towel

Towel finds repeated Python code and extracts it into shared helper functions. Preview the changes, review the generated code, give the helpers meaningful names, and run your project's tests before adopting the result.

Release status: 1.949 (beta). At the November 8, 2026 preparation checkpoint, this candidate is unpublished and its release validation is in progress. At that checkpoint: Latest published release: 1.948. Check the GitHub releases for completed validation and publication records.

Install

The PyPI package is code-towel; the command is towel. The PyPI name towel belongs to an unrelated project, so pip install towel and uvx towel will not install this tool.

pip install code-towel
towel --version
towel --help

The runtime uses only the standard library. Optional tools format inserted code and annotate and type-check generated helpers:

pip install "code-towel[format,types]"

Towel uses these tools when installed; --no-format and --no-types turn either behavior off. Update with pip install --upgrade code-towel, or run without installing with uvx --from code-towel towel --help.

Try it on your project

# See the proposed changes without modifying your project.
towel preview path/to/project

# Keep the original and write into a fresh sibling directory.
towel dry path/to/project path/to/cleaned --no-interactive

# Review the result before adopting it. diff exits 1 when it finds changes.
diff -ru path/to/project path/to/cleaned

The output path must not already exist or overlap the input. Helpers are shared within a module by default; --cross-module also shares them between modules. A complete preview runs the full transformation pipeline. --quick gives a partial structural listing, which does not predict the final result.

Follow the runnable quick start for a complete example through extraction, naming, tests and adoption. The naming guide includes a manual rename mapping; no LLM account is required.

What to expect

Towel checks source correspondence, bindings, control flow and evaluation order, then declines transformations that fail those checks. An extraction must also repay the complexity of its helper and callers. Some repeated code is better left as it is.

Helpers initially have names such as __extracted_func_0. Preserving evaluation and cleanup order can require lookup functions or argument-lifetime bookkeeping. Review the whole change, including callers. The generated-code guide explains those cases; the command-line guide covers exclusions, bounded runs, output formats and recovery.

Requirements

Python 3.11 to 3.13 on a POSIX system (macOS or Linux). Applying changes needs POSIX filesystem semantics. Parallel analysis uses the fork start method; under other start methods analysis runs on a single core. Windows is not a supported or validated release platform.

One core is enough; TOWEL_WORKERS=1 limits analysis to one worker. Memory, disk use and run time depend on the project and enabled tools. See requirements and resources and performance measurements for measured workloads and their conditions.

Checks and limitations

Towel's soundness requirement is to preserve the behavior of programs that do not use reflection or self-instrumentation, including through code they call. An accepted transformation that changes such a program's behavior is a bug; Towel must fix the transformation or refuse it.

Reflection and source, AST, bytecode, frame or namespace inspection are outside its preservation guarantee, as is instrumentation that uses them to transform functions or classes. Towel does not scan for these behaviors or refuse code to protect them; decorators, ordinary calls and hooks have the same boundary. Protect sensitive definitions with # towel: no-extract immediately after the signature's final colon. The function opt-out guide explains its placement and limits. Mark the frame whose identity matters, including when its callee inspects it. The marker preserves that definition's source, not module namespaces, absolute line numbers or unmarked call chains. Review the known limitations and run your tests before adopting changes.

In annotated projects, Towel uses the configured type checkers when available and preserves caller-side narrowing. Existing checker errors are compared against a baseline; a checker that cannot run refuses typed extraction. The typing guide explains this policy and the unverified --no-types option.

Documentation and development

The documentation index groups tutorials, task guides, technical reference, design decisions and release evidence. Contributors can start with development setup and checks; release maintainers should follow the release procedure. Report security issues through the security policy.

License

Towel is licensed under the Apache License 2.0; its source files carry Eric Allen copyright headers.

Releases and validation

1.948 repairs four silent dry miscompilations found in 1.947. Its published release retains the completed validation record and artifacts under their original source identity. Earlier releases and their evidence remain in the release history.

Metadata

Release files for code-towel 1.949

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

Source distribution (sdist)

Source distribution for code-towel 1.949
File Size Uploaded Provenance Actions
code_towel-1.949.tar.gz 7.1 MB Without provenance Details for code_towel-1.949.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for code-towel 1.949
File Interpreter ABI Platform Actions
code_towel-1.949-py3-none-any.whl Python 3 none any Details for code_towel-1.949-py3-none-any.whl

Total release size: 7.9 MB

Release files / code_towel-1.949.tar.gz

Download URL code_towel-1.949.tar.gz
Size 7.1 MB
Tags Source
SHA-256 checksum
How to use checksums
b9065b8d7bdbbeff1b7595254557c72569a7ac808671c5ed11e3ee5388aa85e9
BLAKE2b-256 checksum
How to use checksums
0dfbeadeb4f75e597a033ce425b556bcbedc78a43756676332b2957444918174
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release files / code_towel-1.949-py3-none-any.whl

Download URL code_towel-1.949-py3-none-any.whl
Size 841.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a008bc93a2b9aa938b5dec5c8cc9b30d6cb221a6ca21e6c641cc6ca333372b10
BLAKE2b-256 checksum
How to use checksums
8719b95eae5ad2be89d10caf4742a63b546526d356d96e2c24ac4bf2e979b2db
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Security for code-towel 1.949

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.949 This release

2 release files No provenance

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