{"id":5861,"library":"baron","title":"Baron: Full Syntax Tree for Python","description":"Baron is a Full Syntax Tree (FST) library for Python, designed for refactoring and detailed code analysis. Unlike an Abstract Syntax Tree (AST) which discards some syntax information, Baron's FST preserves all original formatting, including comments, empty lines, and spacing, ensuring that converting code to an FST and back exactly reproduces the original source code. The current version is 0.10.1, released in December 2021. Development is active with a focus on bug fixes, minor feature additions, and performance improvements, indicating a measured release cadence.","status":"active","version":"0.10.1","language":"en","source_language":"en","source_url":"https://github.com/PyCQA/baron","tags":["AST","FST","refactoring","code analysis","syntax tree","python"],"install":[{"cmd":"pip install baron","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Core parsing engine dependency for generating the Full Syntax Tree. It is often included implicitly or as a transitive dependency.","package":"rply","optional":false}],"imports":[{"note":"Used to convert a source code string into a Baron Full Syntax Tree (FST).","symbol":"parse","correct":"from baron import parse"},{"note":"Used to convert a Baron Full Syntax Tree (FST) back into a source code string.","symbol":"dumps","correct":"from baron import dumps"}],"quickstart":{"code":"from baron import parse, dumps\n\nsource_code = \"def example_func(x):\\n    return x + 1 # A simple function\"\nfst = parse(source_code)\n\n# You would typically manipulate the `fst` object here.\n# For most refactoring tasks, it's recommended to use RedBaron,\n# which provides a higher-level API built on top of Baron.\n# For example:\n# from redbaron import RedBaron\n# red = RedBaron(source_code)\n# red.find_node('name', value='example_func').value = 'new_name'\n# modified_code = red.dumps()\n\nregenerated_code = dumps(fst)\nprint(\"Original code:\\n\" + source_code)\nprint(\"\\nRegenerated code from FST:\\n\" + regenerated_code)\nassert source_code == regenerated_code","lang":"python","description":"Demonstrates the core `parse()` and `dumps()` functions to convert Python source code to its FST representation and back. For practical refactoring, the documentation recommends using the higher-level `RedBaron` library which is built upon Baron."},"warnings":[{"fix":"Consider `pip install redbaron` and `from redbaron import RedBaron` for common use cases.","message":"Baron provides a low-level Full Syntax Tree (FST). For most high-level refactoring and code manipulation tasks, it is strongly recommended to use `RedBaron` instead, which offers a more user-friendly and object-oriented API built on top of Baron.","severity":"gotcha","affected_versions":"0.1.0 and later"},{"fix":"Review and update code that accesses or modifies FST nodes related to function, list, or dictionary annotations to reflect the flattened structure.","message":"In version 0.9, the structure for annotations changed. Annotations are now members of `{def,list,dict}_argument` nodes to flatten the data structure, which may break code relying on the previous FST structure for annotated elements.","severity":"breaking","affected_versions":"0.9.0"},{"fix":"Inspect and refactor code that directly manipulates argument nodes in the FST, particularly those handling tuples in function definitions, to conform to the new structure.","message":"Version 0.6 introduced significant FST structure modifications. Specifically, `def_argument_tuple` nodes were removed, and argument structures became more coherent; the `name` attribute of a `def_argument` node was renamed to `target`, which now points to a dictionary instead of a string.","severity":"breaking","affected_versions":"0.6.0"},{"fix":"Test Baron thoroughly with Python code leveraging newer syntax features (e.g., assignment expressions, positional-only arguments). If issues arise, consider contributing to Baron's grammar updates or parsing your code with a compatible Python version.","message":"Baron officially supports Python 2 grammar and up to Python 3.7 grammar. Newer Python versions (3.8+) and their syntax features might not be fully supported, potentially leading to parsing errors or an incomplete FST.","severity":"gotcha","affected_versions":"0.1.0 and later when used with Python 3.8+"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z"}