Baron is a Full Syntax Tree (FST) library for Python. By opposition to an AST which drops some syntax information in the process of its creation (like empty lines, comments, formatting), a FST keeps everything and guarantees the operation fst_to_code(code_to_fst(source_code)) == source_code.


Current roadmap is as boring as needed:

  • bug fixs
  • new small features (walker pattern, maybe code generation) and performance improvement.


pip install baron

Basic Usage

from baron import parse, dumps

fst = parse(source_code_string)
source_code_string == dumps(fst)

Unless you want to do low level things, use
RedBaron instead of using Baron
. Think of Baron as the "bytecode of python source code" and RedBaron
as some sort of usable layer on top of it.

If you don't know what Baron is or don't understand yet why it might be
useful for you, read the « Why is this important? » section.


Baron documentation is available on Read The Docs.