Python CAN Bus USB Streaming API [+Grafana-MQTT Dashboards]
Need to stream CAN bus data in real-time via Python?
With our Python API you can easily integrate the CANsub or CANmod with the popular python-can library - for advanced data processing, custom integrations and automation workflows.
In this intro we outline key features and use cases, including e.g. streaming your data in real-time Grafana dashboards!
Note: For most use cases, the CANsub's webCAN software will suffice - Python is intended for more specialized requirements.
Pip install, then stream data in <5 lines of code
Send/receive raw CAN frames via the CANsub
Deploy on Windows and Linux (incl. Raspberry Pis)
Leverage the extensive python-can extension tools
Benefit from excellent docs and script examples
Our CANsub.2 and CANsub.4 let you send/receive CAN/CAN FD data over USB or Ethernet in real-time. This is often relevant in automotive/industrial OEM development, reverse engineering and CAN bus diagnostics. The CANsub supports 20,000+ frames/sec, 1 µs timestamps, on-device transmit jobs with 10 µs edge-based timing, hardware filters and galvanic isolation.
If your goal is sensor streaming rather than CAN frame streaming, our CANmod devices can also be used via USB to stream GPS/temperature/analog sensor data in real-time, e.g. the CANmod.gps and CANmod.temp. Note that you can also use the CANmod.router as a CAN-USB interface, though the CANsub is superior for this purpose.
webCAN is our recommended software tool for most use cases. It runs on the CANsub, meaning you simply open the software via your browser - no installation required. Further, CANsub enables you to both configure the device, stream raw/decoded CAN data, create visual plots and more - i.e. all your basic streaming needs.
In contrast, using Python is more complex - but enables workflows beyond webCAN:
- Scripted receive/transmit workflows (e.g. for conditional/dynamic transmission)
- Integrations like MQTT or cloud forwarding for remote dashboards and alerting
- Simulation rigs that mimic ECU behaviour
- CI and test pipelines
- Integration with NumPy / pandas / Grafana via custom code
- Sending/receiving CAN data via your command line (e.g. for LLMs) via cantools
In short: Use webCAN for 'everyday streaming tasks' and python-can when you need scripted or programmatic control - or when CAN streaming has to be embedded inside a larger automated system.
View data via CLI
View your raw CAN bus data via the command line (with zero code required) using the can-viewer tool (part of the cantools library) - ideal for LLM/AI access.
Log/convert data via CLI
Log/convert raw CAN data via the command line using the can-logger tool - with extensive export/import format support (MF4, CSV, LOG, TRC, ASC, ...) - incl. CSV format used by webCAN
Replay data via CLI
Easily load CANedge log files or CANsub webCAN CSV exports and replay them via the CANsub onto your CAN bus using the simple can-player tool
Receive/transmit raw CAN frames in scripts
Receive/transmit raw CAN frames in a few lines of code - enabling tons of powerful use cases, incl. e.g. dynamic/conditional communication flows
DBC decode data in real-time
Load your own DBC file(s) to decode data in real-time, enabling e.g. visualization, alerting, conditional logic and more
Leverage CAN protocol extensions
Benefit from the powerful extensions to python-can across protocols, including J1939, CANopen, ISO-TP, UDS, XCP and more
Build custom Python apps (e.g. Grafana-MQTT datasource)
The CANsub Intro shows how to build custom Python apps/integrations - e.g. CAN-to-MQTT (for Grafana dashboards), CAN plotting apps and more.
Try the Python API now!
Setup CAN based monitoring & alerting systems
Need to continuously monitor CAN based systems and automate alerts?
In many production/testing/development use cases, you may need to deploy automation scripts that record CAN data, DBC decode it and react according to certain patterns. For example, you may have a temperature-sensitive process where you could deploy one or more CANmod.temp units to measure temperatures, stream this data to a PC and send an alert if certain thresholds are crossed. Or, you could use a CANsub to record CAN bus data during e.g. an automotive lab test and script it to transmit certain CAN based commands when event X, Y or Z happens.
Visualize data in 100% free & customizable dashboards
Need to deploy customized dashboards for visualizing your data?
With the Python API you can easily integrate your CANsub/CANmod data streams with Grafana dashboards using the MQTT protocol. This lets you visualize DBC decoded data in beautiful and customizable dashboards. This can be used locally on the host PC as a development/diagnostic tool, or it can be port forwarded for remote access, e.g. for process monitoring. For plot visualization without code, see also our webCAN GUI.
Perform advanced CAN bus diagnostics/simulation
Need to perform tailored diagnostics of your CAN bus?
With the Python API, you gain far more granular control in your CAN bus diagnostics efforts, making it an excellent supplement to GUI tools like webCAN or SavvyCAN. For example, you can selectively extract specific CAN frames (or DBC decoded signals) of interest and perform targeted statistical analyses. Or, you can replay entire/partial log files by loading data recorded from a CANedge and outputting it onto your CAN bus via the CANsub. Replaying can be done quickly via the can-player tool, or with more granular control using Python scripts.
Create protocol-specific communication flows
Need to set up advanced and protocol-specific communication?
The python-can library offers a wide array of extensions, incl. for protocols like J1939, UDS, XCP, ISO-TP, CANopen and more. This lets you abstract away a lot of the code complexity required to work with a specific protocol, and lets you focus on writing the communication required for your use case. With this, there are practically no limits to what you can achieve, as long as you know your way around Python. Further, with the CANsub you can deploy advanced cross-channel logic, e.g. transmitting custom CAN frames on CAN 4 in response to certain CAN patterns on CAN 1.
FAQ
Yes, you can connect any number of CANsub and/or CANmod devices in parallel. Each USB-connected device is registered with a unique COM port, which can be referenced via the various command line tools and in your Python scripts. The CANsub also supports streaming over Ethernet, which is convenient when you need to access several units across a network. This is useful if you e.g. need to monitor multiple CAN buses in parallel, or if you need to hook up several CANmod sensor devices for monitoring.
We offer technical support on the basics, i.e. ensuring that you can get started with receiving/transmitting data as per our 'basic' script examples in the Python API documentation.
However, we do not offer technical support on custom scripts or general Python coding. Further, some of the demos we showcase (such as the Grafana-MQTT integration) come without support, though the documentation should make it fairly simple to set up.
Our CANedge, CANsub and CANmod devices all integrate with Python.
We commonly refer to this as the 'Python API'. To be more specific, the 'Python API' in this article refers to our integration of the CANsub/CANmod with the popular open source python-can project for the purpose of real-time streaming of data.
For the CANedge, you can see our separate Python MF4 API article, which focuses on how you can work with CANedge log files in Python using either our python-can integration or by creating a Parquet data lake.
As a supplement to the above Python packages, we also sometimes refer to processing Parquet data lakes in Python, see e.g. our intro to our MF4 decoders. This reflects the fact that we provide simple-to-use executables for DBC decoding CANedge log files to Parquet files. Python can be used to both run the executables (via sub processes) and analyze the Parquet files, which offers a very useful alternative route for analysing data, ideally suited for large-scale data processing.
Ready to analyze your CAN-USB data in Python?
Get your CANsub today!