config_framework.types package
Subpackages
Submodules
- class BaseConfig(loader: AbstractLoader, frozen: bool = True)[source]
Bases:
object
Initializes config class.
- Parameters
loader – loader that will be used to set values to variables of config object.
frozen – prevents user from assigning any values directly to class instance. Object will be not modifiable after __post_init__ is called.
- Returns
nothing.
- frozen: bool
- exception InvalidValueError[source]
Bases:
ValueError
Raised to give traceback about variable validations with more details.
- exception ValueValidationError[source]
Bases:
InvalidValueError
Raised if received value that hasn’t passed users checks.
- class Variable(key: Union[VariableKey, str], default: Optional[Var] = None)[source]
Bases:
Generic
[Var
]- source: Optional[AbstractLoader]
- serialize() Any [source]
Casts variables value to specific loaders type, so it can be saved.
- Returns
anything.
- deserialize(from_value: Any) Var [source]
Performs additional type casting if loader doesn’t provides it out of the box and returns variable with needed type that will also be validated after being casted.
- Parameters
from_value – raw value from loader.
- Returns
validated and caster to python type value.
- Raises
config_framework.types.custom_exceptions.ValueValidationError – adds explanation on where is invalid value in your config and from which loader value is from. This contains also a traceback to your config_framework.types.custom_exceptions.InvalidValueError.
- validate_value(value: Var) bool [source]
Checks if certain value is correct via users code.
- Parameters
value – value of correct python type (after being cast from raw loader value) that will be validated.
- Returns
bool value representing if It’s correct or not.
- Raises
config_framework.types.custom_exceptions.ValueValidationError – adds explanation on where is invalid value in your config and from which loader value is from. This contains also a traceback to your config_framework.types.custom_exceptions.InvalidValueError.
- static custom_serializer(variable: Variable, value: Var) Any [source]
Casts variables value to specific loaders type so it can be saved. This method can be set to instance of Variable using decorator <variable_instance>.register_serializer.
- Parameters
variable – variable instance.
value – the value that will actually be translated into loaders savable type.
- Returns
anything.
- static custom_deserializer(variable: Variable, from_value: Any) Var [source]
Method for defining how your custom variables must be casted from loaders type to pythons one (if they don’t translate 1:1). Can be set using decorator <variable_instance>.register_deserializer.
- Parameters
variable – instance of Variable that is used to get information about where this value from and etc.
from_value – raw value from loader.
- Returns
validated and caster to python type value.
- Raises
config_framework.types.custom_exceptions.ValueValidationError – adds explanation on where is invalid value in your config and from which loader value is from. This contains also a traceback to your config_framework.types.custom_exceptions.InvalidValueError.
- static custom_validator(variable: Variable, value: Var) bool [source]
Method for defining how your variable must be validated. Can be set using decorator <variable_instance>.register_validator.
- Parameters
variable – instance of Variable that is used to get information about where this value from and etc.
value – value of correct python type (after being casted from raw loader value) that will be validated.
- Returns
bool value representing if its correct or not.
- Raises
config_framework.types.custom_exceptions.ValueValidationError – adds explanation on where is invalid value in your config and from which loader value is from. This contains also a traceback to your config_framework.types.custom_exceptions.InvalidValueError.
- register_validator(f: Callable[[Variable, Var], bool]) Callable[[Variable, Var], bool] [source]
Registers passed function as custom_validator to be used later and instantly validates current value.
- Parameters
f – some method that signature matches to CustomValidator.
- Returns
function itself.
- register_serializer(f: Callable[[Variable, Var], Any]) Callable[[Variable, Var], Any] [source]
Registers passed function as custom_serializer to be used later and instantly uses it to trigger possible errors.
- Parameters
f – some method that signature matches to CustomSerializer.
- Returns
function itself.
- register_deserializer(f: Callable[[Variable, Any], Var]) Callable[[Variable, Any], Var] [source]
Registers passed function as custom_deserializer to be used later and instantly uses it to trigger possible errors on value from.
- Parameters
f – some method that signature matches to CustomDeserializer.
- Returns
function itself.
- class VariableKey(root_key: str)[source]
Bases:
Iterable
Class that helps us organize how keys for config variables to look for inside of some complicated nested structures.
Initializes new variable key.
- Parameters
root_key – string key that will be used to fetch value for certain config variable.
- Raises
TypeError – if received not a str instance.
- root_key: str
- next_pieces: List[VariableKey]