1. Home
  2. Docs
  3. Niryo One documentation
  4. Tutorials
  5. Use the Niryo One Python API

Use the Niryo One Python API

PHN0eWxlPgouZGlzY2xhaW1lciB7CmJhY2tncm91bmQ6I2U3ZjJmYTsKICAgIGxpbmUtaGVpZ2h0OiAyNHB4OwogICAgbWFyZ2luLWJvdHRvbTogMjRweDsKICAgICAgYm9yZGVyLXJhZGl1czogMTBweDsKICAgIG92ZXJmbG93OiBoaWRkZW47CiAgICBib3gtc2hhZG93OiAwIDAgMTBweCByZ2IoMCAwIDAgLyAzMCUpOwogIGZvbnQtZmFtaWx5OiBvcGVuLXNhbnMsIGhlbHZldGljYSwgc2Fucy1zZXJpZjsKfQouZGlzLXRpdGxlIHsKYmFja2dyb3VuZDojNmFiMGRlOwogIGZvbnQtd2VpZ2h0OiA3MDA7CiAgICBkaXNwbGF5OiBibG9jazsKICAgIGNvbG9yOiAjZmZmOwogICAgYmFja2dyb3VuZDogIzZhYjBkZTsKICAgIHBhZGRpbmc6IDZweCAxMnB4Owp9Ci5kaXMtdGV4dCB7CiAgICBwYWRkaW5nOiA2cHggMTJweDsKfQouZGlzLXRleHQgYSB7CnRleHQtZGVjb3JhdGlvbjogdW5kZXJsaW5lICFpbXBvcnRhbnQ7Cn0KPC9zdHlsZT4KPGRpdiBjbGFzcz0iZGlzY2xhaW1lciI+CjxkaXYgY2xhc3M9ImRpcy10aXRsZSI+Tm90ZTwvZGl2Pgo8ZGl2IGNsYXNzPSJkaXMtdGV4dCI+VGhpcyB0dXRvcmlhbCBpcyBkZXNpZ25lZCBmb3IgTmlyeW8gT25lIHVzZXJzLiBJZiB5b3UgYXJlIHVzaW5nIE5lZCwgcGxlYXNlIGZpbmQgb3VyIG5ldyBkb2N1bWVudGF0aW9uIDxhIGhyZWY9Imh0dHBzOi8vZG9jcy5uaXJ5by5jb20vIiB0YXJnZXQ9Il9ibGFuayI+aGVyZTwvYT4uPC9kaXY+CjwvZGl2Pg==

You can control Niryo One using directly a Python API (no ROS knowledge needed).

This is great if you want to have more control over the robot, and start teaching/learning Python programming.

Basically, if you’re already using the block interface in Niryo One Studio, you have to know that all the blocks are directly calling functions from the Python API. So, you can start by teaching/learning with blocks first and then dive into the Python code.

Code examples and reference documentation

You can find some examples as well as a documentation for all available functions here on our official GitHub repository.

Remotely execute a Python script

Let’s say you have written a script on the Raspberry Pi inside the robot. It’s working nicely, but now you want to remotely execute it.

Instead of manually connecting to the robot via ssh and launching the Python script, you can start the script with just one command from your computer.

If you just use the command ssh niryo@ip_address python your_script.py, it won’t work, you’ll get an error message stating “ImportError: No module named niryo_one_python_api.niryo_one_api”.

To successfully execute the script, you’ll need to write:

ssh niryo@ip_address ‘source ~/catkin_ws/devel/setup.bash && export PYTHONPATH=${PYTHONPATH}:/home/niryo/catkin_ws/src/niryo_one_python_api/src/niryo_python_api && python your_script.py’

Replace “ip_address” with the Raspberry Pi IP address, and “your_script” with the name of your script. Also, don’t forget to make the script executable (using chmod +x).

If you want to avoid typing this every time you want to execute the script, you can automate this by including it on a script or create an alias on your own .bashrc.

How can we help?