API¶
PyFiguration¶
The PyFiguration class is the class that is used for the conf object that is imported (from pyfiguration import conf). This class can be used to define what the configurations should look like, and to access the configurations once the’re set.
-
class
pyfiguration.pyfiguration.
PyFiguration
¶ Load and document configuration files the right way!
NOTE: All functions are implemented in snake case and have an alias in camel case (e.g. add_int_field() and addIntField())
-
addBooleanField
(field: str, default: Optional[Any] = None, required: bool = True, description: Optional[str] = None)¶ Add a boolean field to the definition of the configuration.
Parameters: - field – The field to add to the definition
- required – Whether this field is required or not
- default – The default value for this field if no value is specified in the configuration
Returns: A wrapped method to use this method as a decorator
Return type: wrapped
-
addFloatField
(field: str, allowedValues: Optional[List[float]] = None, minValue: Optional[float] = None, maxValue: Optional[float] = None, required: bool = True, default: Optional[Any] = None, description: Optional[str] = None)¶ Add a float field to the definition of the configuration.
Parameters: - field – The field to add to the definition
- allowedValues – The allowed values for this field in the configuration (optional)
- minValue – The minimum value for this field
- maxValue – The maximum value for this field
- required – Whether this field is required or not
- default – The default value for this field if no value is specified in the configuration
Returns: A wrapped method to use this method as a decorator
Return type: wrapped
-
addIntField
(field: str, allowedValues: Optional[List[int]] = None, minValue: Optional[int] = None, maxValue: Optional[int] = None, required: bool = True, default: Optional[Any] = None, description: Optional[str] = None)¶ Add a integer field to the definition of the configuration.
Parameters: - field – The field to add to the definition
- allowedValues – The allowed values for this field in the configuration (optional)
- minValue – The minimum value for this field
- maxValue – The maximum value for this field
- required – Whether this field is required or not
- default – The default value for this field if no value is specified in the configuration
Returns: A wrapped method to use this method as a decorator
Return type: wrapped
-
addListField
(field: str, default: Optional[Any] = None, required: bool = True, description: Optional[str] = None)¶ Add a list field to the definition of the configuration.
Parameters: - field – The field to add to the definition
- required – Whether this field is required or not
- default – The default value for this field if no value is specified in the configuration
Returns: A wrapped method to use this method as a decorator
Return type: wrapped
-
addStringField
(field: str, allowedValues: Optional[List[str]] = None, required: bool = True, default: Optional[Any] = None, description: Optional[str] = None)¶ Add a string field to the definition of the configuration.
Parameters: - field – The field to add to the definition
- allowedValues – The allowed values for this field in the configuration (optional)
- required – Whether this field is required or not
- default – The default value for this field if no value is specified in the configuration
Returns: A wrapped method to use this method as a decorator
Return type: wrapped
-
add_boolean_field
(field: str, default: Optional[Any] = None, required: bool = True, description: Optional[str] = None)¶ Add a boolean field to the definition of the configuration.
Parameters: - field – The field to add to the definition
- required – Whether this field is required or not
- default – The default value for this field if no value is specified in the configuration
Returns: A wrapped method to use this method as a decorator
Return type: wrapped
-
add_float_field
(field: str, allowedValues: Optional[List[float]] = None, minValue: Optional[float] = None, maxValue: Optional[float] = None, required: bool = True, default: Optional[Any] = None, description: Optional[str] = None)¶ Add a float field to the definition of the configuration.
Parameters: - field – The field to add to the definition
- allowedValues – The allowed values for this field in the configuration (optional)
- minValue – The minimum value for this field
- maxValue – The maximum value for this field
- required – Whether this field is required or not
- default – The default value for this field if no value is specified in the configuration
Returns: A wrapped method to use this method as a decorator
Return type: wrapped
-
add_int_field
(field: str, allowedValues: Optional[List[int]] = None, minValue: Optional[int] = None, maxValue: Optional[int] = None, required: bool = True, default: Optional[Any] = None, description: Optional[str] = None)¶ Add a integer field to the definition of the configuration.
Parameters: - field – The field to add to the definition
- allowedValues – The allowed values for this field in the configuration (optional)
- minValue – The minimum value for this field
- maxValue – The maximum value for this field
- required – Whether this field is required or not
- default – The default value for this field if no value is specified in the configuration
Returns: A wrapped method to use this method as a decorator
Return type: wrapped
-
add_list_field
(field: str, default: Optional[Any] = None, required: bool = True, description: Optional[str] = None)¶ Add a list field to the definition of the configuration.
Parameters: - field – The field to add to the definition
- required – Whether this field is required or not
- default – The default value for this field if no value is specified in the configuration
Returns: A wrapped method to use this method as a decorator
Return type: wrapped
-
add_string_field
(field: str, allowedValues: Optional[List[str]] = None, required: bool = True, default: Optional[Any] = None, description: Optional[str] = None)¶ Add a string field to the definition of the configuration.
Parameters: - field – The field to add to the definition
- allowedValues – The allowed values for this field in the configuration (optional)
- required – Whether this field is required or not
- default – The default value for this field if no value is specified in the configuration
Returns: A wrapped method to use this method as a decorator
Return type: wrapped
-
setConfiguration
(sources: Optional[List[str]] = None)¶ Method to set the configuration for this PyFiguration object. Configuration is loaded from a YAML or JSON file.
-
set_configuration
(sources: Optional[List[str]] = None)¶ Method to set the configuration for this PyFiguration object. Configuration is loaded from a YAML or JSON file.
-
Utils¶
Utility methods that are used by PyFiguration.
-
pyfiguration.utils.
fromDotNotation
(field: str, obj: Dict[Any, Any]) → Any¶ Method to retrieve a value from the configuration using dot-notation. Dot-notation means nested fields can be accessed by concatenating all the parents and the key with a “.” (e.g. db.driver.name).
Parameters: - field – The field (in dot-notation) to access
- obj – The object to access using dot-notation
Returns: The value at the specified key, in the specified obj
Return type: value
-
pyfiguration.utils.
from_dot_notation
(field: str, obj: Dict[Any, Any]) → Any¶ Method to retrieve a value from the configuration using dot-notation. Dot-notation means nested fields can be accessed by concatenating all the parents and the key with a “.” (e.g. db.driver.name).
Parameters: - field – The field (in dot-notation) to access
- obj – The object to access using dot-notation
Returns: The value at the specified key, in the specified obj
Return type: value
-
pyfiguration.utils.
mergeDictionaries
(a: dict, b: dict, path: Optional[List[str]] = None) → dict¶ Merges dictionary b into a, prefering keys in b over keys in a.
Parameters: - a – The destination dictionary
- b – The source dictionary
- path – The full path in the destination dictionary (for recursion)
Returns: The merged dictionaries
Return type: merged
-
pyfiguration.utils.
merge_dictionaries
(a: dict, b: dict, path: Optional[List[str]] = None) → dict¶ Merges dictionary b into a, prefering keys in b over keys in a.
Parameters: - a – The destination dictionary
- b – The source dictionary
- path – The full path in the destination dictionary (for recursion)
Returns: The merged dictionaries
Return type: merged