Skip to main content

gsusb-canfd (Python)

Part of the gsusb-canfd project. Python implementation of the library: a userspace gs_usb CAN FD driver built directly on pyusb/libusb. It speaks the same wire protocol as the C++ library in this repository, so the two are interchangeable.

It does not depend on the gs_usb / python-can packages. Those assume the candleLight reference endpoints (OUT = 0x02) and only configure classic CAN timing, so they cannot talk to adapters that use different bulk endpoints or CAN FD data-phase timing through GS_USB_BREQ_BT_CONST_EXT / DATA_BITTIMING. This package handles both.

Install

pip install gsusb-canfd        # from PyPI
# or, to work on the package itself:
pip install ./python

The distribution is named gsusb-canfd; the import name is gsusb_canfd.

Requires libusb-1.0 at runtime (brew install libusb, apt install libusb-1.0-0-dev).

Use

from gsusb_canfd import BusConfig, CanFdBus, CanFrame

bus = CanFdBus()
with bus:
    bus.configure(BusConfig(bitrate=1_000_000, sample_point=0.80,
                            data_bitrate=5_000_000, data_sample_point=0.75,
                            fd=True))
    bus.send(CanFrame(id=0x501, data=bytes([0x00, 0x02, 0x50, 0x01]),
                      fd=True, brs=True))
    while True:
        frame = bus.receive(timeout=0.5)
        if frame and not frame.echo and frame.id == 0x481:
            print(frame)

Extended frames: set id > 0x7FF or CanFrame(extended=True).

Async receive (callback on a background thread):

bus.start(lambda frame: print(frame))
...
bus.stop()

Devices

from gsusb_canfd import scan_adapters

for i, adapter in enumerate(scan_adapters()):
    print(i, adapter.name(), f"{adapter.vendor_id:04X}:{adapter.product_id:04X}",
          adapter.serial)

Select one with a DeviceSelector (vid, pid, index, channel, serial, product). By default any gs_usb adapter is auto-discovered (known USB ids plus descriptor heuristics); pass explicit vid/pid to pin one. On devices with several CAN channels, channel selects which one (bus.channel_count() reports the count).

CLI

gsusb-canfd list

gsusb-canfd monitor --bitrate 1000000 --sample-point 0.80 \
                    --data-bitrate 5000000 --data-sample-point 0.75 \
                    --trigger --trigger-id 501 --trigger-data 00025001 \
                    --count 20

gsusb-canfd send --classic 123 1122334455667788

Hardware demo

examples/canfd_demo.py mirrors the C++ demo: it prints the adapter capabilities and negotiated timing, sends a trigger on 0x501, and reports responses on 0x481 with a periodic frame rate.

python examples/canfd_demo.py --seconds 6
python examples/canfd_demo.py --monitor --seconds 5
python examples/canfd_demo.py --all --all-frames

Tests

The protocol logic (bit timing, DLC mapping, frame codec) is pure Python and is covered by unit tests that need no hardware:

pip install -e './python[dev]'
pytest python/tests

Releasing

See PUBLISHING.md; the version lives in src/gsusb_canfd/_version.py.

Metadata

Release files for gsusb-canfd 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gsusb-canfd 0.1.1
File Size Uploaded
gsusb_canfd-0.1.1.tar.gz 16.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gsusb-canfd 0.1.1
File Interpreter ABI Platform
gsusb_canfd-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 31.4 kB

Release files / gsusb_canfd-0.1.1.tar.gz

Download URL gsusb_canfd-0.1.1.tar.gz
Size 16.8 kB
Tags Source
SHA-256 checksum
How to use checksums
85779188702de7b75bebaaedc720fdfc03810b4936bdf71353298406aafc9400
BLAKE2b-256 checksum
How to use checksums
255d4d9f9c98e536e46f2691ed10787949242e65e4d8e5d6486ed466709a2ed7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 19, 2026.

Transparency log

Release files / gsusb_canfd-0.1.1-py3-none-any.whl

Download URL gsusb_canfd-0.1.1-py3-none-any.whl
Size 14.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2f96068485bb2e72fa3e4b8cb65950cc7e573f2978b9404a49908461f5ef1340
BLAKE2b-256 checksum
How to use checksums
04f44f6c83613d1f6c6ec3515e9899b986e6e61ded626666b6cfe71a1e82ee62
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 19, 2026.

Transparency log

Release history Release notifications | RSS feed

0.1.3

2 release files

0.1.2

2 release files

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page