Skip to content

kloppy.config

kloppy.config

reset_config

reset_config()
Source code in kloppy/config.py
def reset_config():
    for key, value in _default_config.items():
        set_config(key, value)  # type: ignore

get_config

get_config(key=None)
Source code in kloppy/config.py
def get_config(key: Optional[CONFIG_KEYS] = None):
    if key is None:
        return config
    elif key in config:
        return config[key]  # type: ignore
    else:
        raise KeyError(f"Non existing config '{key}'")

set_config

set_config(key, value)
Source code in kloppy/config.py
def set_config(key: CONFIG_KEYS, value: Optional[str]):
    if key in config:
        config[key] = value
    else:
        raise KeyError(f"Non existing config '{key}'")

config_context

config_context(*args)

Set some config items for within a certain context. Code borrowed partly from pandas.

Source code in kloppy/config.py
@contextmanager
def config_context(*args):
    """Set some config items for within a certain context. Code borrowed partly from
    pandas."""
    if len(args) % 2 != 0 or len(args) < 2:
        raise ValueError(
            "Need to invoke as config_context(key, value, [(key, value), ...])."
        )

    configs = list(zip(args[::2], args[1::2]))

    undo = {key: get_config(key) for key, _ in configs}
    try:
        for key, value in configs:
            set_config(key, value)

        yield

    finally:
        for key, value in undo.items():
            set_config(key, value)