skillfed

py_trees

pythonic implementation of behaviour trees

py-trees v2.5.0 192.2K downloads/30d#9,868 on PyPI632
Permissive license BSD Active released

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-trees

uv

uv add py-trees

poetry

poetry add py-trees

Installing 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

Environment :: ConsoleIntended Audience :: DevelopersLicense :: OSI Approved :: BSD LicenseProgramming Language :: PythonTopic :: Scientific/Engineering :: Artificial IntelligenceTopic :: Software Development :: Libraries

Tags

behaviour tree implementationdecision tree roboticsbehavior tree library pythonblackboard data sharingtree-based decision makingcomposite behavior patternsbehavior tree visualization
behavior-treesroboticsdecision-engine

More Libraries packages