Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Automotive for Python

PyPI Documentation

A library for synchronous and asynchronous CAN, ISO-TP, DoIP, UDS, CCP, and XCP, powered by the automotive Rust crate. The distribution and import name are both automotive. Rust handles adapter I/O, protocol framing, validation, and timing; Python provides reusable configuration objects, typed values, context managers, and documented services.

Requires CPython 3.11+. This directory contains the Python package, its Rust extension, examples, and Scapy ECU regression tests.

Read the Python documentation for the user guide, examples, and generated API reference.

Installation and development

Install the package from PyPI in your uv project:

uv add automotive

For development, run the following from the repository root. The Nix shell provides uv, the Rust toolchain, and native build dependencies:

nix develop
cd python
uv sync
uv run python examples/uds.py
uv check
uv format

uv check runs ty; uv format runs Ruff with default settings and a 120-character line length. uv sync installs the project and development tools; the lockfile records their versions. Use uv run maturin develop after changing Rust code when working directly in the installed development environment. For Rust formatting, run cargo fmt --all.

The Python extension always includes every adapter supported on its platform: SocketCAN on Linux, panda and PEAK USB adapters, and Vector and J2534 on Windows. Vendor drivers/DLLs and USB permissions remain necessary. The Rust crate retains feature flags for Rust applications.

DoIP over IPv4 and IPv6

await automotive.transports.doip.discover() triggers identification using IPv4 broadcast and normally collects unique vehicles for two seconds. Vehicles with incomplete VIN/GID synchronization and a valid VIN or GID add a five-second per-vehicle wait, then another identification request and collection window. Duplicate responses do not restart the synchronization timer. Connect to a result with await vehicle.connect(), or connect directly with await DoIP.connect("192.168.0.10", 0x1000). Pass the resulting transport to UDSClient as usual. No CAN adapter or administrator privileges are needed. DoIPConfig and DiscoveryConfig expose optional settings. IPv6 multicast uses DiscoveryConfig.ipv6(interface_index) with a portable numeric adapter index. await Discovery.listen() receives passive announcements without sending.

The matching blocking functions live in automotive.sync.transports.doip. See the DoIP API and async/sync examples. TLS and OEM authentication are not implemented.

For a directly connected ECU on Linux, configure the Ethernet adapter from the repository root, then run any of the four discovery combinations from python/:

sudo scripts/set_up_doip.sh eth0
cd python
uv run examples/doip.py --ipv4 --discovery active --local-address 169.254.0.1/16
uv run examples/doip.py --adapter eth0 --ipv6 --discovery active
uv run examples/doip.py --ipv4 --discovery passive
uv run examples/doip.py --adapter eth0 --ipv6 --discovery passive

The setup script defaults to tester addresses 169.254.0.1/16 and fe80::1/64. Override them with sudo scripts/set_up_doip.sh eth0 169.254.10.1/16 fe80::1234/64; use addresses distinct from the ECU and an IPv4 subnet matching its configuration. It enables IPv6, disables router advertisements/SLAAC, adds the static addresses and brings the adapter up. When NetworkManager is running, it first marks the adapter unmanaged so it retains these settings. Restore normal management after testing with sudo nmcli device set eth0 managed yes. Existing addresses/routes are retained; the static configuration lasts until reboot/reconfiguration. When iptables/ip6tables are available, it also allows incoming UDP ports 13400 and 49152–65535 on that adapter for announcements and discovery replies. These firewall rules last until a firewall reload or reboot. Unicast replies to broadcast/multicast requests may otherwise be dropped by a stateful firewall.

The examples read VIN through UDS DID 0xF190 on each discovered entity, using tester address 0x0E89 (override with --source-address 0x0E89). Active mode normally collects replies for two seconds, with the synchronization wait described above when needed. Passive mode listens until Ctrl+C; start it before powering up the ECU to receive unsolicited announcements. Active IPv4 requires --local-address, e.g. 169.254.0.1/16, to bind the source IP and derive the subnet broadcast. Passive IPv4 needs no local address: it listens on all interfaces, and diagnostic TCP connections follow OS routing. Incoming UDP port 13400 must be allowed on each receiving interface; the setup script opens the firewall only for the adapter passed to it. IPv6 requires --adapter to select the link-local multicast interface and retains link-local scopes. IPv4 needs no adapter name. Replace examples/doip.py with examples/sync/doip.py for the blocking version. The Rust example has the same options: cargo run --example doip -- --adapter eth0 --ipv6 --discovery active from the repository root. Rust resolves IPv6 adapter indices using Linux sysfs; the Python examples and library support all three desktop platforms.

Run uv run pytest tests/test_doip.py tests/test_uds.py tests/test_uds_sync.py -q for Scapy ECU tests on any platform; --run-vcan is not required.

Basic usage

Minimal setup retains the Rust defaults. Use CanAdapter() for automatic discovery, PeakAdapter() for default PEAK settings, or SocketCanAdapter("can0") to select a SocketCAN interface directly. Constructors open the device immediately:

import asyncio

from automotive.adapters import CanAdapter
from automotive.protocols.uds import DataIdentifier, UDSClient
from automotive.transports.isotp import IsoTP


async def main():
    adapter = CanAdapter()
    transport = IsoTP.from_id(adapter, 0x7A1)
    uds = UDSClient(transport)
    response = await uds.read_data_by_identifier(DataIdentifier.VIN)
    print(response)


asyncio.run(main())

Synchronous usage

The synchronous API mirrors the async module layout under automotive.sync. Use ordinary constructors, method calls, and receive iterators:

from automotive.sync.adapters import SocketCanAdapter
from automotive.sync.protocols.uds import DataIdentifier, UDSClient
from automotive.sync.transports.isotp import IsoTP

adapter = SocketCanAdapter("can0")
transport = IsoTP.from_id(adapter, 0x7A1)
uds = UDSClient(transport)
print(uds.read_data_by_identifier(DataIdentifier.VIN))

CanAdapter(), PeakAdapter(config), and the other named adapter classes live in automotive.sync.adapters. The import paths match their async counterparts:

Async module Sync module
automotive.adapters automotive.sync.adapters
automotive.adapters.j2534 automotive.sync.adapters.j2534
automotive.transports automotive.sync.transports
automotive.transports.isotp automotive.sync.transports.isotp
automotive.protocols.uds automotive.sync.protocols.uds
automotive.protocols.ccp automotive.sync.protocols.ccp
automotive.protocols.xcp automotive.sync.protocols.xcp
automotive.can automotive.sync.can
automotive.can.bitrate automotive.sync.can.bitrate
automotive.errors automotive.sync.errors

Both APIs share the same configuration classes, frames, enums, result types, and exceptions. These can be imported through either module hierarchy.

Hardware and subscriptions are released when their last owner is dropped. Both APIs expose a shared Transport base class accepted by UDSClient. IsoTP and J2534NativeIsoTP implement this interface. Future transports such as DoIP and HSFZ can use the same interface without depending on CAN or ISO-TP.

Transports, clients, and receivers retain their underlying resources, so they can outlive the adapter variable. For deterministic cleanup, use close() on synchronous resources or await aclose() on asynchronous resources. with and async with remain supported as optional cleanup patterns.

recv() subscribes immediately. Synchronous receivers support for and next(); async receivers support async for and anext(). Drop or close raw ISO-TP receivers before making UDS requests on the same transport. Native J2534 transports and reusable device handles have synchronous counterparts too.

adapter.recv_for(duration) subscribes immediately and returns an independent receiver including transmit echoes. Its timer and waiting start on the first anext() or async for iteration, so create it before sending. The sync API uses the same pattern with next() or for. The receiver closes when its duration ends and leaves existing recv() subscriptions unaffected:

responses = adapter.recv_for(0.1)
await adapter.send(request)
received = [frame async for frame in responses]

The synchronous equivalent is:

responses = adapter.recv_for(0.1)
adapter.send(request)
received = list(responses)

One background event loop runs the existing async implementation and shuts down at process exit. Adapter construction opens hardware synchronously in both APIs, including inside an async function; Rust releases the GIL during device opening. Use the async API for awaitable sends and receives in asyncio applications. Suppression scopes in the synchronous API are local to the calling thread and context. Ctrl+C interrupts a blocking wait; an active Rust UDS exchange still drains before the next request, matching async cancellation.

CCP

CCP 2.1 memory transfers on Classical CAN are supported through automotive.protocols.ccp and automotive.sync.protocols.ccp. Construct CCPClient(adapter, CCPConfig(tx_id=0x6EC, rx_id=0x6ED, byte_order="little")). Choose the adapter bus with bus and set timeout in seconds. Set byte_order to "little" or "big" to match the ECU; station addresses are always little endian. Connect directly to a known station, then use set_mta(), upload() and download() for RAM transfers, or short_upload() for reads at an explicit address. Transfer sizes are 1–5 bytes; download6() writes exactly six bytes. Each method sends one command. After active cancellation or timeout, reconnect and re-establish MTA before continuing. See the standalone examples/ccp.py and examples/sync/ccp.py for a 4 KiB flash read with hexdump output.

XCP

XCP over CAN, CAN FD, and Ethernet (TCP/UDP) is supported through automotive.protocols.xcp and automotive.sync.protocols.xcp.

Configuration

Reusable configs expose advanced settings without Rust-style builders:

import asyncio

from automotive.adapters import PeakAdapter, PeakConfig
from automotive.can import Identifier
from automotive.can.bitrate import BitrateSettings
from automotive.protocols.uds import DataIdentifier, UDSClient, UDSConfig
from automotive.transports.isotp import IsoTP, IsoTPConfig

adapter_config = PeakConfig(
    bitrate=BitrateSettings(
        bitrate=500_000,
        sample_point=0.8,
        data_bitrate=2_000_000,
        data_sample_point=0.8,
    ),
    tx_timeout=1.0,
)
transport_config = IsoTPConfig(
    tx_id=Identifier.extended(0x18DA10F1),
    fd=True,
    max_dlen=32,
    block_size=8,
    receive_separation_time_min=0.0003,
)
uds_config = UDSConfig(request_timeout=10.0, strict=True)


async def main():
    adapter = PeakAdapter(adapter_config)
    transport = IsoTP(adapter, transport_config)
    uds = UDSClient(transport, uds_config)
    print(await uds.read_data_by_identifier(DataIdentifier.VIN))


asyncio.run(main())

All Python durations are seconds. Omitting settings retains Rust defaults; explicit bitrate settings start without presets, so a nominal bitrate alone selects Classic CAN. Vector retains shared access and existing timing when no bitrate settings are supplied. resolved_bitrate reports the calculated timing; SocketCAN selects an existing OS-configured interface.

Payload inputs accept bytes, bytearray, and contiguous byte-oriented memoryview objects; payload results are bytes. Named codes are Python IntEnum members, raw numbers are accepted, and unknown received codes are preserved. Invalid arguments use Python's ValueError/TypeError/OverflowError; deadlines use TimeoutError; disconnects use ConnectionError. Protocol exceptions retain NRCs or full response bytes. See automotive.errors.

Receive subscriptions are created by recv() immediately: create one before sending, then use async for, anext(), and aclose(). Hardware, transports, and receivers also support async with. Drop or close raw ISO-TP receivers before using UDS on the same transport; raw CAN monitoring can run alongside UDS. UDS exchanges on a transport are serialized. A cancelled queued call does not transmit; an active cancelled exchange drains under the lock before the next call starts. Closing the parent interrupts dependent operations. Set request_timeout when an overall bound is needed, including repeated NRC 0x78. UDS retries idle transport receive timeouts on the same stream without resending the request or extending P2/P2*. IsoTPConfig.timeout need not exceed the UDS response waits; transmission and frame-reassembly timeouts still fail the request.

Use an ordinary context manager to suppress positive responses. Suppression supports nested scopes, restores its previous setting on exit, and is local to the current async task. Tasks created inside the scope inherit its context; already-running tasks are unaffected. Negative responses still raise errors.

with uds.suppress_positive_responses():
    await uds.tester_present()
await uds.tester_present()  # Requires a positive response again.

Examples and API documentation

The async Python examples and their counterparts in examples/sync/ mirror every Rust example, including CAN transmission, PEAK bitrate configuration, ISO-TP, UDS, and firmware queries. The synchronous firmware query visits ECUs sequentially; the async version queries them concurrently. Read installed API documentation using uv run python -m pydoc automotive.protocols.uds, or Python's help().

Run uv run python examples/can_sender.py to send one Classic CAN frame. Use uv run python examples/sync/can_sender.py for the synchronous version.

Run uv run python examples/configure_bitrate.py to configure a PEAK PCAN-USB FD adapter, or use examples/sync/configure_bitrate.py for the synchronous version.

End-to-end regression tests

On Linux, create vcan0 from the repository root:

scripts/set_up_vcan.sh

The setup script requires sudo. Then run:

cd python
uv run pytest --run-vcan -q

The regression suite starts the Scapy ECU scripts, verifies readiness, and closes/reaps them after each scenario. The shared UDS fixtures run the same async and blocking service, transfer, suppression, pending-response, validation, and timing tests over CAN ISO-TP and IPv4/IPv6 DoIP. The answering machines share UDS responses and fault cases in scripts/uds_ecu.py. CAN frame observations, adapter lifecycle, ISO-TP Classic/FD framing and flow control, and DoIP routing/discovery checks stay in their respective transport test files. Tests run serially on vcan0; do not run the Rust and Python virtual-CAN suites concurrently. Without --run-vcan, the CAN cases are skipped and the shared UDS suite still runs over both DoIP address families. Explicit CAN runs fail if prerequisites are unavailable.

Metadata

Release files for automotive 0.7.0a1

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

Source distribution (sdist)

Source distribution for automotive 0.7.0a1
File Size Uploaded Provenance Actions
automotive-0.7.0a1.tar.gz 380.7 kB Without provenance Details for automotive-0.7.0a1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for automotive 0.7.0a1
File Actions
automotive-0.7.0a1-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details for automotive-0.7.0a1-cp311-abi3-win_amd64.whl
automotive-0.7.0a1-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 abi3 Linux glibc 2.17+ x86-64 Details for automotive-0.7.0a1-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
automotive-0.7.0a1-cp311-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl CPython 3.11 abi3 Linux glibc 2.17+ ARMv7l Details for automotive-0.7.0a1-cp311-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
automotive-0.7.0a1-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.11 abi3 Linux glibc 2.17+ ARM64 Details for automotive-0.7.0a1-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
automotive-0.7.0a1-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details for automotive-0.7.0a1-cp311-abi3-macosx_11_0_arm64.whl

Total release size: 8.1 MB

Release files / automotive-0.7.0a1.tar.gz

Download URL automotive-0.7.0a1.tar.gz
Size 380.7 kB
Tags Source
SHA-256 checksum
How to use checksums
31851a61c82e28088a6c8ef1f850d71abc34656d0cedf55c126081f1a54e05b5
BLAKE2b-256 checksum
How to use checksums
640403760bdcb20bfe481bc2de5d1c91ea07c6036f6f7af7ab87f2f3a753ee3e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"NixOS","version":"26.11","id":"zokor","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / automotive-0.7.0a1-cp311-abi3-win_amd64.whl

Download URL automotive-0.7.0a1-cp311-abi3-win_amd64.whl
Size 1.5 MB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
37e69d27fcb8f7df5cc921fada52828d10fcc64c150066dcdc69d161e13c4d9c
BLAKE2b-256 checksum
How to use checksums
bf5babc29a7d603a257959cd982ea764c36a9b739838d11514104a8f0fdac586
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"NixOS","version":"26.11","id":"zokor","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / automotive-0.7.0a1-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL automotive-0.7.0a1-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.4 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
e8d324a1ae4bec9f7eab6fa8aa363760adb5a61d32d4956a03da7afac7400241
BLAKE2b-256 checksum
How to use checksums
f4569324e62d70874db721b74174ea68753f1d4450c1da8946ffafa361621cc4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"NixOS","version":"26.11","id":"zokor","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / automotive-0.7.0a1-cp311-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl

Download URL automotive-0.7.0a1-cp311-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Size 1.3 MB
Tags CPython 3.11 Linux glibc 2.17+ ARMv7l abi3
SHA-256 checksum
How to use checksums
eeff1850737c5940327eb73e676e2f3c3937b1754416b9a8c4b7c851677d2056
BLAKE2b-256 checksum
How to use checksums
fbba4dddb10542fade4cdd7da6e84a0d90f024d8e6852794d890b6caa67a320b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"NixOS","version":"26.11","id":"zokor","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / automotive-0.7.0a1-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL automotive-0.7.0a1-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 1.4 MB
Tags CPython 3.11 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
de15a3fdee7ad14ef1298f655bb28129d042996fe169dfcd3cb621e00aa1f829
BLAKE2b-256 checksum
How to use checksums
b3ed2b5765c7c9046ca3bda0bee8b2362a6feb24fa4c046f62aeb23deab2c617
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"NixOS","version":"26.11","id":"zokor","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / automotive-0.7.0a1-cp311-abi3-macosx_11_0_arm64.whl

Download URL automotive-0.7.0a1-cp311-abi3-macosx_11_0_arm64.whl
Size 2.2 MB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
24349acd187217b8acc8588b927ce357a657cb386d252ed697379e1f4d5fcf58
BLAKE2b-256 checksum
How to use checksums
f5a9a3ae728e42cb37455fa2ba48f621e5af5b6b9600806da0df89df92bebadf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"NixOS","version":"26.11","id":"zokor","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for automotive 0.7.0a1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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