Skip to content

About

Command line tools for Pybricks

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

Pybricks Tools

Run Python on your Pybricks hub, from your computer.

A terminal choosing a hub from a list and running a program on it

Install it with uv:

uv tool install pybricks-cli

Then switch a hub on and pick it off the list:

pb connect --scan
pb run -c "
from pybricks.hubs import CityHub
from pybricks.parameters import Color
from pybricks.tools import wait

hub = CityHub()
for hue in range(0, 360, 2):
    hub.light.on(Color(hue))
    wait(20)
"

CityHub is the class for that kind of hub; use PrimeHub, TechnicHub, InventorHub, EssentialHub or MoveHub for yours.

The hub stays connected after the command finishes. So the second pb run starts instantly, and so does the hundredth — edit, run, edit, run, with no waiting for Bluetooth in between. It also means the hub does not switch itself off while you are thinking, the way one nothing is connected to does.

Once a program outgrows one command, put it in a file:

pb run my_robot.py

And the same hub is there from your own Python:

async with pb_client.connect() as pb:
    await pb.connect_hub(name="Rover")
    await pb.run_program(await pb_client.compile_script(Path("my_robot.py")))

Status: beta. Commands and APIs may still change before 1.0.0.

Documentation · Contributing

About

Command line tools for Pybricks

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages