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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b8f68555c32cd61456f7e3a0a2ff38bb8e4c6549ac470a0aea53c22b0429ff6c
|
|
| MD5 |
329c42161546912e847051807851a2ac
|
|
| BLAKE2b-256 |
3bb1a8fe4f05883f46436a5e9a49b866a36730ad79f2a8e4cee017a936a9bd51
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aas_submodel_to_py-0.1.1.tar.gz -
Subject digest:
b8f68555c32cd61456f7e3a0a2ff38bb8e4c6549ac470a0aea53c22b0429ff6c - Sigstore transparency entry: 985800964
- Sigstore integration time:
-
Permalink:
rwth-iat/aas-submodel-template-to-py@63bbc4b484c9370baddb770ad5596c349d50e4cf -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/rwth-iat
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@63bbc4b484c9370baddb770ad5596c349d50e4cf -
Trigger Event:
release
-
Statement type:
File details
Details for the file aas_submodel_to_py-0.1.1-py3-none-any.whl.
File metadata
- Download URL: aas_submodel_to_py-0.1.1-py3-none-any.whl
- Upload date:
- Size: 14.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d4c16b9aabb5c4562304b6257c6c581f381ce25bdb221dfe92150eca8ba765e4
|
|
| MD5 |
0b3621a4204de2d1ce11b30d862af3d8
|
|
| BLAKE2b-256 |
392fef80a36c7096fed638b2d65b4e95db361e2fd9aec8962c9bb935b938d274
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aas_submodel_to_py-0.1.1-py3-none-any.whl -
Subject digest:
d4c16b9aabb5c4562304b6257c6c581f381ce25bdb221dfe92150eca8ba765e4 - Sigstore transparency entry: 985800968
- Sigstore integration time:
-
Permalink:
rwth-iat/aas-submodel-template-to-py@63bbc4b484c9370baddb770ad5596c349d50e4cf -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/rwth-iat
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@63bbc4b484c9370baddb770ad5596c349d50e4cf -
Trigger Event:
release
-
Statement type: