python-can: CAN Bus Streaming API [+ Demo Showcases]

Python CAN bus USB Serial API Streaming

Need to stream CAN bus data in real-time via python-can?

Our CANsub CAN interfaces CANmod sensor-to-CAN modules come with plug & play support for the popular python-can library. This lets you rapidly deploy 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: See also the CANsub's webCAN software for GUI access.

Python CAN-USB Streaming API Script Integration with CANsub
Simple-to-use python-can USB streaming API SIMPLE-TO-USE

Pip install, then stream data in <5 lines of code

Receive/Transmit CAN bus data in real-time STREAM DATA

Send/receive raw CAN frames via the CANsub

DBC decode DBC DECODE

Easily DBC decode data to physical values

Windows/Linux python-can WINDOWS/LINUX

Deploy on Windows and Linux (incl. Raspberry Pis)

python-can ecosystem extensions ECOSYSTEM

Leverage the extensive python-can extension tools

API examples Python CAN-USB API EXAMPLES

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

python-can extensions protocols

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 python-can now!




Extend python-can with protocol-specific packages

The CANsub registers as a standard python-can interface (via python-can-cansub), so it works with the packages below that extend python-can with protocol-specific functionality.


cantools DBC decode and encode for python-can with the CANsub

cantools - DBC decode/encode

The cantools package lets you load a DBC file to decode raw CAN frames into physical values, and encode values back into frames, incl. J1939 PGNs and multiplexing. It also ships the handy can-viewer, can-logger and can-player command line tools. The package is also great for programmatic DBC editing/generation.



can-isotp ISO-TP transport protocol for python-can with the CANsub

can-isotp - ISO-TP transport protocol

The can-isotp package lets you handle the ISO-TP (ISO 15765-2) transport protocol to send and reassemble multi-frame payloads larger than 8 bytes. This is the foundation for the OBD2 and UDS request/response flows used in vehicle diagnostics. The package also supports ISO-TP with extended addressing.



udsoncan UDS diagnostics for python-can with the CANsub

udsoncan - UDS diagnostics

The udsoncan package lets you communicate with ECUs via UDS (ISO 14229) diagnostic services on top of ISO-TP, e.g. ReadDataByIdentifier, DTC readout and session control. Ideal for structured diagnostics of cars, EVs and electronic control units.



can-j1939 SAE J1939 stack for python-can with the CANsub

can-j1939 - SAE J1939 stack

The can-j1939 package lets you work with the SAE J1939 higher-layer protocol used in heavy-duty vehicles, incl. PGN handling, the J1939 transport protocol for multi-packet messages and address claiming. You can combine this with cantools for PGN/SPN decoding and even DM1 handling.



canopen master and node for python-can with the CANsub

canopen - CANopen master/node

The canopen package lets you deploy the CANsub as a CANopen (CiA 301) master or node with NMT, SDO and PDO support, and load EDS files directly. Ideal for industrial machinery, robotics and motion control applications.



pyxcp XCP measurement and calibration for python-can with the CANsub

pyxcp - XCP measurement & calibration

The pyxcp package lets you set up XCP measurement and calibration over CAN, incl. dynamic DAQ list initialization to stream internal ECU variables. Combine it with an A2L file (via pya2l) to resolve measurement addresses and data types.


See our CANsub Intro for full python-can code examples per protocol.




Docs for AI

Want to build CANsub apps faster with AI?

We make our documentation available in LLM-friendly plain-text formats, so you can provide them as context to AI coding tools like Claude Code or ChatGPT and let them do the heavy lifting.

For a real-world example, see our AI CAN sniffer article, where an AI agent reverse engineers proprietary CAN signals using the CANsub, python-can and a custom Claude Code skill.

You can also find multiple python-can 'demo examples' showcasing this in the CANsub Intro.

learn more



Use case examples

Below are various examples of how python-can can be used in practice:


CANsub as a python-can CAN interface for OEM end-of-line (EOL) test automation

CAN interface for OEM end-of-line (EOL) testing

Need a reliable CAN interface for automated end-of-line (EOL) test benches?

On OEM production lines, end-of-line test stations validate each unit's CAN communication before it ships. Since the CANsub registers as a standard python-can interface, it drops straight into your existing test automation scripts and can directly replace legacy CAN interfaces - with no need to rewrite your test logic. This also lets you upgrade EOL setups from USB to secure Ethernet connectivity with optional mTLS user authentication so only authorized test stations can reach the device. The CANsub offers pro specs like 2-4 x CAN FD, 20K+ FPS, edge-based RX/TX timestamps at 1 µs resolution, edge transmit sequences with 10 µs inter-message precision, and more - ideal for deterministic and repeatable automated testing.



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.

Monitor CAN bus data in real-time via USB and Python


CANsub 4 x CAN bus USB/Ethernet interface streaming to Grafana via MQTT

Visualize data in 100% free & customizable dashboards

Need to deploy customized dashboards for visualizing your data?

With python-can 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 python-can, 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.

Diagnose CAN bus data via Python with the CANsub, incl. log file replay


Leverage higher-layer protocol extensions for python-can with the CANsub

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. The CANsub operates as a network device over both USB and Ethernet - not as a legacy COM-port device. Connecting via USB automatically creates a virtual network adapter (no drivers to install), and Ethernet exposes the same network interface. This makes the CANsub OS/platform agnostic and lets you reach one or many devices across a network.

Each device is addressable via a unique hostname - aabbccdd-usb.local over USB or aabbccdd-eth.local over Ethernet (where aabbccdd is the device-ID printed on the label). In python-can, every CAN channel then has its own URL-style endpoint built from this hostname plus a 1-based channel index, e.g. aabbccdd-usb.local@1 for channel 1. You open each channel as its own python-can bus, so you can run multiple channels - and multiple devices - in parallel.

You do not need to hardcode these endpoints. The python-can-cansub package supports mDNS discovery to auto-detect all connected CANsub devices / channels (across USB and Ethernet) and return ready-to-use configs that you pass in your script.


Every received and transmitted frame is timestamped by the CANsub itself at 1 µs resolution, sampled on the CAN bus edge (the frame's start-of-frame) rather than on your PC's clock. Timestamp accuracy therefore does not depend on client-side/host or network timing, which is critical for precise timing analysis and correlation.


The CANsub supports two transmit mechanisms, both available in python-can:

  • Edge-based transmit sequences: Deployed as on-device 'jobs' (via bus.send_periodic()). The device generates the timing on the edge, giving very precise inter-message timing (down to 10 µs) that is independent of client/network latency. The sequence must follow the structural limits of these jobs (per the OpenAPI description), so they suit more static, periodic sequences - ideal when latency between device and client is a challenge, e.g. over WiFi or VPN-based LTE
  • WebSocket transmit frames: Sent frame-by-frame from your script (via bus.send()). Fully flexible and completely controlled in Python, but the timing is determined client-side and is therefore subject to host/network latency

In short: Use edge-based sequences for precise, repeatable periodic transmission (especially over high-latency links), and WebSocket frames when you need dynamic, script-driven control.


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-can 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.


No. python-can is a popular open source Python library for CAN bus communication, not something we invented. Instead of building a custom API, we make the CANsub work directly with python-can: Our python-can-cansub package registers the CANsub as a standard python-can interface.

This means the CANsub plugs straight into the entire python-can ecosystem, so all of its tools, add-on packages and existing scripts work out of the box, with no lock-in to a proprietary API.

For working with CANedge log files in Python, see our separate Python MF4 API article, which covers our python-can integration and the Parquet data lake route.


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 script your CAN bus with python-can?

Get your CANsub today!







Recommended for you