pip_services3_commons.config.ConfigParams module

pip_services3_commons.config.ConfigParams

Config params implementation

copyright

Conceptual Vision Consulting LLC 2018-2019, see AUTHORS for more details.

license

MIT, see LICENSE for more details.

class pip_services3_commons.config.ConfigParams.ConfigParams(values: Any = None)

Bases: pip_services3_commons.data.StringValueMap.StringValueMap

Contains a key-args map with configuration parameters. All values stored as strings and can be serialized as JSON or string forms. When retrieved the values can be automatically converted on read using GetAsXXX methods.

The keys are case-sensitive, so it is recommended to use consistent C-style as: “my_param”

Configuration parameters can be broken into sections and subsections using dot notation as: “section1.subsection1.param1”. Using GetSection method all parameters from specified section can be extracted from a ConfigMap.

The ConfigParams supports serialization from/to plain strings as: “key1=123;key2=ABC;key3=2016-09-16T00:00:00.00Z”

ConfigParams are used to pass configurations to IConfigurable objects. They also serve as a basis for more concrete configurations such as ConnectionParams or CredentialParams (in the Pip.Services components package).

Example:

config = ConfigParams.fromTuples("section1.key1", "AAA",
                                 "section1.key2", 123,
                                 "section2.key1", true)
config.get_as_string("section1.key1")  # Result: AAA
config.get_as_integer("section1.key1") # Result: 0

section1 = config.get_section("section1")
section1.__str__() # Result: key1=AAA;key2=123
add_section(section: str, section_params: pip_services3_commons.config.ConfigParams.ConfigParams)

Adds parameters into this ConfigParams under specified section. Keys for the new parameters are appended with section dot prefix.

Parameters
  • section – name of the section where add new parameters

  • section_params – new parameters to be added.

static from_string(line: str)pip_services3_commons.config.ConfigParams.ConfigParams

Creates a new ConfigParams object filled with key-args pairs serialized as a string.

Parameters

line – a string with serialized key-args pairs as “key1=value1;key2=value2;…”

Returns

a new ConfigParams object.

static from_tuples(*tuples: Any)pip_services3_commons.config.ConfigParams.ConfigParams

Creates a new ConfigParams object filled with provided key-args pairs called tuples. Tuples parameters contain a sequence of key1, value1, key2, value2, … pairs.

Parameters

tuples – the tuples to fill a new ConfigParams object.

Returns

a new ConfigParams object.

static from_value(value: Any)pip_services3_commons.config.ConfigParams.ConfigParams

Creates a new ConfigParams object filled with key-args pairs from specified object.

Parameters

value – an object with key-args pairs used to initialize a new ConfigParams.

Returns

a new ConfigParams object.

get_section(section: str)pip_services3_commons.config.ConfigParams.ConfigParams

Gets parameters from specific section stored in this ConfigMap. The section name is removed from parameter keys.

Parameters

section – name of the section to retrieve configuration parameters from.

Returns

all configuration parameters that belong to the section named ‘section’.

get_section_names() → List[str]

Gets a list with all 1st level section names.

Returns

a list of section names stored in this ConfigMap.

static merge_configs(*configs: pip_services3_commons.config.ConfigParams.ConfigParams)pip_services3_commons.config.ConfigParams.ConfigParams

Merges two or more ConfigParams into one. The following ConfigParams override previously defined parameters.

Parameters

configs – a list of ConfigParams objects to be merged.

Returns

a new ConfigParams object.

override(config_params: pip_services3_commons.config.ConfigParams.ConfigParams)pip_services3_commons.config.ConfigParams.ConfigParams

Overrides parameters with new values from specified ConfigParams and returns a new ConfigParams object.

Parameters

config_params – ConfigMap with parameters to override the current values.

Returns

a new ConfigParams object.

set_defaults(default_config_params: pip_services3_commons.config.ConfigParams.ConfigParams)pip_services3_commons.config.ConfigParams.ConfigParams

Set default values from specified ConfigParams and returns a new ConfigParams object.

Parameters

default_config_params – ConfigMap with default parameter values.

Returns

a new ConfigParams object.