{"id":21723,"library":"py-trees","title":"py_trees","description":"A pythonic implementation of behaviour trees for building hierarchical decision-making systems. Currently at version 2.4.0, with support for Python 3.9+ and ROS 2 Humble/Jazzy. Released roughly every 6-12 months.","status":"active","version":"2.4.0","language":"python","source_language":"en","source_url":"https://github.com/splintered-reality/py_trees","tags":["behaviour trees","robotics","AI","ROS"],"install":[{"cmd":"pip install py-trees","lang":"bash","label":"PyPI install"}],"dependencies":[],"imports":[{"note":"Behaviour is in its own module, not top-level","wrong":"from py_trees import Behaviour","symbol":"Behaviour","correct":"from py_trees.behaviour import Behaviour"},{"note":"Composites are in py_trees.composites","wrong":"from py_trees import Sequence","symbol":"Sequence","correct":"from py_trees.composites import Sequence"},{"note":"Composites are in py_trees.composites","wrong":"from py_trees import Selector","symbol":"Selector","correct":"from py_trees.composites import Selector"},{"note":"Composites are in py_trees.composites","wrong":"from py_trees import Parallel","symbol":"Parallel","correct":"from py_trees.composites import Parallel"},{"note":"Status constants are in py_trees.common","wrong":"from py_trees import Running","symbol":"Running","correct":"from py_trees.common import Running"},{"note":"Console utilities are in py_trees.console","wrong":"from py_trees import create_tree","symbol":"create_tree","correct":"from py_trees.console import create_tree"}],"quickstart":{"code":"import py_trees\n\n# Create a simple sequence tree\nroot = py_trees.composites.Sequence(name=\"Root\", memory=True)\nmove = py_trees.behaviours.SuccessEveryN(name=\"Move\", n=5)\nwait = py_trees.behaviours.Running(name=\"Wait\")\nroot.add_children([move, wait])\n\n# Create the tree\npy_trees.trees.BehaviourTree(root)\n\n# Tick the tree\nfor i in range(3):\n    root.tick_once()\n    print(f\"Tick {i}: {root.status}\")","lang":"python","description":"Creates a simple sequence with two behaviours and ticks it."},"warnings":[{"fix":"Use the new class names: from py_trees.composites import Sequence, Selector; instantiate with memory=True/False as needed.","message":"In v2.2.x, Sequence and Selector were renamed from Sequence and Selector (with memory) to Sequence and Selector (with memory). The old classes without memory are now Sequence and Selector with memory=False. Code using the old names will break.","severity":"breaking","affected_versions":">=2.2.0"},{"fix":"Replace with a custom behaviour that sets status to FAILURE periodically.","message":"The behaviour 'FailureEveryN' was removed. Use a custom behaviour that returns FAILURE instead.","severity":"deprecated","affected_versions":"<2.4.0"},{"fix":"Return py_trees.common.Status.SUCCESS or FAILURE from update().","message":"Behaviours may run indefinitely if they don't return SUCCESS or FAILURE. Always ensure your behaviour's update() method terminates.","severity":"gotcha","affected_versions":"all"},{"fix":"Read the documentation carefully; choose policy = py_trees.common.ParallelPolicy.FailOnOne or SuccessOnAll.","message":"The 'parallel' policy FAIL_ON_ONE and SUCCEED_ON_ALL are confusing. FAIL_ON_ONE means the whole parallel fails if any child fails. SUCCEED_ON_ALL means it succeeds only when all succeed.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"pip install py-trees","cause":"The package is installed with a hyphen: py-trees, not py_trees.","error":"ModuleNotFoundError: No module named 'py_trees'"},{"fix":"from py_trees.behaviour import Behaviour","cause":"Importing from the top-level instead of submodules.","error":"AttributeError: module 'py_trees' has no attribute 'Behaviour'"},{"fix":"tree = py_trees.trees.BehaviourTree(root)","cause":"You created a tree but forgot to wrap it in py_trees.trees.BehaviourTree(root).","error":"ValueError: The behaviour tree has not been initialised. Have you remembered to add the tree root to a BehaviourTree?"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}