skillfed

baron

Full Syntax Tree for python to make writing refactoring code a realist task

baron v0.10.1 414.1K downloads/30d#6,837 on PyPI304
Copyleft license lgplv3+ Abandoned released

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 baron

uv

uv add baron

poetry

poetry add baron

Installing 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

Development Status :: 3 - AlphaIntended Audience :: DevelopersLicense :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)Programming Language :: Python :: 2Programming Language :: Python :: 2.7Programming Language :: Python :: 3Programming Language :: Python :: 3.2Programming Language :: Python :: 3.3Topic :: Software DevelopmentTopic :: Software Development :: Code GeneratorsTopic :: Software Development :: Libraries

Tags

python full syntax tree parserpreserve formatting astrefactoring code transformationpython source code analysisfst json tree representation
syntax-treecode-refactoringabandoned

More Software Development packages