BracketTree

raw JSON →
0.2.5 verified Sat May 09 auth: no python

A Python library for parsing bracket-delimited strings into tree structures, enabling nested representation from indentation or bracket patterns. Version 0.2.5 is stable, with infrequent releases.

pip install brackettree
error TypeError: __init__() missing 1 required positional argument: 'input_string'
cause Instantiating BracketTree without arguments.
fix
Provide a string: BracketTree('[a]')
error RecursionError: maximum recursion depth exceeded
cause Deeply nested brackets (e.g., more than 1000 levels).
fix
Increase recursion limit or pre-process to reduce nesting depth.
gotcha BracketTree assumes well-formed brackets; malformed input may lead to unexpected parse results or recursion errors.
fix Validate bracket balance before parsing, e.g., using a custom check.
deprecated The `BracketTree` class constructor with `None` input may raise errors in future versions; always provide a string.
fix Always pass a non-None string to BracketTree constructor.

Parse a simple bracket string into a nested dictionary structure.

from brackettree import BracketTree

# Parse a bracket string into a tree
bt = BracketTree('[a[bc]]')
tree = bt.parse()
print(tree.to_dict())  # E.g., {'a': {'b': 'c'}}