Skip to main content

pyarx

pyarx is a modern, declarative, Python-based IDL (Interface Definition Language) and compiler designed to translate software architectures, interfaces, and data types into standardized, fully-conforming Adaptive AUTOSAR ARXML and JSON Schema representations.

Instead of writing thousands of lines of verbose, low-level XML or using highly boilerplate metamodel scripts, you can specify your entire system in clean, readable Python and compile it instantly.


Elegant Declarative API

pyarx uses native Python 3 subclassing and type annotations to declare structured types, enumerations, service interfaces, events, and methods.

from typing import Optional, Annotated
import enum
import dataclasses
from pyarx import (
    Struct,
    Enum,
    ServiceInterface,
    UInt16,
    Float32,
    Array,
    Vector,
    event,
    field,
    raises,
    namespace,
)

# 1. Standard Python Enums are supported natively
class SystemStatus(enum.Enum):
    OK = 0
    DEGRADED = 1
    CRITICAL = 2

# 2. Modern struct type declaration with limits and defaults
class GpsLocation(Struct):
    latitude: Annotated[Float32, "min=-90.0", "max=90.0", "unit=deg"]
    longitude: Annotated[Float32, "min=-180.0", "max=180.0", "unit=deg"]
    altitude: Float32 = 0.0

# 3. Standard dataclasses are automatically mapped to Structs
@dataclasses.dataclass
class CabinClimate:
    target_temp: float = 22.0
    fan_speed: int = 3
    air_quality: Optional[Annotated[int, "min=0", "max=500"]] = None

# 4. Service Interfaces with Events, Fields, and Methods
@namespace("car.comfort", cpp="car::comfort::service")
class CabinService(ServiceInterface):
    
    # Publish-Subscribe Event payload
    @event
    def on_climate_changed(self) -> CabinClimate:
        pass

    # Constrained field with notifications
    @field(min=0, max=100, unit="%", has_notifier=True)
    def ambient_brightness(self) -> UInt16:
        pass

    # Method showcasing arrays/vectors and standard types
    def SetRecentRoutes(self, routes: Vector[GpsLocation, 10]) -> bool:
        pass

Key Features

  • Standard Python Type Support: Declare your IDL fields and structures directly with standard library @dataclass, NamedTuple, and enum.Enum classes. Under the hood, pyarx automatically wraps them as AUTOSAR compliant structs and enums.
  • Flexible Arrays & Bounded/Unbounded Vectors: Multiple syntax choices are supported out of the box:
    • Fixed-Size Arrays: Array[T, size], Array(T, size=N)
    • Bounded Vectors: Vector[T, max_size], Vector(T, max_size=M)
    • Unbounded Vectors: Vector[T], list[T], List[T], or compact literal [T]
  • Optional Types: Use Optional[T] or PEP 604 T | None. These are parsed and serialized as <IS-OPTIONAL>true</IS-OPTIONAL> in ARXML (Adaptive SOME/IP TLV compliant) and "is_optional": true in JSON.
  • Annotated Constraints: Unpack PEP 593 typing.Annotated[BaseType, "min=X", "max=Y", "unit=Z", "default=W"] directly.
  • C++ Namespacing: Support for specifying namespaces inside models using _namespace_ / _cpp_namespace_ attributes, or with decorators @namespace("car.adas", cpp="car::adas") and @cpp_namespace("...").
  • Conforming Multi-Format Emitters:
    • ARXML: Generates standard-compliant AUTOSAR Adaptive system descriptions.
    • JSON Schema: Generates clean, structured JSON schemas.

Project Structure

  • src/pyarx/:
    • types.py: AUTOSAR primitives, dynamic standard-type converters, and resolve_type.
    • interfaces.py: Service Interface decoration logic, events, fields, methods, and application errors.
    • emitters.py: Translation layers for ARXML and JSON.
    • compiler.py: Recursive compilation driver.
    • cli.py: Entrypoint for command-line compilations.
  • examples/: Full recursive showcase models (e.g. examples/car/) and compile script.
  • tests/: Comprehensive unit tests confirming parser features, validation, and emitter schemas.

Quick Installation

You can install pyarx directly from GitHub using pip:

pip install git+https://github.com/pyarxlab/pyarx.git

Development & Usage

Setup Environment

# Create and activate virtual environment
python3 -m venv .venv
source .venv/bin/activate

# Install package in editable mode with development dependencies
pip install -e ".[dev]"

Running Tests

pytest

Compiling Models

You can compile a directory package (recursively scanning all Python submodules) or a single .py file into ARXML or JSON using either the Python API or the Command Line Interface.

Via CLI:

# Compile package recursively to ARXML (defaults to saving as car.arxml in CWD)
pyarx arxml ./examples/car

# Compile a single Python IDL file to ARXML (defaults to saving as powertrain.arxml in CWD)
pyarx arxml ./examples/car/powertrain.py

# Compile package recursively to JSON (defaults to saving as car.json in CWD)
pyarx json ./examples/car

# Specify an explicit output path
pyarx arxml ./examples/car/powertrain.py -o ./powertrain_system.arxml

Via Python API:

from pyarx import compile_package

# Recursively crawl and compile a package directory to ARXML
arxml_content = compile_package("examples/car", format="arxml")

with open("car_system.arxml", "w") as f:
    f.write(arxml_content)

Disclaimer

This project is provided “as is” without warranty of any kind.

Support

This is an independent project maintained in my personal time.
Support is best-effort only.

Metadata

Release files for pyarxlab 0.2.32

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

Source distribution (sdist)

Source distribution for pyarxlab 0.2.32
File Size Uploaded Provenance Actions
pyarxlab-0.2.32.tar.gz 21.8 MB Without provenance Details for pyarxlab-0.2.32.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyarxlab 0.2.32
File Interpreter ABI Platform Actions
pyarxlab-0.2.32-py3-none-any.whl Python 3 none any Details for pyarxlab-0.2.32-py3-none-any.whl

Total release size: 43.7 MB

Release files / pyarxlab-0.2.32.tar.gz

Download URL pyarxlab-0.2.32.tar.gz
Size 21.8 MB
Tags Source
SHA-256 checksum
How to use checksums
555ecdfebd7880073f5e8e2088edf55f7386235a2e3382cc01dda0e11a726f37
BLAKE2b-256 checksum
How to use checksums
6d457b60014cfe042dca4aedd0d0c1af3d1b2154a55d75ce32c8f5c73c02ab91
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Release files / pyarxlab-0.2.32-py3-none-any.whl

Download URL pyarxlab-0.2.32-py3-none-any.whl
Size 21.9 MB
Tags Python 3
SHA-256 checksum
How to use checksums
b018313c20c1fb0e45dcf18df34f16053ce04ac8e664b3a9594fc5cc4a759d51
BLAKE2b-256 checksum
How to use checksums
053ee554b485a24d57b559402c714150360ea2f32b69f6c207e70e025cadd27e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Security for pyarxlab 0.2.32

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.

Release history Release notifications | RSS feed

This release

0.2.32 This release

2 release files No provenance

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