Skip to main content

python-can backend for can-hub: remote CAN interfaces over unix/tcp/tls/quic

Project description

python-can-hub

Native python-can backend for can-hub: consume remote CAN interfaces exported by can-hub agents, directly over the binary protocol — unix socket, plain TCP, TLS or QUIC, with mTLS identity and TOFU pinning on the encrypted transports. No bridge process in between.

import can

bus = can.Bus(
    interface="canhub",
    channel="truck42/can0",
    url="quic://hub.example.com:7227",
)
bus.send(can.Message(arbitration_id=0x123, data=b"\xDE\xAD\xBE\xEF"))
for message in bus:
    print(message)
  • channel: namespaced interface agent/iface (or the numeric id from can-hub-client list).
  • url: omit to connect to the local hub unix socket.
  • state_dir: client TLS identity + pin store location (tls/quic).
  • receive_own_messages: standard python-can echo semantics.
  • reliable: carry the channel on a dedicated reliable QUIC stream (lossless, ordered) instead of the lossy datagram plane. Needs a quic:// url and a hub that advertises the capability; otherwise the open fails.

Write access follows the hub client ACLs: if the ACL grants read-only, the bus opens read-only and send() raises.

Listing interfaces

CanHubBus.list_interfaces() asks a hub for the interfaces it exports. Each entry is a python-can config dict you can splat straight into can.Bus:

from canhub import CanHubBus
import can

for config in CanHubBus.list_interfaces(url="quic://hub.example.com:7227"):
    print(config["channel"])          # e.g. "can-agent/can0"
bus = can.Bus(**CanHubBus.list_interfaces()[0])   # first interface, local hub

It accepts the same connection arguments as the bus (url, identity_cert, identity_key, hub_fingerprint, state_dir); omit url to query the local hub unix socket.

This also wires python-can's discovery: can.detect_available_configs("canhub") returns the same dicts. With no explicit target it reads the connection from the environment — CANHUB_URL, CANHUB_STATE_DIR, CANHUB_IDENTITY_CERT, CANHUB_IDENTITY_KEY, CANHUB_HUB_FINGERPRINT — falling back to the local hub unix socket. So CANHUB_URL=quic://hub.example.com:7227 points discovery at a remote host without any code.

The wheel bundles libcanhub.so with the TLS/QUIC stack linked in statically; the only runtime dependency is glibc.

Testing

The unit tests stub the native library, so they run without a build:

pip install -e python/.[test]
pytest python/tests

The backend is also exercised end-to-end against real binaries (recv, send, list_interfaces, and can.detect_available_configs discovery) by test/e2e/tests/python_can.robot; run the whole bench with make e2e.

Building from source

./scripts/build-python-wheel.sh        # host arch, glibc-tagged (local dev)
pip install python/dist/*.whl

Distributable manylinux wheels are built per architecture in a manylinux container and repaired by auditwheel (needs docker, plus QEMU binfmt for the cross arches):

./scripts/build-python-wheel.sh x86_64   # python/dist/x86_64/*.whl
./scripts/build-python-wheel.sh aarch64
./scripts/build-python-wheel.sh armv7l

The release workflow builds these three on native runners (aarch64/armv7l on the arm64 hosted runner, no QEMU) plus a cross-compiled win_amd64 wheel, and publishes all four to PyPI on a v* tag.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

python_can_hub-0.2.6-py3-none-win_amd64.whl (2.4 MB view details)

Uploaded Python 3Windows x86-64

python_can_hub-0.2.6-py3-none-manylinux_2_28_armv7l.manylinux_2_31_armv7l.whl (2.6 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ ARMv7lmanylinux: glibc 2.31+ ARMv7l

python_can_hub-0.2.6-py3-none-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl (3.1 MB view details)

Uploaded Python 3manylinux: glibc 2.26+ x86-64manylinux: glibc 2.28+ x86-64

python_can_hub-0.2.6-py3-none-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (3.4 MB view details)

Uploaded Python 3manylinux: glibc 2.26+ ARM64manylinux: glibc 2.28+ ARM64

File details

Details for the file python_can_hub-0.2.6-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for python_can_hub-0.2.6-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 49a7ec4b92fc5c1a0133d23b341d7c964aedbd69e4bf998c7c089cfbc3a3fd8c
MD5 3815b890f7aefcebbcc61e90f589f6f8
BLAKE2b-256 a6750945ab63ad7caef948131c481ad820823da6da9a5e8633a5e4ec4bc9f098

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_can_hub-0.2.6-py3-none-win_amd64.whl:

Publisher: release.yml on can-hub-io/can-hub

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file python_can_hub-0.2.6-py3-none-manylinux_2_28_armv7l.manylinux_2_31_armv7l.whl.

File metadata

File hashes

Hashes for python_can_hub-0.2.6-py3-none-manylinux_2_28_armv7l.manylinux_2_31_armv7l.whl
Algorithm Hash digest
SHA256 54c635c7f0fa13d05e0f2c17058901f85de5550f849a46cae110a1557b601335
MD5 3224c38a39663ecccdb047ce6bd26685
BLAKE2b-256 27ad62d37071c5b502863599067589994faf3f1d9366ec631c0225c4fa944225

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_can_hub-0.2.6-py3-none-manylinux_2_28_armv7l.manylinux_2_31_armv7l.whl:

Publisher: release.yml on can-hub-io/can-hub

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file python_can_hub-0.2.6-py3-none-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for python_can_hub-0.2.6-py3-none-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 65a7f7e544cc26ac42dc420b54f7bd948260507efd83c5abfe48c8625414f47b
MD5 1defb80dd40bd56648d3582adef3a92d
BLAKE2b-256 b43a9c32ce1d449e54fb413ef0fa13d65b6d07e1668c23320791a8ec64c7758b

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_can_hub-0.2.6-py3-none-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release.yml on can-hub-io/can-hub

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file python_can_hub-0.2.6-py3-none-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for python_can_hub-0.2.6-py3-none-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 a06ca24ddcf16fcc93fce4c0b2ff951407c31f324f9c38e68f3c8dbb66b27bb2
MD5 1f0bf77bdf1f33aff392964b46f20cbd
BLAKE2b-256 29b46ca095f435d542774400613acbd0c68f5b1168ccbcc059c7de472abe1b73

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_can_hub-0.2.6-py3-none-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl:

Publisher: release.yml on can-hub-io/can-hub

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page