The Bonsai SDK is made up of a command line interface for interacting with and controlling BRAINs, a library for connecting simulations to a brain for training or predictions, and examples of simulators connecting to BRAINs. Bonsai libraries known as
libbonsai (C++) and
bonsai-ai (Python) wrap the Bonsai API to simplify the process of building simulators in C++ and Python programming languages.
bonsai-ai is compatible with Python 2.7+ on Windows 7/10, macOS, and Linux.
It is strongly suggested that you first follow our guide to Install the CLI so you can be sure to have any Python prerequisites already installed.
Install bonsai-ai for Python
Here is the sequence of commands for installing bonsai-ai and related components. (NOTE:
bonsai-ai and so installing gym by itself will bring in ai too.)
Do ONE of the following:
See the Python Library Reference for full details on usage of this library.
Install with pip
Python 3+ Install
# Optional to install within a virtual environment python3 -m venv sdk2 source sdk2/bin/activate pip3 install bonsai-ai bonsai-gym bonsai-cli
Python 2.7 Install
# Optional to install within a virtual environment virtualenv sdk2 source sdk2/bin/activate pip install bonsai-ai bonsai-gym bonsai-cli
It it highly recommended that you use the Python SDK with a virtual environment of your choice. In the code panel we show virtualenv being used but you can replace this with one of your choice or leave it out and pip install directly into your system if you wish.
Install with Anaconda
# Optional to install within a virtual environment conda create -n sdk2 pip source activate sdk2 pip install bonsai-ai bonsai-gym bonsai-cli
If you do not have Anaconda installed on your system, please follow to the Install with pip instructions and skip this section.
conda is a tool for installing and managing Python and R dependencies, as well as virtual python
environments. For more information, refer to the Anaconda website.
Install libbonsai for C++
$ brew install BonsaiAI/homebrew-bonsai/bonsai
The C++ library
libbonsai can currently be installed via Homebrew. The formula is hosted on BonsaiAI’s GitHub, therefore the full link to the formula must be specified when using
brew while it is in beta.
See the C++ Library Reference for full details on usage of this library.