config

This module contains code to standardize the configuration of Panorama applications via deploy-time parameters. It also contains a CLI (command-line interface) that generates configuration snippets for the metadata and descriptor json files of your Panorama project.

Defining config structures

This module defines ConfigBase, a base class for Panorama application configurations. The class offers two basic functionalities:

  • parse parameters from the Panorama application input ports (panoramasdk.node.inputs)

  • generate configuration file snippets for graph.json and package.json in your Panorama project. For more information about how to use the CLI, refer to tool().

class backpack.config.ConfigBase

Bases: object

Base class for configuration structures.

Subclasses must be also dataclasses.

get_panorama_definitions(serde_metadata={})

Generate the nodeGraph.nodes snippet in graph.json.

Returns:

A list of dictionaries containing the application parameter node definitions.

Parameters:

serde_metadata (Mapping[str, Any]) –

Return type:

List[Mapping[str, Any]]

get_panorama_edges(code_node_name)

Generate the nodeGraph.edges snippet in graph.json

Returns:

A list of dictionaries containing the application edge definitions.

Parameters:

code_node_name (str) –

Return type:

List[Mapping[str, str]]

get_panorama_app_interface()

Generate the application interface snippet in app node package.json.

Returns:

A list of dictionaries containing the elements of the application interface definition.

Return type:

List[Mapping[str, str]]

get_panorama_markdown_doc(serde_metadata={})

Generates a markdown table of the parameters that can be used in documentation.

Returns:

Markdown formatted text containing the parameter documentation.

Parameters:

serde_metadata (Mapping[str, Any]) –

Return type:

str

classmethod from_panorama_params(inputs, serde_metadata={})

Parses the config values form AWS Panorama input parameters.

A new Config object is created with the default values. If a particular value is found in the input parameter, its value will override the default value.

Parameters:
  • inputs (panoramasdk.port) – The input port of the Panorama application node.

  • serde_metadata (Mapping[str, Any]) –

Returns:

The config instance filled with the parameter values read from the input port.

Return type:

T

Command-line interface

The config.tool module defines a simple command-line interface (CLI) program that can be used as a development tool. It creates snippets that you can copy-paste into the Panorama application project files like graph.json, or package.json of the business logic package.

config.cli(config)

Creates a simple command line interface for printing config snippets.

Parameters:
  • name (str) – The name of your Panorama app

  • config (ConfigBase) – Instance of your configuration structure, subclass of ConfigBase.

Return type:

None

Defining serializers/deserializers

Serializers/Deserializers (SerDe) convert between configuration strings (or numbers) and different Python structures.

You should subclass ConfigSerDeBase and override the following static fields:

  • name: the description of the structure this serde can convert, for example “Comma-separated list of integers”. This text will be used in the documentation generated by the ConfigBase CLI.

  • serialize: Take the Python structure and returns a string representation.

  • deserialize: Take a string representation of the value and return a Python structure.

class backpack.config.ConfigSerDeBase

Bases: ABC

Defines a serializer / deserializer interface.

description: str = 'The base serde encodes and decodes strings to themselves.'

A textual description how the object is encoded in the string. Will be used in docs.

example: str = 'abcdefgh'

Provide a textual example of the encoded string. Will be used in docs.

abstract static serialize(value, metadata={})

Serializes a config value to a string.

Parameters:
  • value (Any) – a Python object to be serialized.

  • metadata (Mapping[str, Any]) – Additional metadata to be passed to SerDe implementations.

Returns:

The object serialized into a string.

Return type:

str

abstract static deserialize(value, metadata={})

Deserializes a string to a config value.

Parameters:
  • value (str) – a Python object serialized into a string

  • metadata (Mapping[str, Any]) – Additional metadata to be passed to SerDe implementations.

Returns:

The the restored Python object.

Return type:

Any

List of SerDe implementations

class backpack.config.IntegerListSerDe

Bases: ConfigSerDeBase

De/serializes a string containing a comma-separated list of integers.

description: str = 'Comma-separated list of integers'

A textual description how the object is encoded in the string. Will be used in docs.

example: str = '0, 1, 2'

Provide a textual example of the encoded string. Will be used in docs.

static serialize(value, metadata={})

Serializes a list of integers into a string.

Parameters:
  • value (Sequence[int]) – The list of integers.

  • metadata (Mapping[str, Any]) –

Returns:

The list of integers serialized into a string.

Return type:

str

static deserialize(value, metadata={})

Restores a list of integers from a string.

Parameters:
  • value (str) – A string containing a serialized list of integers.

  • metadata (Mapping[str, Any]) –

Returns:

The list of integers restored from the string.

Raises:

Exception – exceptions related to invalid string format.

Return type:

List[int]

class backpack.config.geometry.PolyLineSerDe

Bases: ConfigSerDeBase

De/serializes a json string containing a polygon definition.

Example string: [[0.1, 0.1], [0.9, 0.1], [0.9, 0.9], [0.5, 0.5], [0.1, 0.9]]

description: str = 'JSON encoded Polygon'

A textual description how the object is encoded in the string. Will be used in docs.

example: str = '[[0.1, 0.1], [0.9, 0.1], [0.9, 0.9], [0.5, 0.5], [0.1, 0.9]]'

Provide a textual example of the encoded string. Will be used in docs.

static serialize(value, metadata={})

Serializes a PolyLine into a string.

Parameters:
Returns:

The PolyLine serialized into a string.

Return type:

str

static deserialize(value, metadata={})

Restores a PolyLine from a string.

Parameters:
  • value (str) – A string containing a serialized PolyLine.

  • metadata (Mapping[str, Any]) –

Returns:

The PolyLine restored from the string or None if the string was empty.

Raises:

Exception – exceptions related to invalid string format.

Return type:

Optional[PolyLine]