aas_client3_2.aasx_file_server

Implement the operations of the AASX File Server API.

The module also implements the AASX Async File Server API, and its Status and Result APIs.

Every public function implements exactly one operation of the specification. The private functions _build_* and _parse_* build the request and parse the response of the operation. They do no I/O, and constitute a semi-public interface for the testing client, which is released in lockstep with this client.

aas_client3_2.aasx_file_server.CONTENT_TYPE: Final[str] = 'application/asset-administration-shell-package'

Content type of an AASX package, as the OpenAPI gives it for the uploads and the downloads of the packages

aas_client3_2.aasx_file_server.get_all_aasx_package_ids(server: Server, *, aas_id: str | None = None, limit: int | None = None, cursor: str | None = None) → GetPackageDescriptionsResult[source]

List a page of the descriptions of the AASX packages on the server.

A description gives the ID of a package, and the identifiers of the shells it contains.

Parameters:
  • server – where to send the request

  • aas_id – if set, only the packages which contain this shell

  • limit – maximum number of the descriptions in the page

  • cursor – where to continue the listing from

Returns:

a page of the descriptions of the packages

Implements:
  • GetAllAASXPackageIds – GET /packages

aas_client3_2.aasx_file_server.post_aasx_package(server: Server, file: bytes | IO[bytes], *, aas_ids: Sequence[str] | None = None, file_name: str | None = None) → PackageDescription[source]

Upload a new AASX package.

The content is either bytes, or a binary file object which is readable and seekable; it is read from its current position to its end, in chunks, so that a large package is never held in memory. The file object must not be modified during the upload. The package is sent with the content type CONTENT_TYPE.

Parameters:
  • server – where to send the request

  • file – the content of the package

  • aas_ids – if set, the identifiers of the shells which the package contains

  • file_name – if set, the name of the file of the package

Returns:

the description of the package, with the ID which the server assigned

Raises:

TypeError or ValueError before sending anything if file can not be read again, or if file_name contains characters which would break the multipart envelope

Implements:
  • PostAASXPackage – POST /packages

aas_client3_2.aasx_file_server.get_aasx_by_package_id(server: Server, package_id: str) → ContextManager[Download][source]

Download the AASX package with the given ID.

The content is streamed, so use the result as a context manager:

with aasx_file_server.get_aasx_by_package_id(server, package_id) as download:
    with open("package.aasx", "wb") as fid:
        download.write_to(fid)

The connection is released when the context is exited.

Parameters:
  • server – where to send the request

  • package_id – ID of the package

Returns:

a context manager which gives the download

Raises:

NotFound if there is no such package

Implements:
  • GetAASXByPackageId – GET /packages/{packageId}

aas_client3_2.aasx_file_server.put_aasx_by_package_id(server: Server, package_id: str, file: bytes | IO[bytes], *, aas_ids: Sequence[str] | None = None, file_name: str | None = None) → None[source]

Create or replace the AASX package with the given ID.

See post_aasx_package() for the content.

Parameters:
  • server – where to send the request

  • package_id – ID of the package

  • file – the content of the package

  • aas_ids – if set, the identifiers of the shells which the package contains

  • file_name – if set, the name of the file of the package

Raises:

TypeError or ValueError before sending anything if file can not be read again, or if file_name contains characters which would break the multipart envelope

Implements:
  • PutAASXByPackageId – PUT /packages/{packageId}

aas_client3_2.aasx_file_server.delete_aasx_by_package_id(server: Server, package_id: str) → None[source]

Delete the AASX package with the given ID.

Parameters:
  • server – where to send the request

  • package_id – ID of the package

Implements:
  • DeleteAASXByPackageId – DELETE /packages/{packageId}

aas_client3_2.aasx_file_server.post_async_aasx_package(server: Server, file: bytes | IO[bytes], *, aas_ids: Sequence[str] | None = None, file_name: str | None = None) → OperationHandle[source]

Start uploading a new AASX package, and return at once.

The server processes the package asynchronously. Follow its progress with get_aasx_async_status(), and fetch the result with get_aasx_async_result(). See post_aasx_package() for the content.

Parameters:
  • server – where to send the request

  • file – the content of the package

  • aas_ids – if set, the identifiers of the shells which the package contains

  • file_name – if set, the name of the file of the package

Returns:

the handle of the upload

Raises:

TypeError or ValueError before sending anything if file can not be read again, or if file_name contains characters which would break the multipart envelope

Implements:
  • PostAsyncAASXPackage – POST /packages-async

aas_client3_2.aasx_file_server.get_aasx_async_status(server: Server, handle_id: str) → BaseOperationResult[source]

Get the status of the asynchronous upload with the given handle.

As for the asynchronous invocations of operations, the server redirects to the result once the upload is finished. The transport usually follows the redirect (the one based on requests does); if not, the client follows it, but only to the origin of the server. Either way, the status is taken from the result, so its execution_state tells whether the upload completed or failed.

Parameters:
Returns:

the status of the upload

Raises:

NotFound if there is no such upload; UnexpectedResponse if the server redirects to another origin

Implements:
  • GetAasxAsyncStatus – GET /packages-async/status/{handleId}

aas_client3_2.aasx_file_server.get_aasx_async_result(server: Server, handle_id: str) → BaseOperationResult[source]

Get the result of the finished asynchronous upload with the given handle.

A failed upload is a result with the execution_state Failed, not an error.

Parameters:
Returns:

the result of the upload

Raises:

NotFound if there is no such upload

Implements:
  • GetAasxAsyncResult – GET /packages-async/result/{handleId}