Package: pybricksdev
Pybricks tools & interface libraryThis is a package with tools for Pybricks developers. For regular users we
recommend thePybricks Codeweb IDE.This package contains both command line tools and a library to call equivalent
operations from within a Python script.InstallationPython Runtimepybricksdevrequires Python 3.8 or higher.For Windows, use theofficial Python installeror theWindows Store.For Mac, use theofficial Python installeror Homebrew (brew install python@3.8).For Linux, use the distro providedpython3.8or if not available, use a Python
runtime version manager such asasdforpyenv.Command Line ToolWe recommend usingpipxto runpybricksdevas a command line tool. This
ensures that you are always running the latest version ofpybricksdev.We also highly recommend installingpipxusing a package manager such asapt,brew, etc. as suggested in the officialpipx installationinstructions.Then usepipxto runpybricksdev:pipx run pybricksdev ...If you don't like typingpipx run ...all of the time, you can installpybrickdevwith:pipx install pybricksdevThen you can just type:pybricksdev run ...And check for updates with:pipx upgrade pybricksdevWindows usersIf you are using thePython Launcher for Windows(installed by default with
the official Python installer), then you will need to usepy -3instead
ofpython3.py -3 -m pip install --upgrade pip # ensure pip is up to date first
py -3 -m pip install pipx
py -3 -m pipx run pybricksdev ...Linux USBOn Linux,udevrules are needed to allow access via USB. Thepybricksdevcommand line tool contains a function to generate the required rules. Run the
following:pipx run pybricksdev udev | sudo tee /etc/udev/rules.d/99-pybricksdev.rulesLibraryTo installpybricksdevas a library, we highly recommend using a virtual
environment for your project. Our tool of choice for this ispoetry:poetry env use python3.8
poetry add pybricksdevOf course you can always usepipas well:pip install pybricksdev --preUsing the Command Line ToolThe following are some examples of how to use thepybricksdevcommand line tool.
For additional info, runpybricksdev --help.Flashing Pybricks MicroPython firmwareTurn on the hub, and run:pipx run pybricksdev flash <firmware.zip>Replace<firmware.zip>with the actual path to the firmware archive.Running Pybricks MicroPython programsThis compiles a MicroPython script and sends it to a hub with Pybricks
firmware.pipx run pybricksdev run --help

#
# ble connection examples:
#

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

# Run script on the first device we find called Pybricks hub
pipx run 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)
pipx run 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
pipx run pybricksdev run usb demo/shortdemo.py

#
# Other connection examples:
#

# Run script on ev3dev at 192.168.0.102
pipx run pybricksdev run ssh --name 192.168.0.102 demo/shortdemo.pyCompiling Pybricks MicroPython programs without runningThis can be used to compile programs. Instead of also running them as above,
it just prints the output on the screen instead.pipx run pybricksdev compile demo/shortdemo.py

pipx run pybricksdev compile "print('Hello!'); print('world!');"This is mainly intended for developers who want to quickly inspect the
contents of the.mpyfile. To get the actual file, just usempy-crossdirectly. 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 generatedconst uint8_t script[]directly ito your C code.Additional Documentationhttps://docs.pybricks.com/projects/pybricksdev(work in progress)