Skip to main content

The Eclipse BaSyx Python SDK, an implementation of the Asset Administration Shell for Industry 4.0 systems

Project description

Eclipse BaSyx Python SDK

(formerly known as PyI40AAS – Python Industry 4.0 Asset Administration Shell)

The Eclipse BaSyx Python project focuses on providing a Python implementation of the Asset Administration Shell (AAS) for Industry 4.0 Systems, compliant with the meta model and interface specification provided in the document “Details of the Asset Administration Shell” (v2.0.1). It currently adheres to version 2.0.1 of the specification. An updated version with support for version 3.0RC01 is already in preparation and will be made available on an additional branch of this repository and in a future major release.

Features

  • Modelling of AASs as Python objects (according to DotAAS sec. 4)
    • except for: Security extension of the metamodel (according to DotAAS sec. 5), HasDataSpecification
  • Reading and writing of AASX package files (according to DotAAS sec. 6)
  • (De-)serialization of AAS objects into/from JSON and XML (according to DotAAS sec. 7)
  • Storing of AAS objects in CouchDB, Backend infrastructure for easy expansion
  • Compliance checking of AAS XML and JSON files

Project Structure

The BaSyx Python SDK project provides the basax.aas Python package with 6 submodules:

  • basyx.aas.model: The AAS metamodel implemented in python
  • basyx.aas.adapter: Adapters for various file formats
  • basyx.aas.backend: Backend infrastructure for storing and retrieving AAS objects
  • basyx.aas.compliance_tool: Compliance checker for AAS files
  • basyx.aas.util: Provides utilities
  • basyx.aas.examples: Example data and tutorials

License

The BaSyx Python SDK project is licensed under the terms of the MIT License.

SPDX-License-Identifier: MIT

For more information, especially considering the licenses of included third-party works, please consult the NOTICE file.

Dependencies

The BaSyx Python SDK requires the following Python packages to be installed for production usage. These dependencies are listed in setup.py to be fetched automatically when installing with pip:

  • lxml (BSD 3-clause License, using libxml2 under MIT License)
  • python-dateutil (BSD 3-clause License)
  • pyecma376-2 (Apache License v2.0)
  • urllib3 (MIT License)

Optional production usage dependencies:

  • For using the Compliance Tool to validate JSON files against the JSON Schema: jsonschema and its dependencies (MIT License, Apache License, PSF License)

Development/testing/example dependencies (see requirements.txt):

  • jsonschema and its dependencies (MIT License, Apache License, PSF License)
  • psutil (BSD 3-clause License)

Getting Started

Installation

Eclipse BaSyx Python SDK can be installed from PyPI, the Python Package Index, just as nearly every other Python package:

pip install basyx-python-sdk

For working with the current development version, you can also install the package directly from GitHub, using Pip's Git feature:

pip install git+https://github.com/eclipse-basyx/basyx-python-sdk.git@main

You may want to use a Python's venv or a similar tool to install BaSyx Python SDK and its dependencies only in a project-specific local environment.

Example

The following code example shows how to create a Submodel with a Property serialize it into an XML file using the Eclipse BaSyx Python SDK:

Create a Submodel:

from basyx.aas import model  # Import all BaSyx Python SDK classes from the model package

identifier = model.Identifier('https://acplt.org/Simple_Submodel', model.IdentifierType.IRI)
submodel = model.Submodel(identification=identifier)

Create a Property and add it to the Submodel:

# create a global reference to a semantic description of the property
semantic_reference = model.Reference(
    (model.Key(
        type_=model.KeyElements.GLOBAL_REFERENCE,
        local=False,
        value='http://acplt.org/Properties/SimpleProperty',
        id_type=model.KeyType.IRI
    ),)
)
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)

Serialize the Submodel to XML:

from basyx.aas.adapter import write_aas_xml_file

data: model.DictObjectStore[model.Identifiable] = model.DictObjectStore()
data.add(submodel)
with open('Simple_Submodel.xml', 'w', encoding='utf-8') as f:
    write_aas_xml_file(file=f, data=data)

Examples and Tutorials

For further examples and tutorials, check out the basyx.aas.examples-package. Here is a quick overview:

  • tutorial_create_simple_aas: Create an Asset Administration Shell, including an Asset object and a Submodel
  • tutorial_storage: Manage a larger number of Asset Administration Shells in an ObjectStore and resolve references
  • tutorial_serialization_deserialization: Use the JSON and XML serialization/deserialization for single objects or full standard-compliant files
  • tutorial_aasx: Export Asset Administration Shells with related objects and auxiliary files to AASX package files
  • tutorial_backend_couchdb: Use the Backends interface (update()/commit() methods) to manage and retrieve AAS objects in a CouchDB document database

Documentation

A detailed, complete API documentation is available on Read the Docs: https://basyx-python-sdk.readthedocs.io

Compliance Tool

The Eclipse BaSyx Python SDK project contains a compliance tool for testing xml and json files is provided in the basyx.aas.compliance_tool-package. Following functionalities are supported:

  • create an xml or json file compliant to the official schema containing example Asset Administration Shell elements
  • create an aasx file with xml or json files compliant to the official schema containing example Asset Administration Shell elements
  • check if a given xml or json file is compliant to the official schema
  • check if a given xml, json or aasx file is readable even if it is not compliant to the offical schema
  • check if the data in a given xml, json or aasx file is the same as the example data
  • check if two given xml, json or aasx files contain the same Asset Administration Shell elements in any order

Invoking should work with either python -m basyx.aas.compliance_tool.cli or (when installed correctly and PATH is set correctly) with aas-compliance-check on the command line.

For further usage information consider the basyx.aas.compliance_tool-package or invoke with python -m basyx.aas.compliance_tool.cli --help respectively aas-compliance-check --help.

Development

Codestyle and Testing

Our code follows the PEP 8 -- Style Guide for Python Code. Additionally, we use PEP 484 -- Type Hints throughout the code to enable type checking the code.

Before submitting any changes, make sure to let mypy and pycodestyle check your code and run the unit tests with Python's builtin unittest. To install the required tools, use:

pip install mypy pycodestyle

Running all checks:

mypy basyx test
pycodestyle --max-line-length 120 basyx test
python -m unittest

We aim to cover our code with test by at least 80%. To check test coverage, you can use coverage:

pip install coverage
coverage run --source basyx --branch -m unittest
coverage report -m

Eclipse Contributor Agreement

To contribute code to this project you need to sign the Eclipse Contributor Agreement (ECA). This is done by creating an Eclipse account for your git e-mail address and then submitting the following form: https://accounts.eclipse.org/user/eca

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

basyx-python-sdk-0.2.2.tar.gz (140.7 kB view details)

Uploaded Source

Built Distribution

basyx_python_sdk-0.2.2-py3-none-any.whl (166.5 kB view details)

Uploaded Python 3

File details

Details for the file basyx-python-sdk-0.2.2.tar.gz.

File metadata

  • Download URL: basyx-python-sdk-0.2.2.tar.gz
  • Upload date:
  • Size: 140.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for basyx-python-sdk-0.2.2.tar.gz
Algorithm Hash digest
SHA256 e1fe8891f05a2079bf03c8bb39ae9016461778d291374b400a58e4210ef290af
MD5 073b177b9984cf87e906d4bddaf47c63
BLAKE2b-256 fb3f52336ab9b421706aaacce85f03dfc0fb6296f05727aa9425f163a08e0d6f

See more details on using hashes here.

File details

Details for the file basyx_python_sdk-0.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for basyx_python_sdk-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5b535311369537235a4678ba995f8ef50ca9d52b3cc7e8318a1586f6120f2d2b
MD5 a0bd134b8026c464aefa44c4e9d5ead5
BLAKE2b-256 01214d90b774933580c8fc406e1778b8f0b48370ddbbfe77e9bea55d5b351124

See more details on using hashes here.

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