{"id":1323,"library":"anytree","title":"Anytree","description":"Anytree is a powerful and lightweight Python library that provides a tree data structure with various plugins. It simplifies the creation, manipulation, and visualization of hierarchical data. The library is actively maintained with regular releases, approximately every few months, and is currently at version 2.13.0.","status":"active","version":"2.13.0","language":"en","source_language":"en","source_url":"https://github.com/c0fec0de/anytree","tags":["tree","data structure","hierarchy","visualization"],"install":[{"cmd":"pip install anytree","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"symbol":"Node","correct":"from anytree import Node"},{"symbol":"AnyNode","correct":"from anytree import AnyNode"},{"symbol":"NodeMixin","correct":"from anytree import NodeMixin"},{"symbol":"RenderTree","correct":"from anytree import RenderTree"},{"symbol":"DotExporter","correct":"from anytree.exporter import DotExporter"},{"note":"While importing from the submodule works, LightNodeMixin is typically made available directly from the top-level 'anytree' package since its introduction in 2.12.0 for convenience.","wrong":"from anytree.node.lightnodemixin import LightNodeMixin","symbol":"LightNodeMixin","correct":"from anytree import LightNodeMixin"}],"quickstart":{"code":"from anytree import Node, RenderTree\n\n# Create nodes by specifying parent\nudo = Node(\"Udo\")\nmarc = Node(\"Marc\", parent=udo)\nlian = Node(\"Lian\", parent=marc)\ndan = Node(\"Dan\", parent=udo)\njet = Node(\"Jet\", parent=dan)\njan = Node(\"Jan\", parent=dan)\njoe = Node(\"Joe\", parent=dan)\n\n# Or create a complex tree structure directly using children keyword\nroot_complex = Node(\"root\", children=[\n    Node(\"sub0\", children=[\n        Node(\"sub0B\", foo=4, bar=109),\n        Node(\"sub0A\")\n    ]),\n    Node(\"sub1\", children=[\n        Node(\"sub1A\"),\n        Node(\"sub1B\", bar=8),\n        Node(\"sub1C\", children=[\n            Node(\"sub1Ca\")\n        ])\n    ])\n])\n\n# Render the tree\nfor pre, fill, node in RenderTree(root_complex):\n    print(f\"{pre}{node.name}\")","lang":"python","description":"This quickstart demonstrates how to create a tree using `anytree.Node` objects, either by assigning parents incrementally or by defining the full hierarchy with the `children` keyword. It then uses `RenderTree` to print a visual representation of the tree structure to the console."},"warnings":[{"fix":"Upgrade to Python 3.9.2 or newer, and adjust code for Python 3 compatibility if necessary.","message":"Python 2.x support was removed in version 2.9.0. Users upgrading from versions prior to 2.9.0 must migrate to Python 3.x.","severity":"breaking","affected_versions":"<2.9.0"},{"fix":"Replace all usages of `node.anchestors` with `node.ancestors`.","message":"The `anchestors` attribute, which was a typo for `ancestors`, is deprecated and will be removed in version 3.0.0.","severity":"breaking","affected_versions":">=2.9.0"},{"fix":"Upgrade to anytree version 2.12.0 or newer to resolve this issue. If upgrading is not possible, avoid pickling trees with `SymlinkNode` instances.","message":"Prior to version 2.12.0, unpickling a tree containing a `SymlinkNode` could lead to a `RecursionError` due to issues in `__getattr__` for `SymlinkNodeMixin`.","severity":"gotcha","affected_versions":"<2.12.0"},{"fix":"Install `pip install graphviz` and ensure the Graphviz system utility is installed and available in your system's PATH (e.g., `apt-get install graphviz` or `brew install graphviz`).","message":"To export trees as images (e.g., PNG, DOT) using exporters like `DotExporter`, you must install the `graphviz` Python package (`pip install graphviz`) and the underlying `Graphviz` system tool separately.","severity":"gotcha","affected_versions":"All versions (where export functionality is used)"},{"fix":"Be aware of the implications of `__slots__` when using `LightNodeMixin` and prefer to pre-define all attributes or use `NodeMixin` if dynamic attribute assignment is critical.","message":"The `LightNodeMixin` (introduced in 2.12.0) behaves similarly to `NodeMixin` but uses `__slots__` for potentially better memory efficiency. This means it has minor differences in object behavior, such as not allowing arbitrary new attributes to be added dynamically after initialization.","severity":"gotcha","affected_versions":">=2.12.0"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}