Skip to main content

utility for a2l files

Project description

branch build coverage
master Python package code coverage
develop Python package code coverage

License Gitter

Package description

the purpose of this package is to provide an easy way to access and navigate in a2l formatted file.
once the file has been loaded, a tree of Python objects is generated, allowing the user to access nodes.

Installation

Using pip

Install the last released version of the package by running the following command: pip install pya2l

or install the most recent version of the package (master branch) by running the following command: pip install git+https://github.com/Sauci/pya2l.git@master

Example of usage

Command line tool

Once the package installed, the pya2l command will be available. It provides several different commands:

  • Convert an A2L file to JSON with pya2l -v <source>.a2l to_json -o <output.json> -i 2
  • Convert an A2L file to A2L with pya2l -v <source.a2l> to_a2l -o <output.a2l> -i 2
  • Convert a JSON-formatted A2L file to JSON with pya2l -v <source>.json to_json -o <output.json> -i 2
  • Convert a JSON-formatted A2L file to A2L with pya2l -v <source>.json to_a2l -o <output.a2l> -i 2

Python API

the bellow code snippet shows how properties of a node in an a2l string can be retrieved using this package.

from pya2l.parser import A2lParser as Parser

a2l_string = """/begin PROJECT project_name "example project"
    /begin MODULE first_module "first module long identifier"
        /begin CHARACTERISTIC
            example_of_characteristic
            "first characteristic long identifier"
            VALUE
            0
            DAMOS_SST
            0
            first_characteristic_conversion
            -4.5
            12.0
        /end CHARACTERISTIC
    /end MODULE
/end PROJECT
"""

with Parser() as p:
    # get the AST.
    ast = p.tree_from_a2l(a2l_string.encode())

    # get a list of available properties for a specific node.
    assert set(ast.PROJECT.properties) == {'Name', 'LongIdentifier', 'HEADER', 'MODULE'}

    # access nodes explicitly.
    assert ast.PROJECT.MODULE[0].CHARACTERISTIC[0].Name.Value == 'example_of_characteristic'
    assert ast.PROJECT.MODULE[0].CHARACTERISTIC[0].LowerLimit.Value == -4.5
    assert ast.PROJECT.MODULE[0].CHARACTERISTIC[0].UpperLimit.Value == 12.0

a2l_string = """/begin PROJECT project_name "example project"
    /begin MODULE first_module "first module long identifier"
    /end MODULE
/end PROJECT
"""

with Parser() as p:
    # get the AST.
    ast = p.tree_from_a2l(a2l_string.encode())

    # convert node to json-formatted string.
    assert p.json_from_tree(ast, indent=2).decode() == """{
  "PROJECT": {
    "Name": {
      "Value": "project_name"
    },
    "LongIdentifier": {
      "Value": "example project"
    },
    "MODULE": [
      {
        "Name": {
          "Value": "first_module"
        },
        "LongIdentifier": {
          "Value": "first module long identifier"
        }
      }
    ]
  }
}"""

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

pya2l-0.1.10.tar.gz (63.9 MB view details)

Uploaded Source

Built Distribution

pya2l-0.1.10-py3-none-any.whl (64.4 MB view details)

Uploaded Python 3

File details

Details for the file pya2l-0.1.10.tar.gz.

File metadata

  • Download URL: pya2l-0.1.10.tar.gz
  • Upload date:
  • Size: 63.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pya2l-0.1.10.tar.gz
Algorithm Hash digest
SHA256 1211ab0fbb232ca9cdb4e1eef2da1102710eec38215ec6147f6b0cb3561b23ac
MD5 f70d92fb418a435159e9e86b326124a4
BLAKE2b-256 fd71ca760c6db13159bb4db74c8d90b573cec5e3e6318b7b59ca1725224e2a54

See more details on using hashes here.

Provenance

The following attestation bundles were made for pya2l-0.1.10.tar.gz:

Publisher: build.yml on Sauci/pya2l

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

File details

Details for the file pya2l-0.1.10-py3-none-any.whl.

File metadata

  • Download URL: pya2l-0.1.10-py3-none-any.whl
  • Upload date:
  • Size: 64.4 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pya2l-0.1.10-py3-none-any.whl
Algorithm Hash digest
SHA256 1e6a842fea25865eaa6cd7591b835e920f849ca4a1eeb0ec8c9a6f30fb03bc11
MD5 6e74e612f19d336882dedca8fb39a3b0
BLAKE2b-256 d33f7e56e7fb1af53fc1b7bce24c6b65434266b618c36ab34af7fa0e9ea57ede

See more details on using hashes here.

Provenance

The following attestation bundles were made for pya2l-0.1.10-py3-none-any.whl:

Publisher: build.yml on Sauci/pya2l

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 Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page