Base Parser¶
- class django_docker_helpers.config.backends.base.BaseParser(scope=None, config=None, nested_delimiter='__', path_separator='.', env=None)[source]¶
Base class to inherit from in custom parsers.
All
__init__arguments MUST be optional if you needfrom_env()automatic parser initializer (it initializes parsers likeparser_class(**parser_options)).Since
ConfigLoadercan initialize parsers from environment variables it’s recommended to annotate argument types to provide a correct auto typecast.BaseParsercreates aloggerwith name__class__.__name__.BaseParserimplements generic copying of following arguments without any backend-specific logic inside.- Parameters
scope (
Optional[str]) – a global prefix to all underlying valuesconfig (
Optional[str]) – optional confignested_delimiter (
str) – optional delimiter for environment backendpath_separator (
str) – specifies which character separates nested variables, default is'.'env (
Optional[Dict[str,str]]) – a dict with environment variables, default isos.environ
- property client¶
Helper property to lazy initialize and cache client. Runs
get_client().- Returns
an instance of backend-specific client
- static coerce(val, coerce_type=None, coercer=None)[source]¶
Casts a type of
valtocoerce_typewithcoercer.If
coerce_typeis bool and nocoercerspecified it usescoerce_str_to_bool()by default.- Parameters
val (
Any) – a value of any typecoerce_type (
Optional[Type]) – any typecoercer (
Optional[Callable]) – provide a callback that takesvaland returns a value with desired type
- Return type
Any- Returns
type casted value
- get(variable_path, default=None, coerce_type=None, coercer=None, **kwargs)[source]¶
Inherited method should take all specified arguments.
- Parameters
variable_path (
str) – a delimiter-separated path to a nested valuedefault (
Optional[Any]) – default value if there’s no object by specified pathcoerce_type (
Optional[Type]) – cast a type of a value to a specified onecoercer (
Optional[Callable]) – perform a type casting with specified callbackkwargs – additional arguments inherited parser may need
- Returns
value or default