cornflakes package

Subpackages

Submodules

cornflakes.types module

class cornflakes.types.Config(*args, **kwargs)[Quellcode]

Bases: StandardConfigMethods, StandardConfigArgs, CornflakesDataclass, Protocol[_T]

Config Protocol Type.

Rückgabetyp:

ConfigInstance[_T]

class cornflakes.types.ConfigDecorator(FILES='__config_files__', SECTIONS='__config_sections__', USE_REGEX='__multi_config__', IS_LIST='__config_list__', DEFAULT_LOADER='__default_loader__', CUSTOM_LOADER='__custom_loader__', ALLOW_EMPTY='__allow_empty_config__', chain_configs='__chain_configs__', VALIDATE='__validate__', ALIAS_GENERATOR='__alias_generator__', NON_COMPARABLE_FIELDS='__cornflakes_non_comparable_fields__', SECTION_NAME_KEY='section_name')[Quellcode]

Bases: object

Config Decorator Constants.

Parameter:
  • FILES (str) –

  • SECTIONS (str) –

  • USE_REGEX (str) –

  • IS_LIST (str) –

  • DEFAULT_LOADER (str) –

  • CUSTOM_LOADER (str) –

  • ALLOW_EMPTY (str) –

  • chain_configs (str) –

  • VALIDATE (str) –

  • ALIAS_GENERATOR (str) –

  • NON_COMPARABLE_FIELDS (str) –

  • SECTION_NAME_KEY (str) –

ALIAS_GENERATOR: str = '__alias_generator__'
ALLOW_EMPTY: str = '__allow_empty_config__'
CUSTOM_LOADER: str = '__custom_loader__'
DEFAULT_LOADER: str = '__default_loader__'
FILES: str = '__config_files__'
IS_LIST: str = '__config_list__'
NON_COMPARABLE_FIELDS: str = '__cornflakes_non_comparable_fields__'
SECTIONS: str = '__config_sections__'
SECTION_NAME_KEY: str = 'section_name'
USE_REGEX: str = '__multi_config__'
VALIDATE: str = '__validate__'
chain_configs: str = '__chain_configs__'
class cornflakes.types.ConfigDecoratorArgs(FILES='files', SECTIONS='sections', USE_REGEX='use_regex', IS_LIST='is_list', DEFAULT_LOADER='default_loader', ALLOW_EMPTY='allow_empty')[Quellcode]

Bases: object

Config Arguments Arguments.

Parameter:
  • FILES (str) –

  • SECTIONS (str) –

  • USE_REGEX (str) –

  • IS_LIST (str) –

  • DEFAULT_LOADER (str) –

  • ALLOW_EMPTY (str) –

ALLOW_EMPTY: str = 'allow_empty'
DEFAULT_LOADER: str = 'default_loader'
FILES: str = 'files'
IS_LIST: str = 'is_list'
SECTIONS: str = 'sections'
USE_REGEX: str = 'use_regex'
class cornflakes.types.ConfigGroup(*args, **kwargs)[Quellcode]

Bases: StandardConfigGroupMethods, StandardConfigGroupArgs, CornflakesDataclass, Protocol[_T]

ConfigGroup Protocol Type.

Rückgabetyp:

ConfigGroupInstance[_T]

class cornflakes.types.ConfigGroupInstance(*args, **kwargs)[Quellcode]

Bases: StandardConfigGroupMethods, StandardConfigArgs, DataclassInstance, Protocol[_T]

ConfigGroup Protocol Type.

class cornflakes.types.ConfigInstance(*args, **kwargs)[Quellcode]

Bases: StandardConfigMethods, StandardConfigArgs, DataclassInstance, Protocol[_T]

Config Protocol Type.

class cornflakes.types.ConfigOption(ENABLED='__auto_option_enabled__', READ_CONFIG_METHOD='__auto_option_init__', ATTRIBUTES='__auto_option_attributes__', PASSED_DECORATE_KEYS='__auto_option_keys__', OPTION_GROUPS='__option_groups__', ADD_CONFIG_FILE_OPTION_PARAM_VAR='config_file', ADD_CONFIG_FILE_OPTION_PARAM='--config-file', ADD_CONFIG_FILE_OPTION_PARAM_SHORT='-cfg', SHOW_CONFIG_FILES_OPTION_PARAM_VAR='show_config_files', SHOW_CONFIG_FILES_OPTION_PARAM='--show-config-files', SHOW_CONFIG_FILES_OPTION_PARAM_SHORT='-scf')[Quellcode]

Bases: object

Config Option Constants.

Parameter:
  • ENABLED (str) –

  • READ_CONFIG_METHOD (str) –

  • ATTRIBUTES (str) –

  • PASSED_DECORATE_KEYS (str) –

  • OPTION_GROUPS (str) –

  • ADD_CONFIG_FILE_OPTION_PARAM_VAR (str) –

  • ADD_CONFIG_FILE_OPTION_PARAM (str) –

  • ADD_CONFIG_FILE_OPTION_PARAM_SHORT (str) –

  • SHOW_CONFIG_FILES_OPTION_PARAM_VAR (str) –

  • SHOW_CONFIG_FILES_OPTION_PARAM (str) –

  • SHOW_CONFIG_FILES_OPTION_PARAM_SHORT (str) –

ADD_CONFIG_FILE_OPTION_PARAM: str = '--config-file'
ADD_CONFIG_FILE_OPTION_PARAM_SHORT: str = '-cfg'
ADD_CONFIG_FILE_OPTION_PARAM_VAR: str = 'config_file'
ATTRIBUTES: str = '__auto_option_attributes__'
ENABLED: str = '__auto_option_enabled__'
OPTION_GROUPS: str = '__option_groups__'
PASSED_DECORATE_KEYS: str = '__auto_option_keys__'
READ_CONFIG_METHOD: str = '__auto_option_init__'
SHOW_CONFIG_FILES_OPTION_PARAM: str = '--show-config-files'
SHOW_CONFIG_FILES_OPTION_PARAM_SHORT: str = '-scf'
SHOW_CONFIG_FILES_OPTION_PARAM_VAR: str = 'show_config_files'
class cornflakes.types.Constants(DEFAULT_LOADER=Loader.INI, DEFAULT_CONFIG_FILE='config.ini', config_option=<class 'cornflakes.types.ConfigOption'>, config_decorator_args=<class 'cornflakes.types.ConfigDecoratorArgs'>, config_decorator=<class 'cornflakes.types.ConfigDecorator'>, dataclass_decorator=<class 'cornflakes.types.DataclassDecorator'>)[Quellcode]

Bases: object

Constants.

Parameter:
DEFAULT_CONFIG_FILE: str = 'config.ini'
DEFAULT_LOADER: Loader = 'from_ini'
config_decorator

alias of ConfigDecorator

config_decorator_args

alias of ConfigDecoratorArgs

config_option

alias of ConfigOption

dataclass_decorator

alias of DataclassDecorator

class cornflakes.types.CornflakesDataclass(*args, **kwargs)[Quellcode]

Bases: StandardCornflakesDataclass, Protocol[_T]

Dataclass instance protocol.

class cornflakes.types.CornflakesType[Quellcode]

Bases: object

class cornflakes.types.DataclassDecorator(FIELDS='__dataclass_fields__', DICT_FACTORY='__dict_factory__', TUPLE_FACTORY='__tuple_factory__', VALUE_FACTORY='__value_factory__', EVAL_ENV='__eval_env__', IGNORED_SLOTS='__ignored_slots__', IGNORE_NONE='__ignore_none__', VALIDATORS='__cornflakes_validators__', REQUIRED_KEYS='__cornflakes_required_keys__', INIT_EXCLUDE_KEYS='__cornflakes_init_exclude_keys__')[Quellcode]

Bases: object

Dataclass Decorator Constants.

Parameter:
  • FIELDS (str) –

  • DICT_FACTORY (str) –

  • TUPLE_FACTORY (str) –

  • VALUE_FACTORY (str) –

  • EVAL_ENV (str) –

  • IGNORED_SLOTS (str) –

  • IGNORE_NONE (str) –

  • VALIDATORS (str) –

  • REQUIRED_KEYS (str) –

  • INIT_EXCLUDE_KEYS (str) –

DICT_FACTORY: str = '__dict_factory__'
EVAL_ENV: str = '__eval_env__'
FIELDS: str = '__dataclass_fields__'
IGNORED_SLOTS: str = '__ignored_slots__'
IGNORE_NONE: str = '__ignore_none__'
INIT_EXCLUDE_KEYS: str = '__cornflakes_init_exclude_keys__'
REQUIRED_KEYS: str = '__cornflakes_required_keys__'
TUPLE_FACTORY: str = '__tuple_factory__'
VALIDATORS: str = '__cornflakes_validators__'
VALUE_FACTORY: str = '__value_factory__'
class cornflakes.types.DataclassInstance(*args, **kwargs)[Quellcode]

Bases: StandardCornflakesDataclass, Protocol[_T]

Rückgabetyp:

DataclassInstance[_T]

keys()[Quellcode]

Return an iterable of all the keys.

Rückgabetyp:

Iterable[str]

to_dict()[Quellcode]

Parse config to dict.

Method implemented in cornflakes.decorator.dataclass._dataclass.to_dict().

Rückgabetyp:

dict

to_ini(out_cfg=None)[Quellcode]

Parse config to ini file / bytes.

Method implemented in cornflakes.decorator.config.ini.to_ini().

Parameter:

out_cfg (str | None) –

Rückgabetyp:

bytearray | None

to_tuple()[Quellcode]

Parse config to tuple.

Method implemented in cornflakes.decorator.dataclass._dataclass.to_tuple().

Rückgabetyp:

tuple

to_yaml(out_cfg=None, *args, **kwargs)[Quellcode]

Parse config to yaml file / bytes.

Method implemented in cornflakes.decorator.config.yaml.to_yaml().

Parameter:

out_cfg (str | None) –

Rückgabetyp:

bytearray | None

class cornflakes.types.Enum(value)

Bases: object

Generic enumeration.

Derive from this class to define new enumerations.

name

The name of the Enum member.

value

The value of the Enum member.

class cornflakes.types.FuncatTypes(value)[Quellcode]

Bases: Enum

An enumeration.

AFTER = 'after'
BEFORE = 'before'
WRAP = 'wrap'
class cornflakes.types.Generic

Bases: object

Abstract base class for generic types.

A generic type is typically declared by inheriting from this class parameterized with one or more type variables. For example, a generic mapping type might be defined as:

class Mapping(Generic[KT, VT]):
    def __getitem__(self, key: KT) -> VT:
        ...
    # Etc.

This class can then be used as follows:

def lookup_name(mapping: Mapping[KT, VT], key: KT, default: VT) -> VT:
    try:
        return mapping[key]
    except KeyError:
        return default
class cornflakes.types.GenericType[Quellcode]

Bases: Generic[_T]

cornflakes.types.HIDDEN_DEFAULT_TYPE

alias of _HiddenDefault

cornflakes.types.INSPECT_EMPTY_TYPE

alias of _empty

class cornflakes.types.IndexInstance(*args, **kwargs)[Quellcode]

Bases: Protocol

Protocol for Index instances.

reset: Callable[[], None]
class cornflakes.types.Loader(value)[Quellcode]

Bases: Enum

Config Loader Enums.

CUSTOM = 'from_custom'
DICT = 'from_dict'
FILE = 'from_file'
INI = 'from_ini'
YAML = 'from_yaml'
class cornflakes.types.LoaderMethod(*args, **kwargs)[Quellcode]

Bases: Protocol

Config loader method protocol.

cornflakes.types.MISSING_TYPE

alias of _MISSING_TYPE

class cornflakes.types.MappingWrapper(*args, **kwargs)[Quellcode]

Bases: Protocol[_T]

Rückgabetyp:

MappingWrapper[_T]

keys()[Quellcode]
Rückgabetyp:

Iterable[str]

class cornflakes.types.Protocol

Bases: Generic

Base class for protocol classes.

Protocol classes are defined as:

class Proto(Protocol):
    def meth(self) -> int:
        ...

Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing), for example:

class C:
    def meth(self) -> int:
        return 0

def func(x: Proto) -> int:
    return x.meth()

func(C())  # Passes static type check

See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as:

class GenProto(Protocol[T]):
    def meth(self) -> T:
        ...
class cornflakes.types.StandardConfigArgs(*args, **kwargs)[Quellcode]

Bases: Protocol

class cornflakes.types.StandardConfigGroupArgs(*args, **kwargs)[Quellcode]

Bases: Protocol

class cornflakes.types.StandardConfigGroupMethods(*args, **kwargs)[Quellcode]

Bases: Protocol

from_file(files=None, sections=None, keys=None, defaults=None, eval_env=False, *args, **kwargs)[Quellcode]

Method to load a config from files.

Parameter:

eval_env (bool) –

Rückgabetyp:

Any

class cornflakes.types.StandardConfigMethods(*args, **kwargs)[Quellcode]

Bases: Protocol

classmethod from_dict(files=None, sections=None, keys=None, defaults=None, eval_env=False, *args, **kwargs)[Quellcode]

Method to load a config from dict files.

Parameter:

eval_env (bool) –

classmethod from_file(files=None, sections=None, keys=None, defaults=None, eval_env=False, *args, **kwargs)[Quellcode]

Method to load a config from files.

Parameter:

eval_env (bool) –

Rückgabetyp:

Any

classmethod from_ini(files=None, sections=None, keys=None, defaults=None, eval_env=False, *args, **kwargs)[Quellcode]

Method to load a config from ini files.

Parameter:

eval_env (bool) –

classmethod from_yaml(files=None, sections=None, keys=None, defaults=None, eval_env=False, *args, **kwargs)[Quellcode]

Method to load a config from yaml files.

Parameter:

eval_env (bool) –

class cornflakes.types.StandardCornflakesDataclass(*args, **kwargs)[Quellcode]

Bases: StandardDataclass, Protocol[_T]

classmethod check_kwargs(validate=False, **kwargs)[Quellcode]

Check dataclass kwargs.

Method implemented in cornflakes.decorator.dataclass._validate.check_dataclass_kwargs().

Rückgabetyp:

Dict[str, Any]

classmethod validate_kwargs(validate=False, **kwargs)[Quellcode]

Validate kwargs.

Method implemented in cornflakes.decorator.dataclass._validate.validate_dataclass_kwargs().

Rückgabetyp:

Dict[str, Any]

class cornflakes.types.StandardDataclass(*args, **kwargs)[Quellcode]

Bases: Protocol

class cornflakes.types.TypeVar(name, *constraints, bound=None, covariant=False, contravariant=False)

Bases: _Final, _Immutable, _TypeVarLike

Type variable.

Usage:

T = TypeVar('T')  # Can be anything
A = TypeVar('A', str, bytes)  # Must be str or bytes

Type variables exist primarily for the benefit of static type checkers. They serve as the parameters for generic types as well as for generic function definitions. See class Generic for more information on generic types. Generic functions work as follows:

def repeat(x: T, n: int) -> List[T]:

‚‘‘Return a list containing n references to x.‘‘‘ return [x]*n

def longest(x: A, y: A) -> A:

‚‘‘Return the longest of two strings.‘‘‘ return x if len(x) >= len(y) else y

The latter example’s signature is essentially the overloading of (str, str) -> str and (bytes, bytes) -> bytes. Also note that if the arguments are instances of some subclass of str, the return type is still plain str.

At runtime, isinstance(x, T) and issubclass(C, T) will raise TypeError.

Type variables defined with covariant=True or contravariant=True can be used to declare covariant or contravariant generic types. See PEP 484 for more details. By default generic types are invariant in all type variables.

Type variables can be introspected. e.g.:

T.__name__ == ‚T‘ T.__constraints__ == () T.__covariant__ == False T.__contravariant__ = False A.__constraints__ == (str, bytes)

Note that only type variables defined in global scope can be pickled.

cornflakes.types.WITHOUT_DEFAULT_TYPE

alias of _WithoutDefault

class cornflakes.types.Writer(value)[Quellcode]

Bases: Enum

Config Writer Enums.

CUSTOM = 'to_custom'
DICT = 'to_dict'
FILE = 'to_file'
INI = 'to_ini'
YAML = 'to_yaml'
cornflakes.types.dataclass(cls=None, /, *, init=True, repr=True, eq=True, order=False, unsafe_hash=False, frozen=False, match_args=True, kw_only=False, slots=False)

Returns the same class as was passed in, with dunder methods added based on the fields defined in the class.

Examines PEP 526 __annotations__ to determine fields.

If init is true, an __init__() method is added to the class. If repr is true, a __repr__() method is added. If order is true, rich comparison dunder methods are added. If unsafe_hash is true, a __hash__() method function is added. If frozen is true, fields may not be assigned to after instance creation. If match_args is true, the __match_args__ tuple is added. If kw_only is true, then by default all fields are keyword-only. If slots is true, an __slots__ attribute is added.

Module contents

Top Level Module.

ini_load([files, sections, keys, defaults, ...])

py::dict ini::ini_load(const std::map<std::string, std::vector<std::string>> &files, const std::map<std::string, std::vector<std::string>> &sections, const std::map<std::string, std::vector<std::string>> &keys, const std::map<std::string, std::vector<py::object>> &defaults, const bool &eval_env)

This is a simple (lightweight) C++ function to parse ini file into python

Parameter:
  • files -- vector of string with files to read

  • sections -- vector of string with included sections

  • keys -- vector of string with included keys

  • defaults -- vector of python objects for default values

Rückgabe:

environment(s) with configs

eval_type(value)

py::object string_operations::eval_type(std::string value)

This is a simple C++ function to cast strings into python objects with specific type

Parameter:

value -- string to cast

Rückgabe:

python object (none, boolean, int, time, date, datetime, datetime_ms, ip_address)

eval_datetime(value)

py::object string_operations::eval_datetime(const std::string &value)

This is a simple C++ function to cast strings into python datetime object

Bemerkung

This function returns the same value as string when no datetime type is detected

Parameter:

value -- string to cast

Rückgabe:

python object (time, date, datetime, datetime_ms)

eval_csv(value[, disallowed_header_chars])

std::map<std::string, py::object> string_operations::eval_csv(const std::string &input, const char *extra_disallowed_header_chars)

eval_json(arg0)

py::dict string_operations::generateAvroSchemaPy(const std::string &jsonChunk)

extract_between(data, start, end)

py::list string_operations::extract_between(const std::string &data, std::string start, char end)

This is a simple C++ function to extract values from data between two fixed values

Parameter:
  • data -- string / bytes to extract from

  • start -- string / bytes for start-pattern

  • end -- string / bytes for end-pattern

Rückgabe:

list with extracted values

apply_match(vec, start)

py::object string_operations::apply_match(const std::vector<std::string> &vec, std::string match)

This is a simple C++ function to match a vector with values

Parameter:
  • vec -- vector of values

  • match -- value to match

Rückgabe:

list of boolean

generate_config_group_module(source_module)

Module with function to generate automatically config group module.

yaml_load(files[, sections, keys, defaults, ...])

Yaml Wrapper for reading yaml files in a generic way.

attach_log([obj, log_level, default_level, ...])

Function decorator to attach Logger to functions.

setup_logging([default_path, default_level, ...])

Setup logging configuration.

patch_module(module)

Method to overwrite module with all submodules in a generic way.

cornflakes.apply_match(vec: list, start: str) object
py::object string_operations::apply_match(const std::vector<std::string> &vec, std::string match)

This is a simple C++ function to match a vector with values

Parameter:
  • vec – vector of values

  • match – value to match

Rückgabe:

list of boolean

cornflakes.attach_log(obj=None, log_level=None, default_level=None, default_path='logging.yaml', env_key='LOG_CFG')

Function decorator to attach Logger to functions.

Parameter:
  • obj – Logger function or class to attach the logging to.

  • log_level (int | None) – log-level for the current object logging.

  • default_path (str) – Default path to logging config file.

  • default_level (int | None) – Default log-level (Logging.INFO).

  • env_key (str) – Environment key to use for logging configuration.

Rückgabe:

Object with attached logging instance

cornflakes.eval_csv(value: str, disallowed_header_chars: str = '') object
std::map<std::string, py::object> string_operations::eval_csv(const std::string &input, const char *extra_disallowed_header_chars)
cornflakes.eval_datetime(value: str) object
py::object string_operations::eval_datetime(const std::string &value)

This is a simple C++ function to cast strings into python datetime object

Bemerkung

This function returns the same value as string when no datetime type is detected

Parameter:

value – string to cast

Rückgabe:

python object (time, date, datetime, datetime_ms)

cornflakes.eval_json(arg0: str) object
py::dict string_operations::generateAvroSchemaPy(const std::string &jsonChunk)
cornflakes.eval_type(value: str) object
py::object string_operations::eval_type(std::string value)

This is a simple C++ function to cast strings into python objects with specific type

Parameter:

value – string to cast

Rückgabe:

python object (none, boolean, int, time, date, datetime, datetime_ms, ip_address)

cornflakes.extract_between(data: bytes, start: str, end: str) object
py::list string_operations::extract_between(const std::string &data, std::string start, char end)

This is a simple C++ function to extract values from data between two fixed values

Parameter:
  • data – string / bytes to extract from

  • start – string / bytes for start-pattern

  • end – string / bytes for end-pattern

Rückgabe:

list with extracted values

cornflakes.generate_config_group_module(source_module, source_config=None, target_module_file=None, class_name=None, loader=Loader.FILE, module_description='Automatically generated Default Config.', class_description='Main config class of the module.', *args, **kwargs)

Module with function to generate automatically config group module.

Parameter:
  • source_module (module | str) –

  • source_config (Dict[str, str | List[str]] | List[str] | str | None) –

  • target_module_file (str | None) –

  • class_name (str | None) –

  • loader (Loader) –

  • module_description (str) –

  • class_description (str) –

cornflakes.ini_load(files: object = None, sections: object = None, keys: object = None, defaults: object = None, eval_env: bool = False) dict
py::dict ini::ini_load(const std::map<std::string, std::vector<std::string>> &files, const std::map<std::string, std::vector<std::string>> &sections, const std::map<std::string, std::vector<std::string>> &keys, const std::map<std::string, std::vector<py::object>> &defaults, const bool &eval_env)

This is a simple (lightweight) C++ function to parse ini file into python

Parameter:
  • files – vector of string with files to read

  • sections – vector of string with included sections

  • keys – vector of string with included keys

  • defaults – vector of python objects for default values

Rückgabe:

environment(s) with configs

cornflakes.patch_module(module)

Method to overwrite module with all submodules in a generic way.

  1. Overwrite names from submodules declared in __all__ to parent module.

  2. Overwrite doc_string and adds auto summary with objects defined in __all__.

Parameter:

module (str) –

cornflakes.setup_logging(default_path='logging.yaml', default_level=None, env_key='LOG_CFG', force=False, loggers=None, handlers=None, **kwargs)

Setup logging configuration.

Parameter:
  • force (bool) – Overwrite current log-level

  • default_path (str) – Default path to logging config file.

  • default_level (int | None) – Default log-level (Logging.INFO).

  • env_key (str) – Environment key to use for logging configuration.

  • loggers (List[str] | None) – List of loggers to set log-level for.

  • handlers (List[str] | None) – List of handlers to set log-level for.

  • kwargs – arguments to pass to rich_handler

cornflakes.yaml_load(files, sections=None, keys=None, defaults=None, eval_env=False, loader=None)

Yaml Wrapper for reading yaml files in a generic way.

Parameter:
  • files (str | List[str] | Dict[str, str | List[str]]) –

  • sections (str | List[str] | Dict[str | None, List[str] | str] | None) –

  • keys (Dict[str, str | List[str]] | List[str] | str | None) –

  • defaults (str | List[str] | Dict[str, Any] | None) –

  • eval_env (bool) –

  • loader (Type[UnsafeLoader] | Type[SafeLoader] | None) –