Read YAML file into classes.
Project description
YAML-heritage
This library enables easy loading of parameters from a YAML file into Python class structures.
Usage
This example.ipynb
can be found in the examples folder.
-
Create the expected structure with Python classes
from yaml_heritage import Heritage class Subclass(Heritage): subparam: str param1: int class Example(Heritage): param1: int param2: float param3: Subclass
-
Replicate the same structure in the YAML file
param1: 1.1 param2: 2.5 param3: subparam: abc param1: 2.3
-
Load the parameters from the YAML file into the classes
example = Example.load('example.yaml')
-
Then
example
would be :param1: 1, param2: 2.500e+00, param3: subparam: abc, param1: 2
Note that the values are converted to the expected type. For example, param1 is expected to be an integer, so 1.1 is converted to 1.
Yaml syntax
-
Float Floats should have the decimal point at the end. For example, '35e6' should be written as '35.e6'.
-
Link other file You can easily link other files as a parameter and they will be loaded.
etching_param: &etching_param 'const_params/etching_params.yaml'
-
Link to a value:
etching_param: &etching_param 'const_params/etching_params.yaml' ... somewhere: etching_param: *etching_param
-
Link by relative link You can link to a value by relative link, example:
$.param_a
$
sign denotes that it is a link..
denotes to move up one level to find the parameter.param_a
is the name of the parameter
param_a: 1 ... somewhere: param_b: $.param_a
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for yaml_heritage-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 992a0b4382c9ff223e265b5fc137ab8e38b99a80ba74e529350bd4359e6eab62 |
|
MD5 | 2a71d0b701d7a0104d651ed37fac1ade |
|
BLAKE2b-256 | 700ad303c4f2ecdb0b80d820e2c84b11caacb5dbce2963c3d2f1e402e015889d |