### Install SDK and Compliance Tool Dependencies Source: https://github.com/eclipse-basyx/basyx-python-sdk/blob/main/CONTRIBUTING.md Install the SDK and its development dependencies, followed by the compliance tool's development dependencies. Run these commands from the ./compliance_tool directory. ```bash pip install -e ../sdk[dev] pip install .[dev] ``` -------------------------------- ### create_example_asset_administration_shell Source: https://github.com/eclipse-basyx/basyx-python-sdk/blob/main/sdk/docs/source/examples/example_aas_missing_attributes.md Creates an example AssetAdministrationShell containing a reference to an example Submodel. ```APIDOC ## create_example_asset_administration_shell() ### Description Creates an example [`AssetAdministrationShell`](../model/aas.md#basyx.aas.model.aas.AssetAdministrationShell) containing a reference to an example [`Submodel`](../model/submodel.md#basyx.aas.model.submodel.Submodel). ### Returns - example asset administration shell ``` -------------------------------- ### create_example_asset_administration_shell Source: https://github.com/eclipse-basyx/basyx-python-sdk/blob/main/sdk/docs/source/examples/example_aas_mandatory_attributes.md Creates an example AssetAdministrationShell containing references to the example Submodels. ```APIDOC ## create_example_asset_administration_shell() ### Description Creates an example [`AssetAdministrationShell`](../model/aas.md#basyx.aas.model.aas.AssetAdministrationShell) containing references to the example, the example [`~Submodels`](../model/submodel.md#basyx.aas.model.submodel.Submodel). ### Returns example asset administration shell ``` -------------------------------- ### Install Local SDK and Server Source: https://github.com/eclipse-basyx/basyx-python-sdk/blob/main/server/README.md Install the local SDK and server packages using pip. This is a prerequisite for running the server directly on the host. ```bash $ pip install ../sdk $ pip install ./app ``` -------------------------------- ### create_full_example Source: https://github.com/eclipse-basyx/basyx-python-sdk/blob/main/sdk/docs/source/examples/example_aas_missing_attributes.md Creates a DictObjectStore containing an example Submodel, a ConceptDescription, and an AssetAdministrationShell. ```APIDOC ## create_full_example() ### Description Creates an [`DictObjectStore`](../model/provider.md#basyx.aas.model.provider.DictObjectStore) containing an example [`Submodel`](../model/submodel.md#basyx.aas.model.submodel.Submodel), an example [`ConceptDescription`](../model/concept.md#basyx.aas.model.concept.ConceptDescription) and an example [`AssetAdministrationShell`](../model/aas.md#basyx.aas.model.aas.AssetAdministrationShell). ### Returns - [`basyx.aas.model.provider.DictObjectStore`](../model/provider.md#basyx.aas.model.provider.DictObjectStore) ``` -------------------------------- ### Install Development Dependencies Source: https://github.com/eclipse-basyx/basyx-python-sdk/blob/main/CONTRIBUTING.md Install the SDK with development dependencies required for testing and code quality checks. Ensure you are in the directory containing pyproject.toml. ```bash pip install .[dev] ``` -------------------------------- ### create_example_asset_administration_shell Source: https://github.com/eclipse-basyx/basyx-python-sdk/blob/main/sdk/docs/source/examples/example_aas.md Creates an AssetAdministrationShell with references to an example Submodel. ```APIDOC ## create_example_asset_administration_shell() ### Description Creates an [`AssetAdministrationShell`](../model/aas.md#basyx.aas.model.aas.AssetAdministrationShell) with references to an example [`Submodel`](../model/submodel.md#basyx.aas.model.submodel.Submodel). ### Returns example [`AssetAdministrationShell`](../model/aas.md#basyx.aas.model.aas.AssetAdministrationShell) ``` -------------------------------- ### create_full_example Source: https://github.com/eclipse-basyx/basyx-python-sdk/blob/main/sdk/docs/source/examples/example_aas.md Creates an object store filled with an example Submodel, ConceptDescription, and AssetAdministrationShell. ```APIDOC ## create_full_example() ### Description Creates an object store which is filled with an example [`Submodel`](../model/submodel.md#basyx.aas.model.submodel.Submodel), [`ConceptDescription`](../model/concept.md#basyx.aas.model.concept.ConceptDescription) and [`AssetAdministrationShell`](../model/aas.md#basyx.aas.model.aas.AssetAdministrationShell) using the functions of this module ### Returns [`DictObjectStore`](../model/provider.md#basyx.aas.model.provider.DictObjectStore) ``` -------------------------------- ### Install Eclipse BaSyx Python SDK Source: https://github.com/eclipse-basyx/basyx-python-sdk/blob/main/sdk/README.md Install the SDK using pip. For the development version, install directly from GitHub. ```bash pip install basyx-python-sdk ``` ```bash pip install --no-cache-dir git+https://github.com/eclipse-basyx/basyx-python-sdk@main#subdirectory=sdk ``` -------------------------------- ### create_example_concept_description Source: https://github.com/eclipse-basyx/basyx-python-sdk/blob/main/sdk/docs/source/examples/example_aas.md Creates an example ConceptDescription. ```APIDOC ## create_example_concept_description() ### Description Creates an example [`ConceptDescription`](../model/concept.md#basyx.aas.model.concept.ConceptDescription) ### Returns example concept description ``` -------------------------------- ### create_example_concept_description Source: https://github.com/eclipse-basyx/basyx-python-sdk/blob/main/sdk/docs/source/examples/example_aas_missing_attributes.md Creates an example ConceptDescription. ```APIDOC ## create_example_concept_description() ### Description Creates an example [`ConceptDescription`](../model/concept.md#basyx.aas.model.concept.ConceptDescription). ### Returns - example concept description ``` -------------------------------- ### create_full_example Source: https://github.com/eclipse-basyx/basyx-python-sdk/blob/main/sdk/docs/source/examples/example_aas_mandatory_attributes.md Creates an DictObjectStore which is filled with an example Submodel, ConceptDescription and AssetAdministrationShell using the functions of this module. ```APIDOC ## create_full_example() ### Description Creates an [`DictObjectStore`](../model/provider.md#basyx.aas.model.provider.DictObjectStore) which is filled with an example [`Submodel`](../model/submodel.md#basyx.aas.model.submodel.Submodel), [`ConceptDescription`](../model/concept.md#basyx.aas.model.concept.ConceptDescription) and [`AssetAdministrationShell`](../model/aas.md#basyx.aas.model.aas.AssetAdministrationShell) using the functions of this module ### Returns [`DictObjectStore`](../model/provider.md#basyx.aas.model.provider.DictObjectStore) ``` -------------------------------- ### create_example_empty_asset_administration_shell Source: https://github.com/eclipse-basyx/basyx-python-sdk/blob/main/sdk/docs/source/examples/example_aas_mandatory_attributes.md Creates an example empty AssetAdministrationShell with just an empty AssetInformation and an Identifier. ```APIDOC ## create_example_empty_asset_administration_shell() ### Description Creates an example empty [`AssetAdministrationShell`](../model/aas.md#basyx.aas.model.aas.AssetAdministrationShell) with just an empty [`AssetInformation`](../model/aas.md#basyx.aas.model.aas.AssetInformation) and an [`Identifier`](../model/base.md#basyx.aas.model.base.Identifier) ### Returns example [`AssetAdministrationShell`](../model/aas.md#basyx.aas.model.aas.AssetAdministrationShell) ``` -------------------------------- ### check_full_example Source: https://github.com/eclipse-basyx/basyx-python-sdk/blob/main/sdk/docs/source/examples/example_aas_missing_attributes.md Checks a full example including an ObjectStore, AAS, Submodel, and ConceptDescription. ```APIDOC ## check_full_example(checker: [AASDataChecker](_helper.md#basyx.aas.examples.data._helper.AASDataChecker), obj_store: [DictObjectStore](../model/provider.md#basyx.aas.model.provider.DictObjectStore)) ### Description Checks a full example including an [`ObjectStore`](../model/provider.md#basyx.aas.model.provider.DictObjectStore) with an example [`Submodel`](../model/submodel.md#basyx.aas.model.submodel.Submodel), an example [`ConceptDescription`](../model/concept.md#basyx.aas.model.concept.ConceptDescription) and an example [`AssetAdministrationShell`](../model/aas.md#basyx.aas.model.aas.AssetAdministrationShell). ``` -------------------------------- ### check_example_asset_administration_shell Source: https://github.com/eclipse-basyx/basyx-python-sdk/blob/main/sdk/docs/source/examples/example_aas_missing_attributes.md Checks an example Asset Administration Shell object. ```APIDOC ## check_example_asset_administration_shell(checker: [AASDataChecker](_helper.md#basyx.aas.examples.data._helper.AASDataChecker), shell: [AssetAdministrationShell](../model/aas.md#basyx.aas.model.aas.AssetAdministrationShell)) ### Description Checks an example [`AssetAdministrationShell`](../model/aas.md#basyx.aas.model.aas.AssetAdministrationShell) object. ``` -------------------------------- ### create_example_submodel Source: https://github.com/eclipse-basyx/basyx-python-sdk/blob/main/sdk/docs/source/examples/example_aas.md Creates an example Submodel containing all kinds of SubmodelElement objects. ```APIDOC ## create_example_submodel() ### Description Creates an example [`Submodel`](../model/submodel.md#basyx.aas.model.submodel.Submodel) containing all kind of [`SubmodelElement`](../model/submodel.md#basyx.aas.model.submodel.SubmodelElement) objects ### Returns example submodel ``` -------------------------------- ### Run Local Server Source: https://github.com/eclipse-basyx/basyx-python-sdk/blob/main/server/README.md Execute the main function of the local server to start it. The server will be accessible at http://localhost:8080/api/v3.0/. ```bash $ python -m app.interfaces.repository ``` -------------------------------- ### create_example_submodel Source: https://github.com/eclipse-basyx/basyx-python-sdk/blob/main/sdk/docs/source/examples/example_aas_missing_attributes.md Creates an example Submodel containing all kinds of SubmodelElement objects. ```APIDOC ## create_example_submodel() ### Description Creates an example [`Submodel`](../model/submodel.md#basyx.aas.model.submodel.Submodel) containing all kind of [`SubmodelElement`](../model/submodel.md#basyx.aas.model.submodel.SubmodelElement) objects. ### Returns - example submodel ``` -------------------------------- ### create_example_concept_description Source: https://github.com/eclipse-basyx/basyx-python-sdk/blob/main/sdk/docs/source/examples/example_aas_mandatory_attributes.md Creates an example ConceptDescription where only the id attribute is set. ```APIDOC ## create_example_concept_description() ### Description Creates an example [`ConceptDescription`](../model/concept.md#basyx.aas.model.concept.ConceptDescription) where only the id attribute is set ### Returns example concept description ``` -------------------------------- ### check_example_concept_description Source: https://github.com/eclipse-basyx/basyx-python-sdk/blob/main/sdk/docs/source/examples/example_aas_missing_attributes.md Checks an example Concept Description object. ```APIDOC ## check_example_concept_description(checker: [AASDataChecker](_helper.md#basyx.aas.examples.data._helper.AASDataChecker), concept_description: [ConceptDescription](../model/concept.md#basyx.aas.model.concept.ConceptDescription)) ### Description Checks an example [`ConceptDescription`](../model/concept.md#basyx.aas.model.concept.ConceptDescription) object. ``` -------------------------------- ### Create and Configure Property Elements Source: https://context7.com/eclipse-basyx/basyx-python-sdk/llms.txt Shows how to create `Property` elements, which hold single typed values. This example demonstrates creating string, integer, and boolean properties, including setting semantic IDs and descriptions. ```python from basyx.aas import model # String property with semantic reference name_prop = model.Property( id_short='SerialNumber', value_type=model.datatypes.String, value='SN-20240101-007', semantic_id=model.ExternalReference(( model.Key(type_=model.KeyTypes.GLOBAL_REFERENCE, value='0173-1#02-AAM556#002'), )), description=model.MultiLanguageTextType({'en': 'Serial number of the device', 'de': 'Seriennummer des Geräts'}) ) # Integer property using XSD int type count_prop = model.Property( id_short='CycleCount', value_type=model.datatypes.Int, value=42 ) # Boolean property active_prop = model.Property( id_short='IsActive', value_type=model.datatypes.Boolean, value=True ) print(name_prop.value_type) # print(count_prop.value) # 42 ``` -------------------------------- ### Create and Serialize a Submodel with a Property Source: https://github.com/eclipse-basyx/basyx-python-sdk/blob/main/sdk/README.md Example demonstrating how to create a Submodel, add a Property with a semantic reference, and serialize it to an XML file using the SDK. ```python from basyx.aas import model # Import all BaSyx Python SDK classes from the model package identifier = 'https://acplt.org/Simple_Submodel' submodel = model.Submodel(identifier) ``` ```python # create an external reference to a semantic description of the property semantic_reference = model.ExternalReference( (model.Key( type_=model.KeyTypes.GLOBAL_REFERENCE, value='http://acplt.org/Properties/SimpleProperty' ),) ) property = model.Property( id_short='ExampleProperty', # Identifying string of the element within the submodel namespace value_type=model.datatypes.String, # Data type of the value value='exampleValue', # Value of the property semantic_id=semantic_reference # set the semantic reference ) submodel.submodel_element.add(property) ``` ```python from basyx.aas.adapter.xml import write_aas_xml_file data: model.DictObjectStore[model.Identifiable] = model.DictObjectStore() data.add(submodel) write_aas_xml_file(file='Simple_Submodel.xml', data=data) ``` -------------------------------- ### check_example_submodel Source: https://github.com/eclipse-basyx/basyx-python-sdk/blob/main/sdk/docs/source/examples/example_aas_missing_attributes.md Checks an example Submodel object. ```APIDOC ## check_example_submodel(checker: [AASDataChecker](_helper.md#basyx.aas.examples.data._helper.AASDataChecker), submodel: [Submodel](../model/submodel.md#basyx.aas.model.submodel.Submodel)) ### Description Checks an example [`Submodel`](../model/submodel.md#basyx.aas.model.submodel.Submodel) object. ``` -------------------------------- ### create_example_empty_submodel Source: https://github.com/eclipse-basyx/basyx-python-sdk/blob/main/sdk/docs/source/examples/example_aas_mandatory_attributes.md Creates an example empty Submodel where only the id attribute is set. ```APIDOC ## create_example_empty_submodel() ### Description Creates an example empty [`Submodel`](../model/submodel.md#basyx.aas.model.submodel.Submodel) where only the id attribute is set ### Returns example submodel ``` -------------------------------- ### create_example_submodel Source: https://github.com/eclipse-basyx/basyx-python-sdk/blob/main/sdk/docs/source/examples/example_aas_mandatory_attributes.md Creates an example Submodel containing all kind of SubmodelElement objects where only mandatory attributes are set. ```APIDOC ## create_example_submodel() ### Description Creates an example [`Submodel`](../model/submodel.md#basyx.aas.model.submodel.Submodel) containing all kind of [`SubmodelElement`](../model/submodel.md#basyx.aas.model.submodel.SubmodelElement) objects where only mandatory attributes are set ### Returns example submodel ``` -------------------------------- ### Build and Run BaSyx Python Server Docker Image Source: https://github.com/eclipse-basyx/basyx-python-sdk/blob/main/CONTRIBUTING.md Build a Docker image for the BaSyx Python server and run a container. Ensure Docker is installed and you are in the directory with the Dockerfile. ```bash docker build -t basyx-python-server . docker run --name basyx-python-server basyx-python-server ``` -------------------------------- ### Define and Use Concept Descriptions with DataSpecificationIEC61360 Source: https://context7.com/eclipse-basyx/basyx-python-sdk/llms.txt Shows how to create a `ConceptDescription` with embedded `DataSpecificationIEC61360` content for defining semantic concepts. The example retrieves and prints the preferred name. ```python from basyx.aas import model concept = model.ConceptDescription( id_='https://example.org/concepts/SerialNumber', embedded_data_specifications=[ model.EmbeddedDataSpecification( data_specification=model.ExternalReference(( model.Key(type_=model.KeyTypes.GLOBAL_REFERENCE, value='https://admin-shell.io/DataSpecificationTemplates/DataSpecificationIec61360/3/0'), )), data_specification_content=model.DataSpecificationIEC61360( preferred_name=model.PreferredNameTypeIEC61360({'en': 'Serial Number', 'de': 'Seriennummer'}), short_name=model.ShortNameTypeIEC61360({'en': 'SerialNo'}) data_type=model.DataTypeIEC61360.STRING, definition=model.DefinitionTypeIEC61360({'en': 'Unique identifier of the device instance.'}) ) ) ] ) store = model.DictObjectStore([concept]) retrieved = store.get_identifiable('https://example.org/concepts/SerialNumber') content = retrieved.embedded_data_specifications[0].data_specification_content print(content.preferred_name['en']) # Serial Number ``` -------------------------------- ### Setup AAS and Submodel with File Objects Source: https://github.com/eclipse-basyx/basyx-python-sdk/blob/main/sdk/docs/source/tutorials/tutorial_aasx.md Initializes AAS and Submodel objects, including a File object referencing an auxiliary file. Requires setting up a `SupplementaryFileContainer` and adding files to it. ```python #!/usr/bin/env python3 # This work is licensed under a Creative Commons CCZero 1.0 Universal License. # See http://creativecommons.org/publicdomain/zero/1.0/ for more information. """ Tutorial for exporting Asset Administration Shells with related objects and auxiliary files to AASX package files, using the :mod:`~basyx.aas.adapter.aasx` module from the Eclipse BaSyx Python SDK. .. warning:: This tutorial is only valid for the current main branch of the Eclipse BaSyx Python SDK. With version 3.0 of *Details of the Asset Administration Shell* some specifications of AASX files will change, resulting in changes of the :class:`~basyx.aas.adapter.aasx.AASXWriter` interface. """ import datetime from pathlib import Path # Used for easier handling of auxiliary file's local path import pyecma376_2 # The base library for Open Packaging Specifications. We will use the OPCCoreProperties class. from basyx.aas import model from basyx.aas.adapter import aasx # step 1: Setting up an SupplementaryFileContainer and AAS & submodel with File objects # step 2: Writing AAS objects and auxiliary files to an AASX package # step 3: Reading AAS objects and auxiliary files from an AASX package ######################################################################################## # Step 1: Setting up a SupplementaryFileContainer and AAS & submodel with File objects # ######################################################################################## # Let's first create a basic Asset Administration Shell with a simple submodel. # See `tutorial_create_simple_aas.py` for more details. submodel = model.Submodel( id_='https://acplt.org/Simple_Submodel' ) aas = model.AssetAdministrationShell( id_='https://acplt.org/Simple_AAS', asset_information=model.AssetInformation( asset_kind=model.AssetKind.INSTANCE, global_asset_id='http://acplt.org/Simple_Asset' ), submodel={model.ModelReference.from_referable(submodel)} ) # Another submodel, which is not related to the AAS: unrelated_submodel = model.Submodel( id_='https://acplt.org/Unrelated_Submodel' ) # We add these objects to an ObjectStore for easy retrieval by id. # See `tutorial_storage.py` for more details. We could also use a database-backed ObjectStore here # (see `tutorial_backend_couchdb.py`). object_store = model.DictObjectStore([submodel, aas, unrelated_submodel]) # For holding auxiliary files, which will eventually be added to an AASX package, we need a SupplementaryFileContainer. # The `DictSupplementaryFileContainer` is a simple SupplementaryFileContainer that stores the files' contents in simple # bytes objects in memory. file_store = aasx.DictSupplementaryFileContainer() # Now, we add an example file from our local filesystem to the SupplementaryFileContainer. # # For this purpose, we need to specify the file's name in the SupplementaryFileContainer. This name is used to reference # the file in the container and will later be used as the filename in the AASX package file. Thus, this file must begin # with a slash and should begin with `/aasx/`. Here, we use `/aasx/suppl/MyExampleFile.pdf`. The # SupplementaryFileContainer's add_file() method will ensure uniqueness of the name by adding a suffix if an equally # named file with different contents exists. The final name is returned. # # In addition, we need to specify the MIME type of the file, which is later used in the metadata of the AASX package. # (This is actually a requirement of the underlying Open Packaging Conventions (ECMA376-2) format, which imposes the # specification of the MIME type ("content type") of every single file within the package.) with open(Path(__file__).parent / 'data' / 'TestFile.pdf', 'rb') as f: actual_file_name = file_store.add_file("/aasx/suppl/MyExampleFile.pdf", f, "application/pdf") # With the actual_file_name in the SupplementaryFileContainer, we can create a reference to that file in our AAS # Submodel, in the form of a `File` object: submodel.submodel_element.add( model.File(id_short="documentationFile", content_type="application/pdf", value=actual_file_name)) ###################################################################### # Step 2: Writing AAS objects and auxiliary files to an AASX package # ###################################################################### # After setting everything up in Step 1, writing the AAS, including the Submodel objects and the auxiliary file # to an AASX package is simple. # Open an AASXWriter with the destination file name and use it as a context handler, to make sure it is properly closed ``` -------------------------------- ### Create and Configure Submodel Source: https://context7.com/eclipse-basyx/basyx-python-sdk/llms.txt Illustrates the creation of a `Submodel`, which groups related data elements describing an asset aspect. This example shows adding `Property` and `Range` elements to a `Submodel` and accessing them. ```python from basyx.aas import model submodel = model.Submodel( id_='https://example.org/submodels/Nameplate', submodel_element={ model.Property( id_short='ManufacturerName', value_type=model.datatypes.String, value='ACME Corp', semantic_id=model.ExternalReference(( model.Key(type_=model.KeyTypes.GLOBAL_REFERENCE, value='0173-1#02-AAO677#002'), )) ), model.Property( id_short='YearOfConstruction', value_type=model.datatypes.String, value='2024' ), model.Range( id_short='OperatingTemperature', value_type=model.datatypes.Float, min=-20.0, max=85.0 ) } ) # Access an element by id_short elem = submodel.submodel_element.get_object_by_attribute('id_short', 'ManufacturerName') print(elem.value) # ACME Corp ``` -------------------------------- ### Initialize DictObjectStore with AAS and Submodel Source: https://context7.com/eclipse-basyx/basyx-python-sdk/llms.txt Demonstrates the creation of an `AssetAdministrationShell` and a `Submodel`, linking them via a `ModelReference` within an in-memory object store context. This setup is typical for managing AAS objects. ```python from basyx.aas import model submodel = model.Submodel(id_='https://example.org/submodels/Nameplate') aas = model.AssetAdministrationShell( id_='https://example.org/aas/pump-001', asset_information=model.AssetInformation(global_asset_id='http://example.org/asset/pump-001'), submodel={model.ModelReference.from_referable(submodel)} ) ``` -------------------------------- ### Example Commit/PR Titles Source: https://github.com/eclipse-basyx/basyx-python-sdk/blob/main/CONTRIBUTING.md Follow the same conventions as issue titles for commit and pull request titles, indicating the module and using imperative language. ```text model.datatypes: Add type `xs:someThingMadeUp` compliance_tool: Fix fail to check aasx package without thumbnail adapter.aasx: Fix `Property.value` `0` converted into `NoneType` ``` -------------------------------- ### Example Issue Titles Source: https://github.com/eclipse-basyx/basyx-python-sdk/blob/main/CONTRIBUTING.md Use concise, imperative titles for issues, mentioning the affected module if known. Inline code blocks highlight class names or types. ```text model.datatypes: Missing type `xs:someThingMadeUp` compliance_tool: Fail to check aasx package without thumbnail adapter.aasx: `Property.value` `0` are converted into `NoneType` ``` -------------------------------- ### Combine Multiple Object Providers with ObjectProviderMultiplexer Source: https://context7.com/eclipse-basyx/basyx-python-sdk/llms.txt Use ObjectProviderMultiplexer to combine multiple stores into a single provider for unified access. The `get()` method returns None for missing identifiers instead of raising an error. ```python from basyx.aas import model store_a: model.DictObjectStore[model.Identifiable] = model.DictObjectStore() store_b: model.DictObjectStore[model.Identifiable] = model.DictObjectStore() submodel_a = model.Submodel(id_='https://example.org/submodels/A') submodel_b = model.Submodel(id_='https://example.org/submodels/B') store_a.add(submodel_a) store_b.add(submodel_b) multiplexer = model.ObjectProviderMultiplexer([store_a, store_b]) result = multiplexer.get_identifiable('https://example.org/submodels/B') print(result.id) # https://example.org/submodels/B # get() returns None for missing identifiers instead of raising KeyError missing = multiplexer.get('https://example.org/submodels/MISSING') print(missing) # None ``` -------------------------------- ### Initialize and Use LocalFileObjectStore Source: https://context7.com/eclipse-basyx/basyx-python-sdk/llms.txt Demonstrates initializing a `LocalFileObjectStore` pointing to a local directory, creating the directory if it doesn't exist, adding objects (which are persisted as JSON files), retrieving them by identifier, and discarding them. ```python from basyx.aas import model from basyx.aas.backend.local_file import LocalFileObjectStore # Initialize store pointing to a local directory store = LocalFileObjectStore('/tmp/my_aas_store') store.check_directory(create=True) # Create directory if it doesn't exist # Add objects — each is immediately persisted as a JSON file submodel = model.Submodel( id_='https://example.org/submodels/Nameplate', submodel_element={ model.Property(id_short='ManufacturerName', value_type=model.datatypes.String, value='ACME') } ) store.add(submodel) # Retrieve by identifier retrieved = store.get_identifiable('https://example.org/submodels/Nameplate') print(retrieved.id) # https://example.org/submodels/Nameplate # Discard (removes the JSON file from disk) store.discard(submodel) ``` -------------------------------- ### Install and Use AAS Compliance Tool Source: https://context7.com/eclipse-basyx/basyx-python-sdk/llms.txt The `aas-compliance-check` CLI tool validates AAS files against the official schema. Install it via pip and use various commands to create, check, and compare AAS files in JSON, XML, or AASX formats. ```bash # Install pip install aas-compliance-tool # Create an example AAS JSON file aas-compliance-check create example_output.json --json # Create an example AASX package aas-compliance-check create example_output.aasx --json --aasx # Check schema compliance and deserialisability of a JSON file aas-compliance-check deserialization my_aas.json --json # Check if a file contains the expected example AAS data aas-compliance-check example my_aas.json --json # Compare two XML files for AAS element equivalence (order-independent) aas-compliance-check files file_a.xml file_b.xml --xml # Check an AASX file with verbose output aas-compliance-check deserialization my_package.aasx --aasx -v # Suppress output on success; write failures to a log file aas-compliance-check deserialization my_aas.json --json -q -l check.log # Alternative invocation python -m aas_compliance_tool.cli schema my_aas.json --json ``` -------------------------------- ### Initialize and Use CouchDBObjectStore Source: https://context7.com/eclipse-basyx/basyx-python-sdk/llms.txt Shows how to register CouchDB server credentials, create a `CouchDBObjectStore`, add AAS objects (which are immediately sent to CouchDB), retrieve them by identifier, and remove them. ```python import basyx.aas.backend.couchdb # Register server credentials (called once per server URL) basyx.aas.backend.couchdb.register_credentials( url='http://localhost:5984', username='admin', password='secret' ) # Create the store object_store = basyx.aas.backend.couchdb.CouchDBObjectStore( url='http://localhost:5984', database='aas_db' ) from basyx.aas import model submodel = model.Submodel( id_='https://example.org/submodels/Nameplate', submodel_element={ model.Property(id_short='SerialNumber', value_type=model.datatypes.String, value='SN-001') } ) # Add — immediately sends to CouchDB object_store.add(submodel) # Retrieve retrieved = object_store.get_identifiable('https://example.org/submodels/Nameplate') print(retrieved.id) # https://example.org/submodels/Nameplate # Remove object_store.discard(submodel) ``` -------------------------------- ### Create and Configure AssetAdministrationShell Source: https://context7.com/eclipse-basyx/basyx-python-sdk/llms.txt Demonstrates creating an `AssetAdministrationShell` object, which serves as the digital twin envelope for an asset. It includes setting up `AssetInformation` and referencing associated `Submodel` objects. ```python from basyx.aas import model # Create AssetInformation describing the physical asset asset_information = model.AssetInformation( asset_kind=model.AssetKind.INSTANCE, global_asset_id='http://example.org/assets/pump-001' ) # Create the AAS with a reference to a submodel submodel = model.Submodel(id_='https://example.org/submodels/Nameplate') aas = model.AssetAdministrationShell( id_='https://example.org/aas/pump-001', asset_information=asset_information, submodel={model.ModelReference.from_referable(submodel)} ) print(aas.id) # https://example.org/aas/pump-001 print(aas.asset_information.global_asset_id) # http://example.org/assets/pump-001 print(len(aas.submodel)) # 1 ``` -------------------------------- ### Configure and Connect to CouchDB Source: https://github.com/eclipse-basyx/basyx-python-sdk/blob/main/sdk/docs/source/tutorials/tutorial_backend_couchdb.md Reads CouchDB connection details from a configuration file and registers credentials with the CouchDB backend. This prepares the SDK for communication with the CouchDB server. ```python config = ConfigParser() config.read([Path(__file__).parent.parent.parent.parent / 'test' / 'test_config.default.ini', Path(__file__).parent.parent.parent.parent / 'test' / 'test_config.ini']) couchdb_url = config['couchdb']['url'] couchdb_database = config['couchdb']['database'] couchdb_user = config['couchdb']['user'] couchdb_password = config['couchdb']['password'] basyx.aas.backend.couchdb.register_credentials(couchdb_url, couchdb_user, couchdb_password) object_store = basyx.aas.backend.couchdb.CouchDBObjectStore(couchdb_url, couchdb_database) ``` -------------------------------- ### Store AAS Objects in CouchDB Source: https://github.com/eclipse-basyx/basyx-python-sdk/blob/main/sdk/docs/source/tutorials/tutorial_backend_couchdb.md Creates example Submodel objects and adds them to the CouchDBObjectStore. The objects are immediately transferred to the CouchDB server upon addition. ```python example_submodel1 = basyx.aas.examples.data.example_aas.create_example_asset_identification_submodel() example_submodel2 = basyx.aas.examples.data.example_aas.create_example_bill_of_material_submodel() object_store.add(example_submodel1) object_store.add(example_submodel2) ``` -------------------------------- ### Initialize and Use ObjectStore Source: https://github.com/eclipse-basyx/basyx-python-sdk/blob/main/sdk/docs/source/tutorials/tutorial_storage.md Initialize a `DictObjectStore` for in-memory storage and add AAS objects to it. For persistent storage, consider `CouchDBObjectStore`. ```python # Step 2.1: create an ObjectStore for identifiable objects # # In this tutorial, we use a `DictObjectStore`, which is a simple in-memory store: It just keeps track of the Python # objects using a dict. # This may not be a suitable solution, if you need to manage large numbers of objects or objects must be kept in a # persistent memory (i.e. on hard disk). In this case, you may choose the `CouchDBObjectStore` from # `aas.backends.couchdb` to use a CouchDB database server as persistent storage. Both ObjectStore implementations # provide the same interface. In addition, the CouchDBObjectStores allows synchronizing the local object with the # database via a Backend. See the `tutorial_backend_couchdb.py` for more information. obj_store: model.DictObjectStore[model.Identifiable] = model.DictObjectStore() # step 2.2: add submodel and asset administration shell to store obj_store.add(submodel) obj_store.add(aas) ``` -------------------------------- ### Create and Write AASX Package Source: https://context7.com/eclipse-basyx/basyx-python-sdk/llms.txt Demonstrates how to create an AAS, a Submodel, add a supplementary file, reference it from the Submodel, and write the package to an AASX file. Also shows how to read the package back. ```python from basyx.aas import model, aasx import datetime from pyecma376_2 import OPCCoreProperties # Build an AAS with a submodel referencing a PDF submodel = model.Submodel(id_='https://example.org/submodels/Docs') aas = model.AssetAdministrationShell( id_='https://example.org/aas/pump-001', asset_information=model.AssetInformation( asset_kind=model.AssetKind.INSTANCE, global_asset_id='http://example.org/asset/pump-001' ), submodel={model.ModelReference.from_referable(submodel)} ) object_store = model.DictObjectStore([submodel, aas]) # Add a supplementary file to a SupplementaryFileContainer file_store = aasx.DictSupplementaryFileContainer() with open('manual.pdf', 'rb') as f: actual_name = file_store.add_file('/aasx/suppl/manual.pdf', f, 'application/pdf') # Reference the file from the submodel submodel.submodel_element.add( model.File(id_short='Manual', content_type='application/pdf', value=actual_name) ) # Write AASX package with aasx.AASXWriter('package.aasx') as writer: writer.write_aas( aas_ids=['https://example.org/aas/pump-001'], object_store=object_store, file_store=file_store ) meta = OPCCoreProperties() meta.creator = 'My Application' meta.created = datetime.datetime.now() writer.write_core_properties(meta) # Read AASX package back new_store: model.DictObjectStore[model.Identifiable] = model.DictObjectStore() new_files = aasx.DictSupplementaryFileContainer() with aasx.AASXReader('package.aasx') as reader: reader.read_into(object_store=new_store, file_store=new_files) core_props = reader.get_core_properties() print(core_props.creator) # My Application print('/aasx/suppl/manual.pdf' in new_files) # True ``` -------------------------------- ### Run All SDK Checks Source: https://github.com/eclipse-basyx/basyx-python-sdk/blob/main/CONTRIBUTING.md Execute static analysis and unit tests for the SDK. This includes type checking, style checking, and running unit tests with coverage. ```bash mypy basyx test pycodestyle --max-line-length 120 basyx test python -m unittest coverage run --source basyx --branch -m unittest coverage report -m ``` -------------------------------- ### Build Docker Image Source: https://github.com/eclipse-basyx/basyx-python-sdk/blob/main/server/README.md Build the Docker image for the BaSyx Python server. Ensure line separators are LF (`\n`) in script files if cloning on Windows. ```bash docker build -t basyx-python-server -f Dockerfile .. ``` -------------------------------- ### Build and Run Basyx Python Server with Docker Compose Source: https://github.com/eclipse-basyx/basyx-python-sdk/blob/main/server/README.md Command to build and run the Basyx Python server container using Docker Compose. ```bash $ docker compose up ``` -------------------------------- ### Run Basyx Python Server with Docker Source: https://github.com/eclipse-basyx/basyx-python-sdk/blob/main/server/README.md Basic command to run the Basyx Python server container, mapping ports and volumes for input and storage. ```bash $ docker run -p 8080:80 -v ./input:/input -v ./storage:/storage basyx-python-server ``` -------------------------------- ### create_example_asset_identification_submodel Source: https://github.com/eclipse-basyx/basyx-python-sdk/blob/main/sdk/docs/source/examples/example_aas.md Creates a Submodel containing two Property elements according to 'Verwaltungsschale in der Praxis'. ```APIDOC ## create_example_asset_identification_submodel() ### Description Creates a [`Submodel`](../model/submodel.md#basyx.aas.model.submodel.Submodel) containing two [`Property`](../model/submodel.md#basyx.aas.model.submodel.Property) elements according to ‘Verwaltungsschale in der Praxis’ [https://www.plattform-i40.de/PI40/Redaktion/DE/Downloads/Publikation/2019-verwaltungsschale-in-der-praxis.html](https://www.plattform-i40.de/PI40/Redaktion/DE/Downloads/Publikation/2019-verwaltungsschale-in-der-praxis.html) ### Returns example asset identification submodel ``` -------------------------------- ### Docker Compose Configuration for Basyx Python Server Source: https://github.com/eclipse-basyx/basyx-python-sdk/blob/main/server/README.md Exemplary `compose.yml` file for setting up the Basyx Python server, including build context, ports, volumes, and environment variables. ```yaml name: basyx-python-server services: app: build: context: .. dockerfile: server/Dockerfile ports: - "8080:80" volumes: - ./input:/input - ./storage:/storage environment: STORAGE_PERSISTENCY: True ``` -------------------------------- ### Create ObjectStore for serialization Source: https://github.com/eclipse-basyx/basyx-python-sdk/blob/main/sdk/docs/source/tutorials/tutorial_serialization_deserialization.md Initializes an `ObjectStore` and adds AAS objects to it, preparing them for serialization into a standard-compliant JSON or XML file. ```python obj_store: model.DictObjectStore[model.Identifiable] = model.DictObjectStore() obj_store.add(submodel) obj_store.add(aashell) ``` -------------------------------- ### Initialize AASX Writer and Reader Source: https://context7.com/eclipse-basyx/basyx-python-sdk/llms.txt Prepare to create or parse AASX package files, which can contain AAS objects and supplementary files. This involves importing the necessary classes from `basyx.aas.adapter.aasx`. ```python import datetime import pyecma376_2 from basyx.aas import model from basyx.aas.adapter import aasx ``` -------------------------------- ### Create Blob and File Elements Source: https://context7.com/eclipse-basyx/basyx-python-sdk/llms.txt Use `Blob` to store inline binary data and `File` to reference external files. Both require a `content_type` to specify the data format. ```python from basyx.aas import model # Blob: inline binary data blob_elem = model.Blob( id_short='DeviceCertificate', content_type='application/x-pem-file', value=b'-----BEGIN CERTIFICATE-----\nMIIB...\n-----END CERTIFICATE-----\n' ) # File: reference to a supplementary file in an AASX package file_elem = model.File( id_short='DocumentationPDF', content_type='application/pdf', value='/aasx/suppl/manual.pdf' ) submodel = model.Submodel( id_='https://example.org/submodels/Documents', submodel_element={blob_elem, file_elem} ) print(blob_elem.content_type) # application/x-pem-file print(file_elem.value) # /aasx/suppl/manual.pdf ``` -------------------------------- ### Build an AAS with a submodel referencing a PDF Source: https://context7.com/eclipse-basyx/basyx-python-sdk/llms.txt Demonstrates how to create an Asset Administration Shell (AAS) with a submodel that references a supplementary PDF file, and then write this package to an AASX file. ```APIDOC ## Build an AAS with a submodel referencing a PDF This example shows how to construct an AAS, associate a submodel with it, and include a reference to an external PDF file within that submodel. The entire structure is then packaged into an AASX file. ### Steps: 1. Create a `Submodel` instance. 2. Create an `AssetAdministrationShell` instance, linking it to the `Submodel` via `ModelReference`. 3. Populate an `ObjectStore` with the created `Submodel` and `AAS`. 4. Use `AASXWriter` to write the AAS and submodel to a package (`.aasx` file). 5. Add a supplementary file (e.g., 'manual.pdf') to a `DictSupplementaryFileContainer` and get its actual name. 6. Reference this file from a `File` submodel element within the submodel. 7. Write core properties to the AASX package. 8. Demonstrate reading the AASX package back using `AASXReader` and verifying its contents. ``` -------------------------------- ### create_example_bill_of_material_submodel Source: https://github.com/eclipse-basyx/basyx-python-sdk/blob/main/sdk/docs/source/examples/example_aas.md Creates a Submodel for the bill of material containing two entities, one co-managed and one self-managed. ```APIDOC ## create_example_bill_of_material_submodel() ### Description Creates a [`Submodel`](../model/submodel.md#basyx.aas.model.submodel.Submodel) for the bill of material containing two entities one co-managed and one self-managed ### Returns example bill of material submodel ``` -------------------------------- ### Create and Resolve ModelReferences and ExternalReferences Source: https://context7.com/eclipse-basyx/basyx-python-sdk/llms.txt Demonstrates creating `ModelReference` for internal model objects and `ExternalReference` for external resources. `ModelReference` can be resolved against an `ObjectProvider`. ```python from basyx.aas import model submodel = model.Submodel( id_='https://example.org/submodels/Nameplate', submodel_element={ model.Property(id_short='SerialNumber', value_type=model.datatypes.String, value='SN-001') } ) store = model.DictObjectStore([submodel]) # Create a ModelReference to a nested Property using the convenience method submodel_ref = model.ModelReference.from_referable(submodel) # Create a multi-key ModelReference directly prop_ref = model.ModelReference( ( model.Key(type_=model.KeyTypes.SUBMODEL, value='https://example.org/submodels/Nameplate'), model.Key(type_=model.KeyTypes.PROPERTY, value='SerialNumber'), ), type_=model.Property ) resolved_property = prop_ref.resolve(store) print(resolved_property.value) # SN-001 # ExternalReference for semantic IDs semantic_ref = model.ExternalReference( (model.Key(type_=model.KeyTypes.GLOBAL_REFERENCE, value='0173-1#02-AAM556#002'),) ) print(semantic_ref.key[0].value) # 0173-1#02-AAM556#002 ``` -------------------------------- ### Run Basyx Python Server with Docker (Windows) Source: https://github.com/eclipse-basyx/basyx-python-sdk/blob/main/server/README.md Command for running the Basyx Python server container on Windows, adjusting path separators for volume mounts. ```powershell > docker run -p 8080:80 -v .\input:/input -v .\storage:/storage basyx-python-server ``` -------------------------------- ### Create AssetInformation and AAS Source: https://github.com/eclipse-basyx/basyx-python-sdk/blob/main/sdk/docs/source/tutorials/tutorial_create_simple_aas.md Initializes an AssetInformation object and then creates an AssetAdministrationShell using this information. This is the foundational step for defining an AAS. ```python # Import all Eclipse BaSyx Python SDK classes from model package from basyx.aas import model # In this tutorial, you'll get a step-by-step guide on how to create an Asset Administration Shell (AAS) and all # required objects within. First, you need an AssetInformation object for which you want to create an AAS. After that, # an Asset Administration Shell can be created. Then, it's possible to add Submodels to the AAS. The Submodels can # contain SubmodelElements. # # Step-by-Step Guide: # Step 1: create a simple Asset Administration Shell, containing AssetInformation object # Step 2: create a simple Submodel # Step 3: create a simple Property and add it to the Submodel ############################################################################################ # Step 1: Create a Simple Asset Administration Shell Containing an AssetInformation object # ############################################################################################ # Step 1.1: create the AssetInformation object asset_information = model.AssetInformation( asset_kind=model.AssetKind.INSTANCE, global_asset_id='http://acplt.org/Simple_Asset' ) # step 1.2: create the Asset Administration Shell identifier = 'https://acplt.org/Simple_AAS' aas = model.AssetAdministrationShell( id_=identifier, # set identifier asset_information=asset_information ) ``` -------------------------------- ### Create Property and Add to Submodel Source: https://github.com/eclipse-basyx/basyx-python-sdk/blob/main/sdk/docs/source/tutorials/tutorial_create_simple_aas.md Defines a Property with a semantic description, value type, and value, then adds it to the Submodel. This demonstrates how to populate a Submodel with data elements. ```python ############################################################### # Step 3: Create a Simple Property and Add it to the Submodel # ############################################################### # Step 3.1: create a global reference to a semantic description of the Property # A global reference consist of one key which points to the address where the semantic description is stored semantic_reference = model.ExternalReference( (model.Key( type_=model.KeyTypes.GLOBAL_REFERENCE, value='http://acplt.org/Properties/SimpleProperty' ),) ) # Step 3.2: create the simple Property property_ = model.Property( id_short='ExampleProperty', # Identifying string of the element within the Submodel namespace value_type=model.datatypes.String, # Data type of the value value='exampleValue', # Value of the Property semantic_id=semantic_reference # set the semantic reference ) # Step 3.3: add the Property to the Submodel submodel.submodel_element.add(property_) ``` -------------------------------- ### Run Basyx Python Server with Custom Environment Variables Source: https://github.com/eclipse-basyx/basyx-python-sdk/blob/main/server/README.md Command to run the Basyx Python server container with custom environment variables to override default settings for API base path, input/storage directories, and persistence. ```bash $ docker run -p 8080:80 -v ./input:/input2 -v ./storage:/storage2 -e API_BASE_PATH=/api/v3.1/ -e INPUT=/input2 -e STORAGE=/storage2 -e STORAGE_PERSISTENCY=True -e STORAGE_OVERWRITE=True basyx-python-server ```