How danielt/autosar-data-py works
1. Repository purpose
This project provides Python bindings for the Rust autosar-data library. The core job is to load, inspect, validate, modify, and write AUTOSAR ARXML models from Python while keeping the heavy model logic in Rust via PyO3.
2. Two-layer architecture
The repository is split into a Rust implementation layer under src/ and a Python packaging/API layer under python/autosar_data/. The Python side is mostly a thin, typed facade; the Rust side owns the model, parsing, validation, and serialization behavior.
3. Core model layer
The foundational Rust modules are model.rs, arxmlfile.rs, element.rs, specification.rs, and version.rs. Together they define the in-memory AUTOSAR document model, element tree behavior, file membership, version awareness, and schema/specification handling.
4. Generic ARXML tree operations
element.rs and related abstractions support common operations seen in the README: create sub-elements, set attributes, resolve references, navigate by path, and manage which elements belong to which file. This is the central boundary between generic XML-like structure and AUTOSAR-specific semantics.
5. AUTOSAR abstraction layer
Most domain logic sits under src/abstraction/. This layer maps the generic element model onto AUTOSAR concepts such as packages, signals, PDUs, ports, interfaces, ECU configuration, and systems. It is organized by domain rather than by file format concerns.
6. Communication subsystem
src/abstraction/communication/ is the largest domain area and models AUTOSAR communication artifacts. It is subdivided into:
- clusters: CAN, Ethernet, FlexRay, LIN
- controllers: bus controller definitions per network type
- frames and PDUs
- transport layers: CAN TP, DoIP TP, FlexRay TP/AR TP
- network management
- physical channels and Ethernet-specific variants such as SOME/IP, socket addresses, and network endpoints
This domain is where most cross-references and protocol-specific relationships live.
7. Datatype subsystem
src/abstraction/datatype/ models AUTOSAR application data types, base types, implementation types, compu methods, mappings, and value representations. This is the type system that underpins signal and interface data descriptions elsewhere in the model.
8. Software component subsystem
src/abstraction/software_component/ captures AUTOSAR software components, ports, connectors, interfaces, internal behavior, and mode-related concepts. It is the boundary for application-level composition and RTE-facing modeling.
9. ECU configuration and system mapping
src/abstraction/ecu_configuration/ handles ECU configuration definitions and values, while src/abstraction/system/ contains system mapping. These modules represent the configuration side of AUTOSAR: parameter definitions, references, instantiated values, and mappings between system and component/communication structures.
10. Python API surface
The Python package in python/autosar_data/ mirrors the Rust API in a distributable form. It includes .pyi stub files and py.typed, so consumers get type-aware IDE support. The public Python entry point exposes the AUTOSAR model operations shown in the README.
11. Validation and versioning
Validation is built into the load and mutation flow, with strict vs non-strict loading behavior described in the README. Version support is explicit and spans AUTOSAR 4.0.1 and newer, which influences parsing, allowed attributes, and element availability.
12. Data flow
The main runtime flow is: Python code calls into the Rust-backed model → ARXML is loaded or created → abstraction modules materialize AUTOSAR concepts on top of generic elements → references and constraints are validated → the model is serialized or written back to one or more ARXML files.
13. Tests and quality gates
The test/ directory contains Python integration-style tests for each major abstraction area, plus core model/file/specification tests. CI is handled by GitHub Actions workflows for test execution and pages/docs publication, which suggests the API docs are part of the project’s deliverable surface.
14. Documentation boundary
docs/ and mkdocs.yml form the architecture-level reference for the public API, with separate docs for abstraction, communication, datatype, ECU configuration, and software component APIs. This mirrors the source tree and reinforces the module boundaries exposed to users.
Main entry points: abstraction/mod.rs Abstraction · lib.rs PyO3 lib · model.rs Model · software_component/mod.rs Software components
Components 20
Python API
Typed Python facade and package entry points
- autosar_data · Public Python entry point for the library
python/autosar_data/__init__.py - Abstraction API · Python facade for AUTOSAR domain modules
python/autosar_data/abstraction/__init__.py - Comm API · Python communication-domain bindings
python/autosar_data/abstraction/communication/__init__.py - Datatype API · Python datatype-domain bindings
python/autosar_data/abstraction/datatype/__init__.py - ECU API · Python ECU configuration bindings
python/autosar_data/abstraction/ecu_configuration/__init__.py - SWC API · Python software-component bindings
python/autosar_data/abstraction/software_component/__init__.py
Rust Core
PyO3-backed core model and serialization layer
- PyO3 lib · Rust crate entry point exposed to Python
src/lib.rs - Model · In-memory AUTOSAR document model and operations
src/model.rs - Elements · Generic element tree, attributes, refs, and paths
src/element.rs - ARXML files · File membership and write-back boundaries
src/arxmlfile.rs - Spec & version · Specification rules and AUTOSAR version handling
src/specification.rs
AUTOSAR Abstractions
Domain-specific AUTOSAR modeling layers built on generic elements
- Abstraction · AUTOSAR domain mapping on top of generic elements
src/abstraction/mod.rs - Communication · Networks, frames, PDUs, transport, and channels
src/abstraction/communication/mod.rs - Datatypes · Application and implementation type system
src/abstraction/datatype/mod.rs - Software components · Ports, interfaces, behavior, and connectors
src/abstraction/software_component/mod.rs - ECU config · Definition and instantiated ECU configuration values
src/abstraction/ecu_configuration/mod.rs - System mapping · Mapping between systems, components, and communication
src/abstraction/system/mod.rs
Connections 26
- autosar_data → PyO3 lib: imports · Python entry point is backed by the Rust extension
- Abstraction API → Abstraction: wraps · Python abstraction API mirrors Rust domain modules
- Comm API → Communication: wraps · Communication bindings expose Rust communication abstractions
- Datatype API → Datatypes: wraps · Datatype bindings expose Rust datatype abstractions
- ECU API → ECU config: wraps · ECU configuration bindings expose Rust ECU abstractions
- SWC API → Software components: wraps · Software component bindings expose Rust SWC abstractions
- PyO3 lib → Model: exposes · Rust crate exports the core model API to Python
- PyO3 lib → Elements: exposes · Rust crate exports generic tree operations
- PyO3 lib → ARXML files: exposes · Rust crate exports ARXML file handling
- PyO3 lib → Spec & version: exposes · Rust crate exports schema and version behavior
- Model → Elements: uses · Model is built on the generic element tree
- Model → ARXML files: uses · Model tracks file membership and serialization boundaries
- Model → Spec & version: checks · Model behavior is constrained by spec and version
- Abstraction → Communication: contains · Domain layer includes communication modeling
- Abstraction → Datatypes: contains · Domain layer includes datatype modeling
- Abstraction → Software components: contains · Domain layer includes software component modeling
- Abstraction → ECU config: contains · Domain layer includes ECU configuration modeling
- Abstraction → System mapping: contains · Domain layer includes system mapping
- Communication → Datatypes: references · Communication artifacts depend on data types and mappings
- Software components → Communication: connects to · Software components interact through communication interfaces and connectors
- Software components → Datatypes: typed by · Ports and interfaces are described using datatype definitions
- ECU config → System mapping: maps into · ECU configuration participates in system mapping
- Docs → autosar_data: documents · Docs describe the public Python-facing API
- Tests → autosar_data: covers · Integration tests exercise the package surface
- CI → Tests: runs · CI executes the test suite
- CI → Docs: publishes · CI includes documentation/site publication