The Matter Python REPL is a native IPython shell environment loaded with a Python-wrapped version of the C++ Matter stack to permit interacting as a controller to other Matter-compliant devices.
You can interact with the REPL in a one of three ways:
This guide provides instructions on how to utilize its various features.
You can find source files of the Python CHIP Controller tool in the src/controller/python
directory.
The tool uses the generic CHIP Device Controller library, available in the src/controller
directory.
Please follow the instructions here to build the Python virtual environment.
Activate the Python virtual environment:
source out/python_env/bin/activate
Launch the REPL.
sudo out/python_env/bin/chip-repl
By default, the REPL points to
/tmp/repl-storage.json
for persistent storage. You can over-ride that location by passing in--storagepath <path>
to the above invocation.
The REPL playground is a Jupyter Lab instance that allows you to interact with the REPL from a web browser (or a Jupyter Notebook client of your choice!). It contains the entire REPL encapsulated as an IPython kernel.
The locally hosted version requires you to follow the build instructions below to initially setup your Python environment.
Then:
pip3 install jupyterlab ipykernel
pip3 install jupyterlab-lsp pip3 install python-lsp-server
python -m ipykernel install <name-for-your-kernel>
jupyter-lab
This will automatically launch the playground on your browser.
{ "continuousHinting": true, "showDocumentation": true, "theme": 'material' }
Now, when you type, it should auto complete functions/objects/etc.
For more details, go to the Python LSP page.
A pre-built version of the REPL playground is made available through the cloud. This is ideal if you're new to the REPL and want to try it out without having to follow the build and launch instructions below. You can also use this to prototype various bits of logic in Python as well as interact with all-clusters-app from a browser.
The playground can be accessed here.
NOTE: You have to create a user ID when accessing the above for the first time (password can be blank). That creates a sandboxed environment for you to play in. There-after, you'll always be re-directed straight to the Jupyter Lab landing page.
NOTE: The sandbox is temporary. After an hour of inactivity, the sandbox is deleted and your saved contents will be lost.
For more information on Jupyter Lab, check out these docs.
Going through the above isn‘t terribly useful, since all you’ll be able to do is launch the REPL environment itself through the IPython shell.
To launch the IPython REPL, launch “matter-env” from the “Console” tab in the Launcher.
A number of Jupyter Notebooks have been written that serve as both guides for interacting with the REPL as well as being launchable directly into the cloud-hosted playground.
The following icon is present at the top of applicable guides that can be launched into the playground: