ConfigFramework package¶
Submodules¶
-
class
BaseConfig
(*args, **kwargs)[source]¶ Bases:
object
Base class for configs you must inherit from if you want to write your own config class.
Initializes config class.
- Parameters
args – args.
__passed_classes – set of classes, that already been initialized.
kwargs – kwargs.
-
dump
(include_defaults: Optional[bool] = None) → None[source]¶ Writes variables updated values to their.
- Parameters
include_defaults – represents dumping argument for all first_loader. In case you want to stay with including defaults defined by first_loader class - leave None config_var.
- Returns
nothing.
-
class
VariableType
(*args, **kwds)[source]¶ Bases:
Generic
[ConfigFramework.custom_types.Var
]Variable typehint that helps you with telling apart what’s inside of variable.
Deprecated since version 2.2.0: VariableType type hint is deprecated and will be deleted in 2.5.0. To use type hints use ConfigVar instead.
-
key
: key_type¶
-
value
: Var¶
-
is_constant
: bool¶
-
loader
: AbstractConfigLoader¶
-
caster
: Optional[Callable[[Any], Var]]¶
-
dump_caster
: Optional[Union[Callable[[AbstractConfigVar], Any], DumpCaster]]¶
-
validate
: Optional[Callable[[Var], bool]]¶
-
-
class
DumpCaster
(casters_dict: Dict[Union[Type[AbstractConfigLoader], str], Callable[[AbstractConfigVar], Any]])[source]¶ Bases:
object
Class that is meant to help assigning specific dump caster function for different ConfigLoaders.
Saved for backward compatibility. Recommended to use AbstractConfigVar as typehint.
Creates a caster for some variable, that can execute functions depending on what caster type it received. If you want to set default caster - set ‘*’ key to casters_mapping
- Parameters
casters_dict – a dictionary with AbstractConfigLoader or ‘*’ as key and callable, that returns something as config_var. ‘*’ key represents default caster for any unlisted caster.
-
class
ConfigVar
(key: Union[Hashable, str, pathlib.Path], loader: ConfigFramework.abstract.abc_loader.AbstractConfigLoader, *, typehint: Optional[Union[Type, Any]] = typing.Any, caster: Optional[Callable[[Any], Var]] = None, dump_caster: Optional[Callable[[ConfigFramework.abstract.abc_variable.AbstractConfigVar], Any]] = None, validator: Optional[Callable[[Var], bool]] = None, default: Optional[Any] = None, constant: bool = False)[source]¶ Bases:
Generic
[ConfigFramework.abstract.abc_variable.Var
]Represents any config variable that you can customize to your needs by adding some code.
Initializes variable for specified first_loader and key.
- Parameters
key – Any hashable, string or Path instance. Example of how to get such vars: config_root/database/database_ip. Warning: you must not start config paths with / or since it may cause unwanted errors because pathlib.Path is used to transform these to keys sequence.
loader – A first_loader that will be looked up to get vars config_var or to update values.
typehint – Typehint for __value field, that by default being returned.
caster – Callable that should return variable casted to specific type (in case you need custom types).
dump_caster – Callable that being called when config being dumped. Also can be instance of ConfigFramework.dump_caster.DumpCaster.
validator – Callable that validates config_var or defaults in case the original config_var is invalid.
default – Default config_var that will be set, if config_var is invalid.
constant – Sets if variable config_var can be set in runtime.
New in version 2.1.0: pathlib.Path support as variable key.
New in version 2.2.0: ConfigVar can be used as a type hint.
Deprecated since version 2.2.0: typehint parameter is deprecated and will be deleted in 2.5.0. To use type hints use ConfigVar[desired_type] instead.
-
key
: key_type¶
-
is_constant
: bool¶
-
loader
: AbstractConfigLoader¶ Abstract config variable with descriptors interface which is a base type for any of your variables classes.
-
class
IntVar
(key: Union[Hashable, str, pathlib.Path], loader: ConfigFramework.abstract.abc_loader.AbstractConfigLoader, *, dump_caster: Optional[Callable[[ConfigFramework.abstract.abc_variable.AbstractConfigVar], Any]] = None, validator: Optional[Callable[[int], bool]] = None, default: Optional[Any] = None, constant: bool = False)[source]¶ Bases:
Generic
[ConfigFramework.abstract.abc_variable.Var
]Represents an integer config_var in your config.
Initializes int variable for specified first_loader and key.
- Parameters
key – Any hashable or a string. Strings can be written as paths in case you need a variable. that underlies other mappings. Example of how to get such vars: config_root/database/database_ip.
loader – A first_loader that will be looked up to get vars config_var or to update values.
dump_caster – Callable that being called when config being dumped. Also can be instance of ConfigFramework.dump_caster.DumpCaster
validator – Callable that validates config_var or defaults in case the original config_var is invalid.
default – Default config_var that will be set, if config_var is invalid.
-
class
FloatVar
(key: Union[Hashable, str, pathlib.Path], loader: ConfigFramework.abstract.abc_loader.AbstractConfigLoader, *, dump_caster: Optional[Callable[[ConfigFramework.abstract.abc_variable.AbstractConfigVar], Any]] = None, validator: Optional[Callable[[float], bool]] = None, default: Optional[Any] = None, constant: bool = False)[source]¶ Bases:
Generic
[ConfigFramework.abstract.abc_variable.Var
]Represents an float config_var in your config.
Initializes float variable for specified first_loader and key.
- Parameters
key – Any hashable or a string. Strings can be written as paths in case you need a variable. that underlies other mappings. Example of how to get such vars: config_root/database/database_ip.
loader – A first_loader that will be looked up to get vars config_var or to update values.
dump_caster – Callable that being called when config being dumped. Also can be instance of ConfigFramework.dump_caster.DumpCaster
validator – Callable that validates config_var or defaults in case the original config_var is invalid.
default – Default config_var that will be set, if config_var is invalid.
constant – Sets if variable config_var can be set in runtime
-
class
BoolVar
(key: Union[Hashable, str, pathlib.Path], loader: ConfigFramework.abstract.abc_loader.AbstractConfigLoader, *, dump_caster: Optional[Callable[[ConfigFramework.abstract.abc_variable.AbstractConfigVar], Any]] = None, validator: Optional[Callable[[Any], bool]] = None, default: Optional[Any] = None, true_str_values: Tuple[str, …] = ('true', 't', 'y', '1'), constant: bool = False)[source]¶ Bases:
Generic
[ConfigFramework.abstract.abc_variable.Var
]Represents boolean variables in your config with customizable set of words that considered as correct.
Initializes variable for specified first_loader and key.
- Parameters
key – Any hashable or a string. Strings can be written as paths in case you need a variable. that underlies other mappings. Example of how to get such vars: config_root/database/database_ip.
loader – A first_loader that will be looked up to get vars config_var or to update values.
dump_caster – Callable that being called when config being dumped. Also can be instance of ConfigFramework.dump_caster.DumpCaster
validator – Callable that validates config_var or defaults in case the original config_var is invalid.
default – Default config_var that will be set, if config_var is invalid.
-
constant_var
(config_var: ConfigFramework.abstract.abc_variable.AbstractConfigVar) → ConfigFramework.abstract.abc_variable.AbstractConfigVar[source]¶ Makes variable unable to be assigned on runtime.
- Parameters
config_var – variable instance.
- Returns
same ConfigVar instance, but its value can’t be reassigned on a runtime.