baron
Full Syntax Tree for python to make writing refactoring code a realist task
What it is and what it does
Baron is a Full Syntax Tree library that parses Python source code into a JSON-like structure while preserving all formatting details—comments, whitespace, and line breaks—that a standard AST discards. Unlike Python's built-in ast module, Baron guarantees that converting code to FST and back produces identical source code. The library outputs trees similar to Python AST but with modifications to be more human-intuitive, making it suitable for code transformation tasks like variable renaming, function inlining, and refactoring operations where formatting must be preserved.
The package depends only on rply and installs with low friction. However, it is no longer actively maintained—the last release was in December 2021 and the project is marked abandoned. Baron is positioned as a low-level tool; the documentation explicitly recommends using RedBaron (a higher-level abstraction built on Baron) for most use cases. Support covers Python 2 grammar and up to Python 3.7.
Use it for:
- Rename variables in source files without accidentally modifying strings or comments containing the same text
- Inline functions or methods while preserving original code formatting and structure
- Extract code blocks into separate functions or modules with exact formatting preservation
- Implement custom refactoring operations not available in standard IDE tools or rope
- Analyze and transform code while maintaining exact source formatting for version control diffs
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Baron parses Python source code into a Full Syntax Tree (FST) that preserves all formatting, comments, and whitespace, and can be converted back to identical source code.
No—unless you are working with a frozen Python 2 or 3.7 codebase and have no alternative. The project is abandoned (last commit 2021-12-09, 1709 days ago), and the documentation recommends RedBaron as the usable layer instead. If you need FST parsing for modern Python or active maintenance, look elsewhere; if you need it for legacy code and can accept a frozen dependency, proceed with caution.
Install
baron on PyPI
pip
pip install baronuv
uv add baronpoetry
poetry add baronInstalling baron
Before you install
Low install friction with a single dependency (rply). However, the project is abandoned—last release was 2021-12-09 and no commits since then. Use only if you need FST parsing for Python 2 through 3.7 grammar and are comfortable maintaining a frozen codebase.
License in practice
Licensed under LGPLv3 (copyleft). Derivative works and modifications must be distributed under the same license; proprietary use requires careful compliance review.
Quickstart
from baron import parse, dumps
source_code = "x = 1"
fst = parse(source_code)
reconstructed = dumps(fst)
assert reconstructed == source_code
Verify before relying
- Whether baron handles Python 3.8+ grammar (documentation states support up to 3.7)
- Current stability and bug-fix status given 1709 days since last release
- Whether RedBaron (the recommended higher-level abstraction) is actively maintained as an alternative
Package facts
| License | lgplv3+ (copyleft) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — rply |
| Maintenance | abandoned — 1,709 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 414,063/month — #6,837 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: baron-0.10.1-py2.py3-none-any.whl
Keywords: ast, fst, refactoring, syntax, tree
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
asttokensAnnotates Python abstract syntax trees with the…
permissive · top 1,000 on PyPI
redbaronRedBaron is a Python library for…
copyleft · top 15,000 on PyPI
tree-sitter-pythonProvides a Python grammar for tree-sitter,…
permissive · top 5,000 on PyPI
tree-sitter-goProvides a Go language grammar for tree-sitter,…
permissive · top 5,000 on PyPI
google-pastaParse Python source code into an AST, modify…
permissive · top 1,000 on PyPI
tree-sitter-markdownProvides a tree-sitter grammar for parsing…
permissive · top 5,000 on PyPI
tree-sitter-jsonProvides a JSON grammar parser for tree-sitter,…
permissive · top 5,000 on PyPI
tree-sitter-cssProvides a CSS grammar parser for tree-sitter,…
permissive · top 5,000 on PyPI
tree-sitter-javaProvides a Java language grammar for…
permissive · top 5,000 on PyPI
tree-sitter-groovyProvides a Groovy language grammar for…
permissive · top 5,000 on PyPI