untokenize
Transforms tokens into original source code (while preserving whitespace).
What it is and what it does
untokenize is a small utility that reverses Python's tokenization process—taking a stream of tokens and reconstructing the original source code. The key difference from the standard library's tokenize.untokenize() is that it preserves the exact whitespace that appeared between tokens in the original source, rather than normalizing or collapsing it. This makes it useful when you need to round-trip code through tokenization without losing formatting details.
The package has no external dependencies and is straightforward to use: pass a token stream to untokenize.untokenize() and get back the reconstructed source. However, the project is abandoned—last updated in 2014—and has not been maintained or tested against modern Python versions. It was originally written for Python 2.6, 2.7, and 3, but its actual compatibility with current Python releases is unknown.
Use it for:
- Reconstructing source code after tokenization in code analysis or transformation tools that need to preserve formatting.
- Building code generators or refactoring tools that must round-trip code without altering whitespace.
- Testing tokenization round-trip fidelity—verifying that tokenize → untokenize produces byte-for-byte identical output.
- Implementing syntax-aware code editors or linters that need to preserve original formatting while making targeted changes.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Converts Python tokens back into source code while preserving original whitespace, unlike the standard library's tokenize.untokenize() which loses formatting.
No. The package is abandoned (last update 2014, last commit 2019-05-24) with no active maintenance or security updates. Compatibility with modern Python versions is unverified. Unless you have a specific legacy codebase or a very narrow use case that depends on this exact implementation, the standard library's tokenize module or a maintained alternative is a safer choice.
Install
untokenize on PyPI
pip
pip install untokenizeuv
uv add untokenizepoetry
poetry add untokenizeInstalling untokenize
Before you install
High install friction with no runtime dependencies. The package is abandoned—last commit was 2019-05-24, over four years ago—and has not been updated since its 0.1.1 release in 2014. No active maintenance or security updates should be expected.
License in practice
Licensed under the Expat License (MIT), a permissive open-source license with minimal restrictions. You may use, modify, and distribute the package freely in proprietary or open-source projects.
Quickstart
import untokenize
import tokenize
import io
tokens = tokenize.generate_tokens(io.StringIO(source_code).readline)
reconstructed = untokenize.untokenize(tokens)
The package was written for Python 2.6, 2.7, and 3 but has not been maintained since 2014; compatibility with modern Python versions is unverified.
Verify before relying
- Whether the package works correctly with Python versions released after 2014.
- Whether the whitespace-preservation behavior handles all edge cases in modern Python syntax.
- Active alternatives or whether the standard library's tokenize module has since improved.
Package facts
| License | Expat License (permissive) |
| Python support | not specified |
| Install friction | high — source build required |
| Runtime dependencies | none |
| Maintenance | abandoned — 4,570 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 493,860/month — #6,353 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: untokenize-0.1.1.tar.gz
Keywords: tokenize, untokenize, transform, generate
Tags
More Text Processing packages
A drop-in replacement for Python's standard…
permissive · top 100 on PyPI
pyparsingpyparsing provides a library for building text…
permissive · top 1,000 on PyPI
docutilsDocutils converts plaintext documentation in…
unclear · top 1,000 on PyPI
RapidFuzzRapidFuzz provides fast fuzzy string matching…
permissive · top 1,000 on PyPI
tinycss2tinycss2 parses CSS strings into token and…
permissive · top 1,000 on PyPI
llama-parseLlamaParse parses complex documents (PDFs,…
permissive · top 1,000 on PyPI
tokenize-rtWraps Python's stdlib tokenize module to enable…
permissive · top 5,000 on PyPI
sacremosesSacremoses provides tokenization,…
permissive · top 5,000 on PyPI
imperfectParses and edits configparser-compatible INI…
permissive · top 15,000 on PyPI
tomlkitParses and edits TOML files while preserving…
permissive · top 1,000 on PyPI
tensorflow-textTensorFlow Text provides text preprocessing…
permissive · top 5,000 on PyPI
tokenizersTokenizers converts raw text into token…
permissive · top 1,000 on PyPI
semchunksemchunk splits text into semantically…
permissive · top 5,000 on PyPI
python-minifierTransforms Python source code into compact,…
permissive · top 15,000 on PyPI
htmlmin2Minifies HTML by removing unnecessary…
permissive · top 5,000 on PyPI
tokenizerTokenizes Icelandic text into words,…
permissive · top 15,000 on PyPI