Configuration
To easily load and access your configuration options, you can use one of the provided objects. Loaded options are accessible via the dot notation of variables.
Note
Keys from the configuration files are normalized into variables names, e.g. lower-cased,
additional spaces are removed, special characters are replaced with “_” and accents are removed.
For example Č. org.
will transform into c_org
or DIČ DPH
into dic_dph
.
- class aiviro.modules.config.YAMLConfig(file_name: str | None, file_dir: str | Path | None = None, encoding: str = 'utf-8')
It loads YAML configuration file, and provides interface for easy access to the loaded data.
- Parameters:
file_name – Name of the yaml configuration file
file_dir – Folder of the configuration files. Primary is loaded from
SCENARIO_CONFIG_FOLDER_PATH
, if it is not set, thenfile_dir
is used.
# example of YAML configuration file # "data/configuration/config.yaml" email: username: aiviro.robot password: "*******" smtp: smtp.server.com imap: smtp.server.com rdp: ip_address: 192.168.0.15 username: aiviro password: "*******" domain: ""
- Example:
>>> import aiviro >>> from aiviro.modules.config import YAMLConfig >>> cfg = YAMLConfig("config.yaml", "data/configuration/") >>> r = aiviro.create_rdp_robot( ... cfg.rdp.ip_address, ... cfg.rdp.username, ... cfg.rdp.password, ... cfg.rdp.domain ... )
- merge(other: YAMLConfig) YAMLConfig
Merges this configuration with another configuration.
- Parameters:
other – Other configuration to merge with
- Returns:
New instance of YAMLConfig with merged data
- Example:
>>> from aiviro.modules.config import YAMLConfig >>> y1 = YAMLConfig("config1.yaml", "data/") >>> y2 = YAMLConfig("config2.yaml", "data/") >>> ym = y1.merge(y2) >>> # alternatively also OR operator can be used >>> ym_2 = y1 | y2
- class aiviro.modules.config.CSVConfig(file_name: str | None, file_dir: str | Path | None = None, encoding: str = 'utf-8', dialect: str = 'excel')
It loads CSV configuration file, and provides interface for easy access to the loaded data.
- Parameters:
file_name – Name of the yaml configuration file
file_dir – Folder of the configuration files. Primary is loaded from
SCENARIO_CONFIG_FOLDER_PATH
, if it is not set, thenfile_dir
is used.
Č. org.
Název
Řada
Měna
DIČ DPH
52
Supplier 1
601
CZK
CZ12345678
53
Supplier 2
603
CZK
CZ99998888
98
Supplier 3
555
EUR
DE12345678
- Example:
>>> from aiviro.modules.config import CSVConfig >>> cfg = CSVConfig("robot_config.csv", "data/configuration/") >>> # get "Č. org." of "Supplier 2" >>> org_number = cfg.nazev["Supplier 2"].c_org