Metadata-Version: 2.4
Name: bteng
Version: 0.4.0
Summary: Modular Behavior Tree execution engine for Python
Author: BTEng contributors
License-Expression: MIT
Project-URL: Homepage, https://github.com/BTEng-dev/bteng
Project-URL: Bug Tracker, https://github.com/BTEng-dev/bteng/issues
Keywords: behavior-tree,robotics,automation,planning,control
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: zmq
Requires-Dist: pyzmq>=26; extra == "zmq"
Provides-Extra: dev
Requires-Dist: build; extra == "dev"
Requires-Dist: pytest; extra == "dev"
Requires-Dist: twine; extra == "dev"
Dynamic: license-file

<p align="center">
  <img src="https://raw.githubusercontent.com/BTEng-dev/bteng/main/docs/images/BTEng.webp" alt="BTEng — Behavior Tree Engine" width="720">
</p>

# BTEng — Behavior Tree Engine for Python

[![Python](https://img.shields.io/badge/python-3.12%2B-blue)](https://www.python.org/)
[![License](https://img.shields.io/badge/license-MIT-green)](https://github.com/BTEng-dev/bteng/blob/main/LICENSE)
[![Version](https://img.shields.io/badge/version-0.4.0-green)](https://github.com/BTEng-dev/bteng/blob/main/pyproject.toml)

**BTEng is a Behavior Tree engine for Python with no runtime dependencies.**

`pip install bteng` installs one package and nothing else. Every module the engine loads
at runtime imports only the standard library, so BTEng drops into a ROS node, a PLC bridge
or an embedded controller without touching your dependency tree. Exactly two modules
import anything third-party, and neither is on that path: the ZMQ event transport
(`pip install "bteng[zmq]"`) and the pytest plugin, loaded only by a test run that asks
for it.

Use it for robotics, automation, simulation — anything tick-driven that needs
preconditions, fallbacks, retries and recovery paths rather than one large control loop.

## Features

- **`async def` leaves without an async tick loop** — `CoroActionNode` awaits your host's coroutines; the tick loop stays synchronous.
- **Reactive nodes that watch the blackboard** — `ReactiveSequence` / `ReactiveFallback` interrupt a running action the moment a guard stops holding.
- **Introspection built in** — Inspector, structured logger, execution tracer with replay and an optional ZMQ stream, all fed from one point.
- **Full node library** — `Sequence`, `Fallback`, `Parallel`, `Inverter`, `RetryUntilSuccessful`, `Timeout`, `RateController`, `ForceSuccess` / `ForceFailure`.
- **Long-running work** — `StatefulActionNode`, and `AsyncActionNode` with a `CancellationToken` and an auto-injected `ThreadPool`.
- **Two ways to build trees** — the fluent `TreeBuilder`, or BehaviorTree.CPP v4-style XML with subtrees and preconditions (`_skipIf`, `_while`, …).
- **Scoped, observable blackboard** — change subscriptions, provenance history, schema validation.
- **Extensible and testable** — `@register_node`, plugin loading, mock nodes, `BehaviorTreeTest`, and a `bteng run` CLI.

## Install

```bash
pip install bteng
```

Requires Python 3.12 or newer.

## Quick Start

```python
from bteng import Blackboard, NodeStatus, TreeBuilder, TreeExecutor

bb = Blackboard.create("demo")
bb.set("battery_level", 87)

tree = (
    TreeBuilder(blackboard=bb)
    .tree_id("Mission")
    .sequence("root")
        .condition("BatteryOK", lambda: bb.get("battery_level", 0) > 20)
        .action("Navigate",     lambda: NodeStatus.SUCCESS)
    .end()
    .build()
)

executor = TreeExecutor()
executor.set_tree(tree)
print(executor.tick_until_result(max_ticks=100))  # NodeStatus.SUCCESS
```

Trees can also live in XML, so behavior is data you edit without touching code
(`Timeout` is in milliseconds):

```xml
<root BTEng_format="1.0" main_tree_to_execute="main">
  <BehaviorTree ID="main">
    <ReactiveFallback name="root">
      <ReactiveSequence name="navigate_if_safe">
        <Condition ID="PathClear"/>
        <Timeout duration="10000">
          <RetryUntilSuccessful num_attempts="3">
            <Action ID="NavigateTo" goal="{target_goal}"/>
          </RetryUntilSuccessful>
        </Timeout>
      </ReactiveSequence>
      <Action ID="StopRobot"/>
    </ReactiveFallback>
  </BehaviorTree>
</root>
```

## Documentation

| Page | What it is |
|------|------------|
| [Documentation index](https://github.com/BTEng-dev/bteng/blob/main/docs/README.md) | Every page, grouped by level |
| [Quick Start](https://github.com/BTEng-dev/bteng/blob/main/docs/start-here/quickstart.md) | Your first tree in five minutes |
| [Which API should I use?](https://github.com/BTEng-dev/bteng/blob/main/docs/start-here/which-api.md) | Python, XML, legacy `BehaviorTreeEngine`, advanced APIs |
| [Core Concepts](https://github.com/BTEng-dev/bteng/blob/main/docs/start-here/concepts.md) | Statuses, control nodes, decorators, blackboard, ports, tick loop |
| [Beginner guide](https://github.com/BTEng-dev/bteng/blob/main/docs/beginner/control-nodes.md) | Control nodes, actions, blackboard, TreeBuilder, first tests |
| [Recipes](https://github.com/BTEng-dev/bteng/blob/main/docs/README.md#practical-recipes--solve-specific-problems) | Guards, retry with recovery, async actions, subtree reuse |
| [Advanced guide](https://github.com/BTEng-dev/bteng/blob/main/docs/advanced/ports-validation.md) | Ports, reactive internals, plugins, introspection, ZMQ, runtime modification |
| [XML reference](https://github.com/BTEng-dev/bteng/blob/main/docs/reference/xml.md) | The full XML format, port syntax, preconditions, loading from Python |
| [Node reference](https://github.com/BTEng-dev/bteng/blob/main/docs/reference/nodes.md) | Node lifecycle, port model, custom node authoring |
| [Command line](https://github.com/BTEng-dev/bteng/blob/main/docs/reference/cli.md) | `bteng run` and `bteng licenses` |
| [Examples](https://github.com/BTEng-dev/bteng/tree/main/examples) | Two runnable programs with XML trees, no hardware needed |
| [Architecture](https://github.com/BTEng-dev/bteng/blob/main/docs/architecture.md) | Component relationships and data flow |
| [Changelog](https://github.com/BTEng-dev/bteng/blob/main/docs/changelog.md) | Release history |
| [Licensing](https://github.com/BTEng-dev/bteng/blob/main/docs/license/README.md) | Third-party audit and open-source alternatives |

## Acknowledgements

BTEng's design is inspired by [BehaviorTree.CPP](https://github.com/BehaviorTree/BehaviorTree.CPP),
a widely used C++ behavior tree library.

## License

BTEng is released under the MIT License. See [LICENSE](https://github.com/BTEng-dev/bteng/blob/main/LICENSE) for terms.
