Skip to main content

Python

Connect directly to Foxglove or play back local data recorded with the Python SDK.

Install the SDK

The SDK is distributed through PyPI. You can get started with a new project or use Foxglove from a notebook.

Install foxglove-sdk from PyPI: https://pypi.org/project/foxglove-sdk

pip install foxglove-sdk

The exact installation will depend on your package manager; here's an example using poetry.

poetry new example
poetry add foxglove-sdk

Live data

Log messages from Python

Create a new file in your project (for example, src/example/main.py)

import foxglove
import time

foxglove.start_server()

while True:
foxglove.log("/hello", {"time": time.time()})
time.sleep(0.03)

Run the script

Run the script to start logging. Following the poetry example above, you can run the following command from the "example" directory:

poetry run python src/example/main.py

Connect

In Foxglove, select "Open connection" from the dashboard or left-hand menu.

Select open connection

Select "Foxglove WebSocket" in the "Open a new connection" dialog, then click "Open" to accept the default connection string:

Foxglove WebSocket dialog

Local data

Recording data to a file

The SDK can also log data to disk. Let's augment the example above to also produce an MCAP file which can later be opened in Foxglove:

import foxglove
import time

foxglove.start_server()

# Keep a reference to the mcap. It will automatically close the file when the program exits, but
# we could also close it manually with `mcap.close()`.
mcap = foxglove.open_mcap("example.mcap")

while True:
foxglove.log("/hello", {"time": time.time()})
time.sleep(0.03)

Viewing data from a file

Open your recording(s) directly from your computer by:

  • Dragging and dropping them into Foxglove
  • Using Cmd/Ctrl + o
  • Clicking Open local file(s) in the app

Local file dialog

note

When opening multiple files, Foxglove will display the data as a single merged timeline. The files must be of the same format.

Explore your data

Your data is now available for exploring in Foxglove. Add some panels to begin visualizing what your robot is seeing and producing. Not sure where to start? Try adding a Raw Messages panel, Plot panel, or 3D panel.