serialization

aas_client3_2.serialization implements the Serialization API: the server exports the shells, the submodels and, optionally, the concept descriptions you select as one environment, in JSON, XML or as an AASX package. The server of the Serialization API usually serves the repositories as well, as the AAS Environment of the BaSyx Go components does, here at http://localhost:5011.

import requests

import aas_core3_2.types as aas_types

from aas_client3_2 import (
    aas_repository as aas_client_aas_repository,
    http as aas_client_http,
    requests_transport as aas_client_requests_transport,
    serialization as aas_client_serialization,
)

server = aas_client_http.Server(
    transport=aas_client_requests_transport.RequestsTransport(
        requests.Session()
    ),
    base_url="http://localhost:5011",
)

shell = aas_types.AssetAdministrationShell(
    id="https://example.com/ids/aas/getting-started/serialization",
    id_short="Conveyor",
    asset_information=aas_types.AssetInformation(
        asset_kind=aas_types.AssetKind.INSTANCE,
        global_asset_id="https://example.com/ids/asset/conveyor-0010",
    ),
)
aas_client_aas_repository.post_asset_administration_shell(
    server, shell
)

The serialization is a download, since an environment can be large. In JSON, parse it with aas_core3_2.jsonization:

import json

import aas_core3_2.jsonization as aas_jsonization

with aas_client_serialization.generate_serialization_by_ids(
    server,
    aas_ids=[shell.id],
    serialization_format=aas_client_serialization.SerializationFormat.JSON,
) as download:
    content = b""
    for chunk in download.iter_chunks():
        content += chunk

jsonable = json.loads(content)
environment = aas_jsonization.environment_from_jsonable(jsonable)

for (
    a_shell
) in environment.over_asset_administration_shells_or_empty():
    print(a_shell.id_short)

# Prints:
# Conveyor

Without serialization_format, the server gives XML, the default of the specification; write it to a file with write_to().

Clean Up

Delete what we created in this chapter, so that you can run the code of this chapter again. The identifiers are unique, so the server would refuse to create the shell a second time:

aas_client_aas_repository.delete_asset_administration_shell_by_id(
    server, shell.id
)