tools – General purpose tools

Common tools for timing, data logging, and linear algebra.

Timing tools


Pauses the user program for a specified amount of time.


time (Number, ms) – How long to wait.

class StopWatch

A stopwatch to measure time intervals. Similar to the stopwatch feature on your phone.

time() int: ms

Gets the current time of the stopwatch.


Elapsed time.


Pauses the stopwatch.


Resumes the stopwatch.


Resets the stopwatch time to 0.

The run state is unaffected:

  • If it was paused, it stays paused (but now at 0).

  • If it was running, it stays running (but starting again from 0).

Input tools

read_input_byte() int | None

Reads one byte from standard input without blocking.


The numeric value of the byte read or None if no data is available.

Linear algebra tools

Changed in version 3.3: These tools were previously located in the pybricks.geometry module.

class Matrix(rows)

Mathematical representation of a matrix. It supports addition (A + B), subtraction (A - B), and matrix multiplication (A * B) for matrices of compatible size.

It also supports scalar multiplication (c * A or A * c) and scalar division (A / c).

A Matrix object is immutable.


rows (list) – List of rows. Each row is itself a list of numbers.


Returns a new Matrix that is the transpose of the original.


Returns a tuple (m, n), where m is the number of rows and n is the number of columns.

vector(x, y) Matrix
vector(x, y, z) Matrix

Convenience function to create a Matrix with the shape (2, 1) or (3, 1).

  • x (float) – x-coordinate of the vector.

  • y (float) – y-coordinate of the vector.

  • z (float) – z-coordinate of the vector (optional).


A matrix with the shape of a column vector.

cross(a, b) Matrix

Gets the cross product a × b of two vectors.

  • a (Matrix) – A three-dimensional vector.

  • b (Matrix) – A three-dimensional vector.


The cross product, also a three-dimensional vector.