Skip to main content

read, write and modify Autosar arxml data using Python

Project description

autosar-data-py

PyPI version Github Actions codecov

Python bindings for autosar-data

Features

This crate implements Python bindings for autosar-data using PyO3. This allows all the features of autosar-data to be used from python code:

  • read and write arxml files
  • fully validate all data when it is loaded in strict mode
  • non-strict mode so that invalid but structurally sound data can be loaded
  • various element operations to modify and create sub-elements, data and attributes
  • support for Autosar paths and cross references
  • supports Autosar version 4.0.1 and up.

API documentation

API documentation is located here: https://danielt.github.io/autosar-data-py/

Example

Load data from a file

from autosar_data import *

# load a file
model = AutosarModel()
(arxmlfile, warnings) = model.load_file("filename.arxml", False)

Load data from text

from autosar_data import *
# alternatively: load a buffer
model = AutosarModel()
filebuf = """<?xml version="1.0" encoding="utf-8"?>
    <AUTOSAR xsi:schemaLocation="http://autosar.org/schema/r4.0 AUTOSAR_00050.xsd" xmlns="http://autosar.org/schema/r4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <AR-PACKAGES><AR-PACKAGE><SHORT-NAME>Pkg</SHORT-NAME></AR-PACKAGE></AR-PACKAGES></AUTOSAR>"""
(arxmlfile, warnings) = model.load_buffer(filebuf, "filename.arxml", False)

Create data from scratch

from autosar_data import *
# alternatively: create a new data model from scratch
model = AutosarModel()

# create a file in the model
file1 = model.create_file("filename.arxml", AutosarVersion.Autosar_4_3_0)
# a model can consist of multiple files - elements appear in all of them by default, unless restrictions are set
file2 = model.create_file("filename2.arxml", AutosarVersion.Autosar_00051)

# initially the model only has its root element, <AUTOSAR>. Create some elements
el_elements = model.root_element \
    .create_sub_element("AR-PACKAGES") \
    .create_named_sub_element("AR-PACKAGE", "Pkg") \
    .create_sub_element("ELEMENTS")

# create some more elements
el_fibex_element_ref = el_elements \
    .create_named_sub_element("SYSTEM", "System") \
    .create_sub_element("FIBEX-ELEMENTS") \
    .create_sub_element("FIBEX-ELEMENT-REF-CONDITIONAL") \
    .create_sub_element("FIBEX-ELEMENT-REF")
el_can_cluster = model.root_element \
    .get_sub_element("AR-PACKAGES") \
    .create_named_sub_element("AR-PACKAGE", "Pkg2") \
    .create_sub_element("ELEMENTS") \
    .create_named_sub_element("CAN-CLUSTER", "CanCluster")

# set a cross reference
el_fibex_element_ref.reference_target = el_can_cluster

# check the cross reference
el_fibex_element_ref.character_data
# '/Pkg2/CanCluster'
el_fibex_element_ref.reference_target == el_can_cluster
# True

# get an attribute
el_fibex_element_ref.attribute_value("DEST")
# EnumItem.CanCluster
model.root_element.attribute_value("xmlns")
# 'http://autosar.org/schema/r4.0'

# set an attribute value
el_fibex_element_ref.set_attribute("DEST", "I-SIGNAL")
# setting the DEST of the reference to an invalid value has invalidated the
# reference, so accessing el_fibex_element_ref.reference_target will now cause an exception

el_can_cluster.set_attribute("UUID", "1234567890abcdefg")

# get the current xml text of the model:
print(file1.serialize())
# this prints "<?xml version="1.0" encoding="utf-8"?>\n<AUTOSAR ..."

# write all the files in the model - this will create filename.arxml and filename2.arxml with identical content
model.write()

# get the autosar paths of all elements in the model
paths = model.identifiable_elements
# paths = ['/Pkg', '/Pkg/System', '/Pkg2', '/Pkg2/CanCluster']

# get an element by its path
el_ar_package1 = model.get_element_by_path("/Pkg")
el_ar_package2 = model.get_element_by_path("/Pkg2")
el_system = model.get_element_by_path("/Pkg/System")

# restrict the packages to only appear in one file each
el_ar_package1.remove_from_file(file2)
el_ar_package2.remove_from_file(file1)

# write all the files in the model - now the content is different
model.write()

Working with data

from autosar_data import *

model = AutosarModel()
(arxmlfile, warnings) = model.load_file("somefile.arxml", False)

# display all the triggered PDUs in the file
for (depth, element) in model.elements_dfs:
    if element.element_name == "PDU-TRIGGERING":
        pdu = element.get_sub_element("I-PDU-REF").reference_target
        print(str.format("PDU: <{}> = {}", pdu.element_name, pdu.item_name))

Development

  • maturin must be installed: pip install maturin if it isn't
  • create a venv in the cloned source: python -m venv .venv
  • build the wheel and directly install it in the venv: maturin develop
  • activate the venv in a shell: source .venv/bin/activate or .venv\Scripts\Activate.ps1
  • run python in the shell with the venv

Project details


Download files

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

Source Distribution

autosar_data-0.7.0.tar.gz (36.2 kB view hashes)

Uploaded Source

Built Distributions

autosar_data-0.7.0-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

autosar_data-0.7.0-pp310-pypy310_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.9 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ s390x

autosar_data-0.7.0-pp310-pypy310_pp73-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.7 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ppc64le

autosar_data-0.7.0-pp310-pypy310_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.6 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARMv7l

autosar_data-0.7.0-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.7 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

autosar_data-0.7.0-pp310-pypy310_pp73-manylinux_2_5_i686.manylinux1_i686.whl (1.6 MB view hashes)

Uploaded PyPy manylinux: glibc 2.5+ i686

autosar_data-0.7.0-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

autosar_data-0.7.0-pp39-pypy39_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.9 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ s390x

autosar_data-0.7.0-pp39-pypy39_pp73-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.7 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ppc64le

autosar_data-0.7.0-pp39-pypy39_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.6 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARMv7l

autosar_data-0.7.0-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.7 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

autosar_data-0.7.0-pp39-pypy39_pp73-manylinux_2_5_i686.manylinux1_i686.whl (1.6 MB view hashes)

Uploaded PyPy manylinux: glibc 2.5+ i686

autosar_data-0.7.0-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

autosar_data-0.7.0-pp38-pypy38_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.9 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ s390x

autosar_data-0.7.0-pp38-pypy38_pp73-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.7 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ppc64le

autosar_data-0.7.0-pp38-pypy38_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.6 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARMv7l

autosar_data-0.7.0-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.7 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

autosar_data-0.7.0-pp38-pypy38_pp73-manylinux_2_5_i686.manylinux1_i686.whl (1.6 MB view hashes)

Uploaded PyPy manylinux: glibc 2.5+ i686

autosar_data-0.7.0-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

autosar_data-0.7.0-pp37-pypy37_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.9 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ s390x

autosar_data-0.7.0-pp37-pypy37_pp73-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.7 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ppc64le

autosar_data-0.7.0-pp37-pypy37_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.6 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARMv7l

autosar_data-0.7.0-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.7 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

autosar_data-0.7.0-pp37-pypy37_pp73-manylinux_2_5_i686.manylinux1_i686.whl (1.6 MB view hashes)

Uploaded PyPy manylinux: glibc 2.5+ i686

autosar_data-0.7.0-cp312-none-win_amd64.whl (653.6 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

autosar_data-0.7.0-cp312-none-win32.whl (626.2 kB view hashes)

Uploaded CPython 3.12 Windows x86

autosar_data-0.7.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

autosar_data-0.7.0-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.8 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ s390x

autosar_data-0.7.0-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.7 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ppc64le

autosar_data-0.7.0-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.6 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARMv7l

autosar_data-0.7.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.7 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARM64

autosar_data-0.7.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.whl (1.6 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.5+ i686

autosar_data-0.7.0-cp312-cp312-macosx_11_0_arm64.whl (786.0 kB view hashes)

Uploaded CPython 3.12 macOS 11.0+ ARM64

autosar_data-0.7.0-cp312-cp312-macosx_10_12_x86_64.whl (782.6 kB view hashes)

Uploaded CPython 3.12 macOS 10.12+ x86-64

autosar_data-0.7.0-cp311-none-win_amd64.whl (651.4 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

autosar_data-0.7.0-cp311-none-win32.whl (623.9 kB view hashes)

Uploaded CPython 3.11 Windows x86

autosar_data-0.7.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

autosar_data-0.7.0-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.9 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ s390x

autosar_data-0.7.0-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.7 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ppc64le

autosar_data-0.7.0-cp311-cp311-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.6 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARMv7l

autosar_data-0.7.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.7 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

autosar_data-0.7.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.whl (1.6 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.5+ i686

autosar_data-0.7.0-cp311-cp311-macosx_11_0_arm64.whl (783.9 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

autosar_data-0.7.0-cp311-cp311-macosx_10_12_x86_64.whl (779.9 kB view hashes)

Uploaded CPython 3.11 macOS 10.12+ x86-64

autosar_data-0.7.0-cp310-none-win_amd64.whl (651.5 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

autosar_data-0.7.0-cp310-none-win32.whl (624.0 kB view hashes)

Uploaded CPython 3.10 Windows x86

autosar_data-0.7.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

autosar_data-0.7.0-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.9 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ s390x

autosar_data-0.7.0-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.7 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ppc64le

autosar_data-0.7.0-cp310-cp310-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.6 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARMv7l

autosar_data-0.7.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.7 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

autosar_data-0.7.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.whl (1.6 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.5+ i686

autosar_data-0.7.0-cp310-cp310-macosx_11_0_arm64.whl (784.1 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

autosar_data-0.7.0-cp310-cp310-macosx_10_12_x86_64.whl (779.7 kB view hashes)

Uploaded CPython 3.10 macOS 10.12+ x86-64

autosar_data-0.7.0-cp39-none-win_amd64.whl (651.9 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

autosar_data-0.7.0-cp39-none-win32.whl (622.4 kB view hashes)

Uploaded CPython 3.9 Windows x86

autosar_data-0.7.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

autosar_data-0.7.0-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.9 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ s390x

autosar_data-0.7.0-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.7 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ppc64le

autosar_data-0.7.0-cp39-cp39-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.6 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARMv7l

autosar_data-0.7.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.7 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

autosar_data-0.7.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.whl (1.6 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.5+ i686

autosar_data-0.7.0-cp38-none-win_amd64.whl (651.1 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

autosar_data-0.7.0-cp38-none-win32.whl (623.8 kB view hashes)

Uploaded CPython 3.8 Windows x86

autosar_data-0.7.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

autosar_data-0.7.0-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.9 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ s390x

autosar_data-0.7.0-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.7 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ppc64le

autosar_data-0.7.0-cp38-cp38-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.6 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARMv7l

autosar_data-0.7.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.7 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

autosar_data-0.7.0-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.whl (1.6 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.5+ i686

autosar_data-0.7.0-cp37-none-win_amd64.whl (651.7 kB view hashes)

Uploaded CPython 3.7 Windows x86-64

autosar_data-0.7.0-cp37-none-win32.whl (623.5 kB view hashes)

Uploaded CPython 3.7 Windows x86

autosar_data-0.7.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

autosar_data-0.7.0-cp37-cp37m-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.9 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ s390x

autosar_data-0.7.0-cp37-cp37m-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.7 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ ppc64le

autosar_data-0.7.0-cp37-cp37m-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.6 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ ARMv7l

autosar_data-0.7.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.7 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ ARM64

autosar_data-0.7.0-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.whl (1.6 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.5+ i686

Supported by

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