Skip to main content

Pybricks developer tools

Project description

Coverage Status Documentation Status

Pybricks tools & interface library

This is a package with tools for Pybricks developers. For regular users we recommend the Pybricks Code web IDE.

This package contains both command line tools and a library to call equivalent operations from within a Python script.

Installation

Python Runtime

pybricksdev requires Python 3.8 or higher.

Command Line Tool

We recommend using pipx to install pybricksdev as a command line tool.

We also highly recommend installing pipx using a package manager such as apt, brew, etc. as suggested in the official pipx installation instructions.

And don't forget to run pipx ensurepath after the initial installation. This will make it so that tools installed with pipx are in your PATH. You will need to restart any terminal windows for this to take effect. If that doesn't work, try logging out and logging back in.

Then use pipx to install pybricksdev:

# POSIX shell (Linux, macOS, Cygwin, etc)
PIPX_DEFAULT_PYTHON=python3.8 pipx install pybricksdev

Setting the PIPX_DEFAULT_PYTHON environment variable is only needed when pipx uses a different Python runtime other that Python 3.8. This may be the case if your package manager uses a different Python runtime.

Windows users

If you are using the Python Launcher for Windows (installed by default with the official Python installer), then you will need to use py -3.8 instead of python3.8.

py -3.8 -m pip install --upgrade pip # ensure pip is up to date first
py -3.8 -m pip install pipx
py -3.8 -m pipx ensurepath
py -3.8 -m pipx install pybricksdev

Linux USB

On Linux, udev rules are needed to allow access via USB. The pybricksdev command line tool contains a function to generate the required rules. Run the following:

pybricksdev udev | sudo tee /etc/udev/rules.d/99-pybricksdev.rules

Library

To install pybricksdev as a library, we highly recommend using a virtual environment for your project. Our tool of choice for this is poetry:

poetry env use python3.8
poetry add pybricksdev

Of course you can always use pip as well:

pip install pybricksdev --pre

Using the Command Line Tool

The following are some examples of how to use the pybricksdev command line tool. For additional info, run pybricksdev --help.

Flashing Pybricks MicroPython firmware

Make sure the hub is off. Press and keep holding the hub button, and run:

pybricksdev flash <firmware.zip>

Replace <firmware.zip> with the actual path to the firmware archive.

You may release the button once the progress bar first appears.

The SPIKE Prime Hub and MINDSTORMS Robot Inventor Hub do not have a Bluetooth bootloader. It is recommended to install Pybricks using a Python script that runs on the hub. You can also flash the firmware manually using DFU.

Running Pybricks MicroPython programs

This compiles a MicroPython script and sends it to a hub with Pybricks firmware.

pybricksdev run --help

#
# ble connection examples:
#

# Run script on any Pybricks device
pybricksdev run ble demo/shortdemo.py

# Run script on the first device we find called Pybricks hub
pybricksdev run ble --name "Pybricks Hub" demo/shortdemo.py

# Run script on device with address 90:84:2B:4A:2B:75 (doesn't work on Mac)
pybricksdev run ble --name 90:84:2B:4A:2B:75 demo/shortdemo.py
       
#
# usb connection examples:
# NOTE: running programs via usb connection works for official LEGO firmwares only

# Run script on any Pybricks device
pybricksdev run usb demo/shortdemo.py

#
# Other connection examples:
#

# Run script on ev3dev at 192.168.0.102
pybricksdev run ssh --name 192.168.0.102 demo/shortdemo.py

Compiling Pybricks MicroPython programs without running

This can be used to compile programs. Instead of also running them as above, it just prints the output on the screen instead.

pybricksdev compile demo/shortdemo.py

pybricksdev compile "print('Hello!'); print('world!');"

This is mainly intended for developers who want to quickly inspect the contents of the .mpy file. To get the actual file, just use mpy-cross directly. We have used this tool in the past to test bare minimum MicroPython ports that have neither a builtin compiler or any form of I/O yet. You can paste the generated const uint8_t script[] directly ito your C code.

Additional Documentation

https://docs.pybricks.com/projects/pybricksdev (work in progress)

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pybricksdev-1.0.0a22.tar.gz (193.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pybricksdev-1.0.0a22-py3-none-any.whl (200.4 kB view details)

Uploaded Python 3

File details

Details for the file pybricksdev-1.0.0a22.tar.gz.

File metadata

  • Download URL: pybricksdev-1.0.0a22.tar.gz
  • Upload date:
  • Size: 193.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.6 CPython/3.8.12 Linux/5.11.0-1025-azure

File hashes

Hashes for pybricksdev-1.0.0a22.tar.gz
Algorithm Hash digest
SHA256 64112e3a27a456489a27cebab1bbf448ba49f022d3b7c0439355c103a8a7ed80
MD5 06cbf542ea61eba249958746874e39ba
BLAKE2b-256 d1c63b603add334a0a51d55e3e8d7df103d7346b15e8f6682892ba41bc4c20af

See more details on using hashes here.

File details

Details for the file pybricksdev-1.0.0a22-py3-none-any.whl.

File metadata

  • Download URL: pybricksdev-1.0.0a22-py3-none-any.whl
  • Upload date:
  • Size: 200.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.6 CPython/3.8.12 Linux/5.11.0-1025-azure

File hashes

Hashes for pybricksdev-1.0.0a22-py3-none-any.whl
Algorithm Hash digest
SHA256 637a536a931ba825356466717a26b5dcf56014dc38e58e8c96ebfce1316c9749
MD5 b8e2a1083dd92187ac2d0598a12c79cf
BLAKE2b-256 edb01d5b7dc5ee4918e87c787d5efe556fef98533db6c4ff2a8a9b6b18160e33

See more details on using hashes here.

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