Skip to main content

Behavior trees in Python, powered by the bonsai-bt Rust crate.

Project description

bonsai-bt - Python bindings

Python bindings for the bonsai-bt behavior-tree library.

Installation (dev)

python -m venv .venv
source .venv/bin/activate   # Windows: .venv\Scripts\Activate.ps1
pip install maturin
cd bonsai-py
maturin develop
python -c "import bonsai_bt; print(bonsai_bt.__version__)"

Same BT in Rust and Python

A minimal three-node tree (Hello → Wait(1.0) → Goodbye) implemented in both languages. Semantics are identical because the Python package is a thin wrapper around the Rust crate; only the API surface differs (Rust requires an enum + explicit types; Python uses any hashable object as the action payload).

Rust

use bonsai_bt::{Behavior, Event, Status, UpdateArgs, BT};

#[derive(Clone, Debug)]
enum Greet { Hello, Goodbye }

fn main() {
    let tree = Behavior::Sequence(vec![
        Behavior::Action(Greet::Hello),
        Behavior::Wait(1.0),
        Behavior::Action(Greet::Goodbye),
    ]);

    let mut bt: BT<Greet, ()> = BT::new(tree, ());

    for _ in 0..5 {
        let e: Event = UpdateArgs { dt: 0.5 }.into();
        bt.tick(&e, &mut |args, _bb| {
            match *args.action {
                Greet::Hello   => println!("hello"),
                Greet::Goodbye => println!("goodbye"),
            }
            (Status::Success, args.dt)
        });
    }
}

Python

import bonsai_bt as bt

tree = bt.Sequence([
    bt.Action("hello"),
    bt.Wait(1.0),
    bt.Action("goodbye"),
])

tree_bt = bt.BT(tree, None)

def cb(args, _bb):
    print(args.action)
    return (bt.Status.Success, args.dt)

for _ in range(5):
    tree_bt.tick(0.5, cb)

Output (both):

hello
goodbye

For richer examples — multi-job orchestration, visualizer integration, parallel agents — see examples/.

License

MIT - see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bonsai_bt-0.12.0.tar.gz (106.4 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

bonsai_bt-0.12.0-cp310-abi3-win_amd64.whl (377.8 kB view details)

Uploaded CPython 3.10+Windows x86-64

bonsai_bt-0.12.0-cp310-abi3-manylinux_2_28_x86_64.whl (493.7 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ x86-64

bonsai_bt-0.12.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (856.3 kB view details)

Uploaded CPython 3.10+macOS 10.12+ universal2 (ARM64, x86-64)macOS 10.12+ x86-64macOS 11.0+ ARM64

File details

Details for the file bonsai_bt-0.12.0.tar.gz.

File metadata

  • Download URL: bonsai_bt-0.12.0.tar.gz
  • Upload date:
  • Size: 106.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for bonsai_bt-0.12.0.tar.gz
Algorithm Hash digest
SHA256 ac6f8e2a686f68594e8b8e5b599b4eb32bbb12aa135cc6f494b2789ff5aaec6f
MD5 20b737c50e4e2aa283d5b4fe2b19370e
BLAKE2b-256 c95fd54aaf40747a6af158355f7584972770a73d39c456db3746d13b653b29ef

See more details on using hashes here.

Provenance

The following attestation bundles were made for bonsai_bt-0.12.0.tar.gz:

Publisher: python-wheels.yml on Sollimann/bonsai

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bonsai_bt-0.12.0-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: bonsai_bt-0.12.0-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 377.8 kB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for bonsai_bt-0.12.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 a064586a936240f36a4ff4f08ad5e24842ca97c968ee3f5bf17cd3fcb033d4b9
MD5 e9f993e73e1e5d30f6af3f5cb96fe025
BLAKE2b-256 675f32d0f6d5be1efe5cb0ead8bdd87a0875146aad548bdef9326ad8264489b6

See more details on using hashes here.

Provenance

The following attestation bundles were made for bonsai_bt-0.12.0-cp310-abi3-win_amd64.whl:

Publisher: python-wheels.yml on Sollimann/bonsai

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bonsai_bt-0.12.0-cp310-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for bonsai_bt-0.12.0-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8ebe80453075355fb7979bc2990d3ed2343654d1141714aa31783b3a12398b1c
MD5 90cf9a2d03b4f06b8e804b7d7712cc50
BLAKE2b-256 cd67f0b2a8e5565aff45f35b74f93f587ceea15f227065c9e6165c2f0433567a

See more details on using hashes here.

Provenance

The following attestation bundles were made for bonsai_bt-0.12.0-cp310-abi3-manylinux_2_28_x86_64.whl:

Publisher: python-wheels.yml on Sollimann/bonsai

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bonsai_bt-0.12.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for bonsai_bt-0.12.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 b40d1d6f8bbf1007e76cc81cf8817cdd122932707c3171e37fc2ae88bfc28490
MD5 9f4eacf4d5cd92e4f885479797396876
BLAKE2b-256 0a3ec4b4afb97e04cd85ab6d5a11dc6f1c531f1556f7589c65dd1fc38ceb626e

See more details on using hashes here.

Provenance

The following attestation bundles were made for bonsai_bt-0.12.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl:

Publisher: python-wheels.yml on Sollimann/bonsai

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page