Skip to main content

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

Project description

Bonsai logo

PyPI Python License: MIT

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

Install

pip install bonsai-bt

The package is published on PyPI as bonsai-bt and imported as bonsai_bt:

import bonsai_bt as bt

Installation (dev)

For building from source — needed if you're contributing to the Rust core or developing against an unpublished version:

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.1.tar.gz (107.2 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.1-cp310-abi3-win_amd64.whl (378.1 kB view details)

Uploaded CPython 3.10+Windows x86-64

bonsai_bt-0.12.1-cp310-abi3-manylinux_2_28_x86_64.whl (494.0 kB view details)

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

bonsai_bt-0.12.1-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (856.6 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.1.tar.gz.

File metadata

  • Download URL: bonsai_bt-0.12.1.tar.gz
  • Upload date:
  • Size: 107.2 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.1.tar.gz
Algorithm Hash digest
SHA256 ec9d0ee56f4b0aaf3348d1db9a1da7d668805095c4efa8a154ec4d556c9a56ad
MD5 a540471471cd3be448bda852324e32cb
BLAKE2b-256 32b02bddd287c77b52245d0287ae6f1b28f3f4e90f1ffdb7ed105043f729d818

See more details on using hashes here.

Provenance

The following attestation bundles were made for bonsai_bt-0.12.1.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.1-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: bonsai_bt-0.12.1-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 378.1 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.1-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 6108bfe8ce8da93ed9d18aaf3d5064a22d4926d6167ac67029cbf478a2a2ff68
MD5 e8522fa0bf9dffd061bb57e86c6ebecf
BLAKE2b-256 67f306d24b2f5bb713daac1da3234dfb0feac02c25746a8e90e19c60e3593e7f

See more details on using hashes here.

Provenance

The following attestation bundles were made for bonsai_bt-0.12.1-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.1-cp310-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for bonsai_bt-0.12.1-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 407961321ad09316c9cc968d0a2de9e785fa2733219c7998f14f63272d33b1e8
MD5 a462a42858d9ec4c21d08776e4dc7ba1
BLAKE2b-256 dc75299bb9f7703ded56cb2241f3268b1d9633d608e069d2594ade0ff40200d2

See more details on using hashes here.

Provenance

The following attestation bundles were made for bonsai_bt-0.12.1-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.1-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.1-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 30a2b8189f9f34519c6524bf4e1c3e0a530b4ca4d0a1b111d7c7ab0d2f7111b0
MD5 7e68ba9f138e503f413b3ed99e30fef8
BLAKE2b-256 97646955657639e611c7b3bb93773a8ff471d3c99ef1369d8068f574fc78047a

See more details on using hashes here.

Provenance

The following attestation bundles were made for bonsai_bt-0.12.1-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