redbaron
Abstraction on top of baron, a FST for python to make writing refactoring code a realistic task
What it is and what it does
RedBaron wraps Baron, a lossless abstract syntax tree (FST) for Python, to let you write code that modifies code. It guarantees that parsing and unparsing preserves the original source exactly, so you only change what you explicitly ask it to change. The API is inspired by BeautifulSoup, using intuitive navigation and query methods to find and transform nodes in the syntax tree.
You can use it to write custom refactoring tools, generic refactoring scripts, or interactively modify code in IPython without the limitations of text-based editors. The core is stable but the project is in alpha and has not been actively maintained since 2019, so it is not battle-tested for modern Python versions or edge cases.
Use it for:
- Write automated refactoring scripts that safely transform Python source code while preserving formatting and comments.
- Build IDE plugins or code analysis tools that need to understand and modify Python syntax trees programmatically.
- Interactively explore and modify code in IPython using a higher-level abstraction than text manipulation.
- Implement code generation or template-based code transformation that must preserve original structure.
- Create linting or code quality tools that need to rewrite code based on syntax analysis.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
RedBaron is a Python library for programmatically modifying source code by parsing it into a lossless syntax tree and allowing you to navigate, query, and transform it with a BeautifulSoup-like API.
Yes, if you need lossless code transformation and can tolerate alpha-stage software. The core concept is sound and the library has been stable for years, but the lack of maintenance means Python 3.7+ compatibility is uncertain and bugs may not be fixed. Suitable for internal tools or one-off scripts; risky for production systems or new projects requiring long-term support.
Install
redbaron on PyPI
pip
pip install redbaronuv
uv add redbaronpoetry
poetry add redbaronInstalling redbaron
Before you install
Installation is straightforward with no runtime dependencies. However, the package is in alpha status and has been abandoned since its last release on 2019-03-17, so stability and compatibility with recent Python versions are concerns.
License in practice
RedBaron is licensed under LGPLv3 (copyleft), which requires that derivative works and modifications remain under the same license. This is permissive for use but restrictive if you plan to redistribute modified versions.
Quickstart
pip install redbaron
from redbaron import RedBaron
code = "def hello(): pass"
red = RedBaron(code)
functions = red.find_all("def")
The package supports Python 2 and up to Python 3.7 grammar; compatibility beyond 3.7 is not documented.
Verify before relying
- Whether the package works correctly with Python versions beyond 3.7 despite being abandoned
- Current state of Baron dependency and whether it has received updates since RedBaron's last release
- Real-world stability and edge cases in production use given alpha status and lack of recent maintenance
Package facts
| License | lgplv3+ (copyleft) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | abandoned — 2,707 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 412,795/month — #6,845 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: redbaron-0.9.2-py2.py3-none-any.whl
Keywords: baron, fst, ast, refactoring
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
baronBaron parses Python source code into a Full…
copyleft · top 15,000 on PyPI
asttokensAnnotates Python abstract syntax trees with the…
permissive · top 1,000 on PyPI
bpythonbpython is an enhanced Python interactive…
permissive · top 15,000 on PyPI
google-pastaParse Python source code into an AST, modify…
permissive · top 1,000 on PyPI
ropeRope is a Python refactoring library that…
copyleft · top 5,000 on PyPI
astorastor converts Python abstract syntax trees…
permissive · top 5,000 on PyPI
tokenize-rtWraps Python's stdlib tokenize module to enable…
permissive · top 5,000 on PyPI
jediJedi provides static analysis, autocompletion,…
permissive · top 1,000 on PyPI
untokenizeConverts Python tokens back into source code…
permissive · top 15,000 on PyPI