Registry / ai-ml / py-trees

py-trees

JSON →
library2.4.0pypypi✓ verified 87d ago

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.

pip install py-trees
INSTALL
IMPORT
SIG · PY-TREES
P
py-trees
ai-mlpythonv2.4.0
Install
1.8s avg
Import
179ms
Disk
18MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.4.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.190s · 19.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.8s · import 0.168s · 20MB
18MB installed
● package 18MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Behaviour
from py_trees.behaviour import Behaviour
from py_trees import Behaviour
Behaviour is in its own module, not top-level
Sequence
from py_trees.composites import Sequence
from py_trees import Sequence
Composites are in py_trees.composites
Selector
from py_trees.composites import Selector
from py_trees import Selector
Composites are in py_trees.composites
Parallel
from py_trees.composites import Parallel
from py_trees import Parallel
Composites are in py_trees.composites
Running
from py_trees.common import Running
from py_trees import Running
Status constants are in py_trees.common
create_tree
from py_trees.console import create_tree
from py_trees import create_tree
Console utilities are in py_trees.console

Creates a simple sequence with two behaviours and ticks it.

import py_trees # Create a simple sequence tree root = py_trees.composites.Sequence(name="Root", memory=True) move = py_trees.behaviours.SuccessEveryN(name="Move", n=5) wait = py_trees.behaviours.Running(name="Wait") root.add_children([move, wait]) # Create the tree py_trees.trees.BehaviourTree(root) # Tick the tree for i in range(3): root.tick_once() print(f"Tick {i}: {root.status}")
Debug
Known issues
breakingIn 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.
fix
Use the new class names: from py_trees.composites import Sequence, Selector; instantiate with memory=True/False as needed.
affects: >=2.2.0
deprecatedThe behaviour 'FailureEveryN' was removed. Use a custom behaviour that returns FAILURE instead.
fix
Replace with a custom behaviour that sets status to FAILURE periodically.
affects: <2.4.0
gotchaBehaviours may run indefinitely if they don't return SUCCESS or FAILURE. Always ensure your behaviour's update() method terminates.
fix
Return py_trees.common.Status.SUCCESS or FAILURE from update().
affects: all
gotchaThe '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.
fix
Read the documentation carefully; choose policy = py_trees.common.ParallelPolicy.FailOnOne or SuccessOnAll.
affects: all
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'py_trees'
The package is installed with a hyphen: py-trees, not py_trees.
fix
pip install py-trees
AttributeError: module 'py_trees' has no attribute 'Behaviour'
Importing from the top-level instead of submodules.
fix
from py_trees.behaviour import Behaviour
ValueError: The behaviour tree has not been initialised. Have you remembered to add the tree root to a BehaviourTree?
You created a tree but forgot to wrap it in py_trees.trees.BehaviourTree(root).
fix
tree = py_trees.trees.BehaviourTree(root)
Upgrade
Version history
2.4.0latest on PyPI · released Nov 13, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
45 hits · last 30 days
node
42
OpenAI (training)
1
Resources
py-trees — pip install py-trees · libregistry