py_trees
pythonic implementation of behaviour trees
What it is and what it does
py_trees is a Python library for building behaviour trees—hierarchical, composable decision-making structures commonly used in robotics and game AI. It provides core primitives like behaviours (leaf nodes representing actions), decorators (wrappers that modify behaviour), composites (sequences, selectors, parallels that combine children), and a blackboard system for sharing state across the tree. Trees can be constructed programmatically or declaratively via XML, serialized to dot graphs for visualization, and rendered in the terminal.
The library is designed for medium-sized decision engines where you need to orchestrate complex conditional logic and state management without writing deeply nested if-else chains. It includes a library of ready-made behaviours and idioms, plus tools for introspection and debugging. Recent versions add typed input/output ports for behaviours and a ForEach decorator for iteration patterns.
Use it for:
- Build a robot control layer that sequences sensor checks, decision logic, and motor commands using tree composites.
- Implement game AI that selects actions (attack, flee, heal) based on game state stored in a shared blackboard.
- Create a workflow engine where tasks are behaviours and control flow (try-catch, retry, parallel execution) is expressed as tree structure.
- Visualize and debug decision logic by rendering the tree to ASCII/Unicode or exporting to dot graphs.
- Define complex conditional logic declaratively in XML rather than imperative code, then parse and execute it at runtime.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
py_trees implements behaviour trees in Python, providing composable decision-making primitives (behaviours, decorators, sequences, selectors, parallels) and a blackboard for data sharing to build medium-sized decision engines.
Yes. py_trees is actively maintained, has low install friction, carries no known vulnerabilities, and offers a clean abstraction for hierarchical decision-making. Install it if you are building a robotics system, game AI, or any medium-complexity state machine that benefits from tree-structured control flow and shared state management.
Install
py-trees on PyPI
pip
pip install py-treesuv
uv add py-treespoetry
poetry add py-treesInstalling py_trees
Before you install
Low friction: pure Python wheel with a single runtime dependency (pydot). Actively maintained with a recent release; last commit 2026-07-16 and support for modern Python versions including 3.14.
License in practice
BSD permissive license allows use in commercial and proprietary projects with minimal restrictions; retain license notice in distributions.
Quickstart
pip install py_trees
import py_trees
# Create a simple behavior tree
root = py_trees.composites.Sequence(name="Root", memory=False)
root.add_child(py_trees.behaviours.Success(name="Task"))
tree = py_trees.trees.BehaviourTree(root=root)
tree.setup_with_descendants()
tree.tick_once()
Verify before relying
- Whether pydot is required at runtime or only for visualization features
- Exact Python version floor for current releases (requires_python is unspecified)
Package facts
| License | BSD (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — pydot |
| Maintenance | actively maintained — 31 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 192,161/month — #9,868 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: py_trees-2.5.0-py2.py3-none-any.whl
Keywords: behaviour-trees, py-trees, py_trees
Tags
More Libraries packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
python-dateutilProvides parsing, arithmetic, and recurrence…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
dtreevizdtreeviz renders decision trees from…
permissive · top 15,000 on PyPI
tensorflow-decision-forestsTrains and deploys decision forest models…
permissive · top 15,000 on PyPI
treelite-runtimeTreelite-runtime provides a Python runtime for…
permissive · top 15,000 on PyPI
treeliteTreelite serializes and exchanges decision tree…
permissive · top 15,000 on PyPI
ydfYDF trains, evaluates, and interprets decision…
permissive · top 15,000 on PyPI
pyjptpyjpt learns and reasons about joint…
unclear · top 15,000 on PyPI
skope-rulesSkope-rules learns interpretable logical rules…
permissive · top 15,000 on PyPI
rulesrules provides object-level permission checking…
permissive · top 15,000 on PyPI
optreeOpTree provides optimized utilities for…
permissive · top 5,000 on PyPI
red-black-tree-modProvides Python implementations of red-black…
permissive · top 5,000 on PyPI