Skip to main content

Generate Submodel-Specific classes with filled metainformation derived from submodel templates

Project description

aas-submodel-to-py - AAS Submodel Python Code Generator

aas-submodel-to-py is a code generator tool built on top of the BaSyx-Python-SDK. It is designed to generate Submodel-specific classes and classes for its submodel elements with filled meta-information derived from submodel templates. These generated classes act as child classes of the BaSyx-Python-SDK classes and represent classes of the Asset Administration Shell Metamodel. The hierarchical structure of the generated submodel-specific class includes all the required submodel element-specific classes. Input files can be .aasx, .json, or .xml format.

Examples

Example of generated classes

Here's a snippet of a generated Submodel class from the DigitalNameplate Submodel Template:

class Nameplate(Submodel):
    class ManufacturerName(MultiLanguageProperty):
        def __init__(
                self,
                value: LangStringSet,
                id_short: str = "ManufacturerName",
                value_id: Optional[Reference] = None,
                category: Optional[str] = None,
                description: Optional[LangStringSet] = None,
                semantic_id: Optional[Reference] = Reference(
                    key=(Key(type_=KeyElements.CONCEPT_DESCRIPTION,
                             local=True,
                             value="0173-1#02-AAO677#002",
                             id_type=KeyType.IRDI, ),)),
                qualifier: Optional[Set[Constraint]] = None,
                kind: ModelingKind = ModelingKind.INSTANCE,
        ):
            if description is None:
                description = {
                    "en": "Note: see also [IRDI] 0112/2///61987#ABA565#007 manufacturer Note: mandatory property according to EU Machine Directive 2006/42/EC. "}

            if qualifier is None:
                qualifier = {
                    Qualifier(type_="Multiplicity", value_type=str,
                              value="One", value_id=None, semantic_id=None, )
                }

            super().__init__(
                value=value,
                id_short=id_short,
                value_id=value_id,
                category=category,
                description=description,
                semantic_id=semantic_id,
                qualifier=qualifier,
                kind=kind,
            )

    ...

Usage Example of the generated class

Here's an example of instantiating the DigitalNameplate Submodel:

nameplate = Nameplate(
    identification=Identifier(id_="www.example.com/ids/sm/1234", id_type=IdentifierType.IRI),
    uRIOfTheProduct="https://www.domain-abc.com/Model-Nr-1234/Serial-Nr-5678",
    manufacturerName={'de': 'Muster AG'},
    manufacturerProductDesignation={'en': 'ABC-123'},
    yearOfConstruction="2022",
    contactInformation=Nameplate.ContactInformation(
        nationalCode={'en': 'DE'},
        cityTown={'de': 'Musterstadt'},
        street={'de': 'Musterstrasse 1'},
        zipcode={'de': '12345'})
)

All required submodel elements are positional arguments; optional elements default to None. The output is auto-formatted with Black.

Installation

Using PyPI:

pip install aas-submodel-to-py

Or from the repository root:

pip install -e ./aas-submodel-to-py

Usage

Command Line

# Minimal: output .py is generated next to the input file
# e.g. IDTA-02006-2-0_Submodel_Digital Nameplate.aasx → IDTA_02006_2_0_Submodel_Digital_Nameplate.py
submodel_to_code -i /some/path/DigitalNameplate.aasx

# Write to a specific output directory (filename still auto-derived)
submodel_to_code -i /some/path/DigitalNameplate.aasx -d /some/other/path/

# Write to an explicit output file path
submodel_to_code -i /some/path/DigitalNameplate.aasx -o /some/path/output.py

# Overwrite an existing output file
submodel_to_code -i /some/path/DigitalNameplate.aasx --force
Flag Long form Description Required
-i --aas_path Input AAS file (.aasx, .json, or .xml) Yes
-o --outpath Output .py file path (mutually exclusive with -d) No
-d --outdir Output directory; filename is derived from the input filename (mutually exclusive with -o) No
-f --force Overwrite the output file if it already exists No

If neither -o nor -d is given, the output file is written next to the input file with hyphens and spaces in the name replaced by underscores.

If the entry-point is not on PATH, use the module invocation:

python -m aas_submodel_to_py.submodel_to_code \
    -i /some/path/DigitalNameplate.aasx \
    -o /some/path/output.py

Python API

from aas_submodel_to_py import SubmodelCodegen

codegen = SubmodelCodegen()

# Generate from an AAS file (.aasx, .json, or .xml)
codegen.generate_from(
    input_file="/some/path/DigitalNameplate.aasx",
    output_file="nameplate.py"
)

# If you already have an AAS object store loaded in memory
codegen.generate_from_obj_store(
    obj_store=my_existing_store,
    output_file="output.py"
)

Support and Contribution

If you encounter any issues, or want to contribute to the project, feel free to open an issue or a pull request. Your contributions are always welcome!

License

This project is licensed under the MIT License. See the LICENSE file for details.

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

aas_submodel_to_py-0.1.1.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aas_submodel_to_py-0.1.1-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

Details for the file aas_submodel_to_py-0.1.1.tar.gz.

File metadata

  • Download URL: aas_submodel_to_py-0.1.1.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for aas_submodel_to_py-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b8f68555c32cd61456f7e3a0a2ff38bb8e4c6549ac470a0aea53c22b0429ff6c
MD5 329c42161546912e847051807851a2ac
BLAKE2b-256 3bb1a8fe4f05883f46436a5e9a49b866a36730ad79f2a8e4cee017a936a9bd51

See more details on using hashes here.

Provenance

The following attestation bundles were made for aas_submodel_to_py-0.1.1.tar.gz:

Publisher: publish.yml on rwth-iat/aas-submodel-template-to-py

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

File details

Details for the file aas_submodel_to_py-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for aas_submodel_to_py-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d4c16b9aabb5c4562304b6257c6c581f381ce25bdb221dfe92150eca8ba765e4
MD5 0b3621a4204de2d1ce11b30d862af3d8
BLAKE2b-256 392fef80a36c7096fed638b2d65b4e95db361e2fd9aec8962c9bb935b938d274

See more details on using hashes here.

Provenance

The following attestation bundles were made for aas_submodel_to_py-0.1.1-py3-none-any.whl:

Publisher: publish.yml on rwth-iat/aas-submodel-template-to-py

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