pybts


Namepybts JSON
Version 1.9.0 PyPI version JSON
download
home_pagehttps://github.com/wangtong2015/pybts
SummaryNone
upload_time2024-04-21 19:18:10
maintainerNone
docs_urlNone
author王童
requires_python<4.0,>=3.9
licenseNone
keywords behaviortree ai
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # PYBTS - Python Behavior Tree

[![PyPI Latest Release](https://img.shields.io/pypi/v/pybts.svg)](https://pypi.org/project/pybts/)
[![License](https://img.shields.io/pypi/l/pybts.svg)](https://github.com/wangtong2015/pybts)
[![Package Status](https://img.shields.io/pypi/status/pybts.svg)](https://pypi.org/project/pybts/)


## Overview

pybts (Python Behavior Tree) is a Python library for creating and managing behavior trees, which are used to model the decision-making process in artificial intelligence systems, such as in games or robotics. The library provides a structured way to organize complex behaviors through a hierarchy of nodes, each representing a specific action, decision, or condition.

## Features

- **Node Hierarchy**: Implements various node types such as `Action`, `Composite`, `Decorator`, and `Condition`, allowing complex behavior modeling.
- **Extensible Framework**: Users can define custom nodes by inheriting from base classes like `Node`, `Composite`, or `Decorator`.
- **Memory Management**: Nodes like `Sequence` and `Selector` can have memory, maintaining state between ticks.
- **Parallel Execution**: Supports parallel node execution with customizable policies (`SuccessOnOne`, `SuccessOnAll`).
- **Behavior Tracking**: Integrates with a `Board` class to track and log the state of the tree during execution.
- **Web Interface**: Features a web server (`BoardServer`) to visualize and manage behavior trees through a web interface, including real-time updates.

## Key Components

- Node Classes: Define the behavior and structure of the behavior tree.
  - `Node`: Base class for all behavior tree nodes.
  - `Composite`, `Decorator`, `Sequence`, `Parallel`, `Selector`: Specialized node types for structuring tree logic.
- Tree Management
  - `Tree`: Represents the entire behavior tree, initialized with a root node.
  - `Board`: Manages logging and tracking of tree state and history.
- Web Server
  - `BoardServer`: Flask-based web server for visualizing and managing behavior trees. Supports dynamic data updates and visualization through ECharts.

## Installation

Currently, pybts is not available through package managers and must be installed by cloning the repository:

```sh
pip install pybts
pip install pybts[rl] # add reinforcement learning support
# or
git clone https://github.com/wangtong2015/pybts.git
cd pybts
pip install -r requirements.txt
pip install .
```

## Usage

1. **Define Behavior Nodes**: Create custom behavior nodes by extending `pybts.Node` or other specific node types like `Action`, `Condition`, etc.
2. **Build the Behavior Tree**: Use the `pybts.builder.Builder` to create trees from your nodes.
3. **Track and Log**: Initialize a `Board` object with your tree to enable tracking and logging.
4. **Visualize and Manage**: Start the `BoardServer` to view and interact with the behavior tree in a web interface.

### Example

```python
from pybts import Tree, board, builder
from pybts.node import Action
from py_trees import common
import time


# Define custom behavior node
class Person(Action):
  def __init__(self, name: str, age: int):
    super().__init__(name=name)
    self.age = age

  def update(self) -> common.Status:
    self.age += 1
    return common.Status.SUCCESS


# Build the behavior tree
builder = builder.Builder()
builder.register('Person', Person)
# or
builder.register_node(Person)  # will register tag 'Person' and 'person'(snake case)
root = builder.build_from_file('demos/demo_bt.xml')
tree = Tree(root=root, name='Person')

# Initialize board for tracking
bt_board = board.Board(tree=tree, log_dir='logs')

bt_board.clear()
for i in range(10000):
  tree.tick()
  bt_board.track(info={
    'test_info': i
  })  # track the tree status
  time.sleep(0.5)
```

## Web Interface

**Running the Board Server:**

Use the following command to start the `BoardServer` with the specified log directory, enabling debug mode, and setting the host and port:

```
python -m pybts.board_server --dir=logs --debug --host=localhost --port=10000
```

1. This command starts the pybts board server using the `logs` directory for storing and retrieving behavior tree logs. Debug mode is enabled, and the server is accessible at `http://localhost:10000`.
2. **Alternative Command:** If you have a command line interface setup for `pybts` as a package, you can also start the server using a more direct command:

```bash
pybts --dir=logs --debug --host=localhost --port=10000
```

1. This assumes that `pybts` is configured as a command-line tool that internally calls `pybts.board_server`.

After running the appropriate command, you can open a web browser and navigate to `http://localhost:10000` to view and interact with the behavior tree visualizations and management tools provided by pybts.

![DEMO_Sequence  10-10 _ 100](README.assets/DEMO_Sequence%20%2010-10%20_%20100.png)

![image-20240401211609525](README.assets/image-20240401211609525.png)



![image-20240401211552611](README.assets/image-20240401211552611.png)


## Acknowledgements

This project, PYBTS (Python Behavior Tree), is developed based on the `py_trees` library, a powerful and flexible Python framework for building and managing behavior trees. We extend our heartfelt thanks to the `py_trees` project and its contributors for providing the foundational components and concepts upon which pybts is built.

For more information about `py_trees` and to access its source code, visit the official GitHub repository: [py_trees on GitHub](https://github.com/splintered-reality/py_trees).

We appreciate the effort and expertise that has gone into `py_trees`, making it possible for us to develop advanced features in pybts and offer a comprehensive behavior tree solution in the Python ecosystem.

## Development and Contributions

Contributions to pybts are welcome! You can contribute by submitting issues, providing updates to documentation, or submitting pull requests with new features or bug fixes.


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/wangtong2015/pybts",
    "name": "pybts",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.9",
    "maintainer_email": null,
    "keywords": "BehaviorTree, AI",
    "author": "\u738b\u7ae5",
    "author_email": "785271992@qq.com",
    "download_url": "https://files.pythonhosted.org/packages/e9/85/d40c84778f5a9dee41f3b58af436c8fd00cf3608ee90fb462bd53e5b5f45/pybts-1.9.0.tar.gz",
    "platform": null,
    "description": "# PYBTS - Python Behavior Tree\n\n[![PyPI Latest Release](https://img.shields.io/pypi/v/pybts.svg)](https://pypi.org/project/pybts/)\n[![License](https://img.shields.io/pypi/l/pybts.svg)](https://github.com/wangtong2015/pybts)\n[![Package Status](https://img.shields.io/pypi/status/pybts.svg)](https://pypi.org/project/pybts/)\n\n\n## Overview\n\npybts (Python Behavior Tree) is a Python library for creating and managing behavior trees, which are used to model the decision-making process in artificial intelligence systems, such as in games or robotics. The library provides a structured way to organize complex behaviors through a hierarchy of nodes, each representing a specific action, decision, or condition.\n\n## Features\n\n- **Node Hierarchy**: Implements various node types such as `Action`, `Composite`, `Decorator`, and `Condition`, allowing complex behavior modeling.\n- **Extensible Framework**: Users can define custom nodes by inheriting from base classes like `Node`, `Composite`, or `Decorator`.\n- **Memory Management**: Nodes like `Sequence` and `Selector` can have memory, maintaining state between ticks.\n- **Parallel Execution**: Supports parallel node execution with customizable policies (`SuccessOnOne`, `SuccessOnAll`).\n- **Behavior Tracking**: Integrates with a `Board` class to track and log the state of the tree during execution.\n- **Web Interface**: Features a web server (`BoardServer`) to visualize and manage behavior trees through a web interface, including real-time updates.\n\n## Key Components\n\n- Node Classes: Define the behavior and structure of the behavior tree.\n  - `Node`: Base class for all behavior tree nodes.\n  - `Composite`, `Decorator`, `Sequence`, `Parallel`, `Selector`: Specialized node types for structuring tree logic.\n- Tree Management\n  - `Tree`: Represents the entire behavior tree, initialized with a root node.\n  - `Board`: Manages logging and tracking of tree state and history.\n- Web Server\n  - `BoardServer`: Flask-based web server for visualizing and managing behavior trees. Supports dynamic data updates and visualization through ECharts.\n\n## Installation\n\nCurrently, pybts is not available through package managers and must be installed by cloning the repository:\n\n```sh\npip install pybts\npip install pybts[rl] # add reinforcement learning support\n# or\ngit clone https://github.com/wangtong2015/pybts.git\ncd pybts\npip install -r requirements.txt\npip install .\n```\n\n## Usage\n\n1. **Define Behavior Nodes**: Create custom behavior nodes by extending `pybts.Node` or other specific node types like `Action`, `Condition`, etc.\n2. **Build the Behavior Tree**: Use the `pybts.builder.Builder` to create trees from your nodes.\n3. **Track and Log**: Initialize a `Board` object with your tree to enable tracking and logging.\n4. **Visualize and Manage**: Start the `BoardServer` to view and interact with the behavior tree in a web interface.\n\n### Example\n\n```python\nfrom pybts import Tree, board, builder\nfrom pybts.node import Action\nfrom py_trees import common\nimport time\n\n\n# Define custom behavior node\nclass Person(Action):\n  def __init__(self, name: str, age: int):\n    super().__init__(name=name)\n    self.age = age\n\n  def update(self) -> common.Status:\n    self.age += 1\n    return common.Status.SUCCESS\n\n\n# Build the behavior tree\nbuilder = builder.Builder()\nbuilder.register('Person', Person)\n# or\nbuilder.register_node(Person)  # will register tag 'Person' and 'person'(snake case)\nroot = builder.build_from_file('demos/demo_bt.xml')\ntree = Tree(root=root, name='Person')\n\n# Initialize board for tracking\nbt_board = board.Board(tree=tree, log_dir='logs')\n\nbt_board.clear()\nfor i in range(10000):\n  tree.tick()\n  bt_board.track(info={\n    'test_info': i\n  })  # track the tree status\n  time.sleep(0.5)\n```\n\n## Web Interface\n\n**Running the Board Server:**\n\nUse the following command to start the `BoardServer` with the specified log directory, enabling debug mode, and setting the host and port:\n\n```\npython -m pybts.board_server --dir=logs --debug --host=localhost --port=10000\n```\n\n1. This command starts the pybts board server using the `logs` directory for storing and retrieving behavior tree logs. Debug mode is enabled, and the server is accessible at `http://localhost:10000`.\n2. **Alternative Command:** If you have a command line interface setup for `pybts` as a package, you can also start the server using a more direct command:\n\n```bash\npybts --dir=logs --debug --host=localhost --port=10000\n```\n\n1. This assumes that `pybts` is configured as a command-line tool that internally calls `pybts.board_server`.\n\nAfter running the appropriate command, you can open a web browser and navigate to `http://localhost:10000` to view and interact with the behavior tree visualizations and management tools provided by pybts.\n\n![DEMO_Sequence  10-10 _ 100](README.assets/DEMO_Sequence%20%2010-10%20_%20100.png)\n\n![image-20240401211609525](README.assets/image-20240401211609525.png)\n\n\n\n![image-20240401211552611](README.assets/image-20240401211552611.png)\n\n\n## Acknowledgements\n\nThis project, PYBTS (Python Behavior Tree), is developed based on the `py_trees` library, a powerful and flexible Python framework for building and managing behavior trees. We extend our heartfelt thanks to the `py_trees` project and its contributors for providing the foundational components and concepts upon which pybts is built.\n\nFor more information about `py_trees` and to access its source code, visit the official GitHub repository: [py_trees on GitHub](https://github.com/splintered-reality/py_trees).\n\nWe appreciate the effort and expertise that has gone into `py_trees`, making it possible for us to develop advanced features in pybts and offer a comprehensive behavior tree solution in the Python ecosystem.\n\n## Development and Contributions\n\nContributions to pybts are welcome! You can contribute by submitting issues, providing updates to documentation, or submitting pull requests with new features or bug fixes.\n\n",
    "bugtrack_url": null,
    "license": null,
    "summary": null,
    "version": "1.9.0",
    "project_urls": {
        "Homepage": "https://github.com/wangtong2015/pybts",
        "Repository": "https://github.com/wangtong2015/pybts"
    },
    "split_keywords": [
        "behaviortree",
        " ai"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cef92b50eb1488e91598e96983764c773d7bbf9ed0963f3ae2e0ee252253f188",
                "md5": "017f8e6982d7948edf8944e600352500",
                "sha256": "005b5f0b3a6113cc451ccb3fd63027b05ae371a1b9045f078e8ba4401b9ec2c8"
            },
            "downloads": -1,
            "filename": "pybts-1.9.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "017f8e6982d7948edf8944e600352500",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 765163,
            "upload_time": "2024-04-21T19:18:07",
            "upload_time_iso_8601": "2024-04-21T19:18:07.912933Z",
            "url": "https://files.pythonhosted.org/packages/ce/f9/2b50eb1488e91598e96983764c773d7bbf9ed0963f3ae2e0ee252253f188/pybts-1.9.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e985d40c84778f5a9dee41f3b58af436c8fd00cf3608ee90fb462bd53e5b5f45",
                "md5": "0091b690ea9d0b985731b571660d38a8",
                "sha256": "bb080b4669839a4316c77aa116156073c11e9826feac1f6fd5cf7e5a0207c85a"
            },
            "downloads": -1,
            "filename": "pybts-1.9.0.tar.gz",
            "has_sig": false,
            "md5_digest": "0091b690ea9d0b985731b571660d38a8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 1127022,
            "upload_time": "2024-04-21T19:18:10",
            "upload_time_iso_8601": "2024-04-21T19:18:10.209697Z",
            "url": "https://files.pythonhosted.org/packages/e9/85/d40c84778f5a9dee41f3b58af436c8fd00cf3608ee90fb462bd53e5b5f45/pybts-1.9.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-21 19:18:10",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "wangtong2015",
    "github_project": "pybts",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pybts"
}
        
Elapsed time: 0.22539s