cfg4py package

Submodules

cfg4py.command_line module

class cfg4py.command_line.Command[source]

Bases: object

build(config_dir: str)[source]

Compile configuration files into a python class file, which is used by IDE’s auto-complete function

Args:

config_dir: The folder where your configuration files located

Returns:

hint(what: str = None, usage: bool = False)[source]

show a cheat sheet for configurations. for example:

cfg4py hint mysql

this will print how to configure PyMySQL :param what :param usage

scaffold(dst: Optional[str])[source]

Creates initial configuration files based on our choices. Args:

dst:

Returns:

set_server_role()[source]
cfg4py.command_line.main()[source]

cfg4py.config module

class cfg4py.config.Config[source]

Bases: object

cfg4py.core module

Main module.

class cfg4py.core.LocalConfigChangeHandler[source]

Bases: watchdog.events.FileSystemEventHandler

dispatch(event)[source]

Dispatches events to the appropriate methods.

Parameters

event (FileSystemEvent) – The event object representing the file system event.

class cfg4py.core.RedisConfigFetcher(key: str, host: str = 'localhost', port: int = 6379, db: int = 0, **kwargs)[source]

Bases: cfg4py.core.RemoteConfigFetcher

fetch() → dict[source]
class cfg4py.core.RemoteConfigFetcher[source]

Bases: object

fetch() → str[source]
cfg4py.core.build(save_to: str)[source]
cfg4py.core.config_remote_fetcher(fetcher: cfg4py.core.RemoteConfigFetcher, interval: int = 300)[source]
config a remote configuration fetcher, which will pull the settings on every

refresh_interval

Args:

fetcher: sub class of RemoteConfigFetcher interval: how long should cfg4py to pull the configuration from remote

Returns:

cfg4py.core.config_server_role(role: str)[source]
cfg4py.core.enable_logging(level=20, log_file=None, file_size=10, file_count=7)[source]

Enable basic log function for the application

if log_file is None, then it’ll provide console logging, otherwise, the console logging is turned off, all events will be logged into the provided file.

Args:

level: the log level, one of logging.DEBUG, logging.INFO, logging.WARNING, logging.Error log_file: the absolute file path for the log. file_size: file size in MB unit file_count: how many backup files leaved in disk

Returns:

None

cfg4py.core.get_config_dir()[source]
cfg4py.core.init(local_cfg_path: str = None, dump_on_change=True, strict=False)[source]

create cfg object. Args:

local_cfg_path: the directory name where your configuration files exist dump_on_change: if configuration is updated, whether or not to dump them into

log file

Returns:

cfg4py.core.update_config(conf: dict)[source]
cfg4py.core.yaml_dump(conf, options=None)[source]

Module contents

Top-level package for Cfg4Py.

class cfg4py.RemoteConfigFetcher[source]

Bases: object

fetch() → str[source]
cfg4py.enable_logging(level=20, log_file=None, file_size=10, file_count=7)[source]

Enable basic log function for the application

if log_file is None, then it’ll provide console logging, otherwise, the console logging is turned off, all events will be logged into the provided file.

Args:

level: the log level, one of logging.DEBUG, logging.INFO, logging.WARNING, logging.Error log_file: the absolute file path for the log. file_size: file size in MB unit file_count: how many backup files leaved in disk

Returns:

None

cfg4py.config_remote_fetcher(fetcher: cfg4py.core.RemoteConfigFetcher, interval: int = 300)[source]
config a remote configuration fetcher, which will pull the settings on every

refresh_interval

Args:

fetcher: sub class of RemoteConfigFetcher interval: how long should cfg4py to pull the configuration from remote

Returns:

cfg4py.init(local_cfg_path: str = None, dump_on_change=True, strict=False)[source]

create cfg object. Args:

local_cfg_path: the directory name where your configuration files exist dump_on_change: if configuration is updated, whether or not to dump them into

log file

Returns:

cfg4py.update_config(conf: dict)[source]
class cfg4py.RedisConfigFetcher(key: str, host: str = 'localhost', port: int = 6379, db: int = 0, **kwargs)[source]

Bases: cfg4py.core.RemoteConfigFetcher

fetch() → dict[source]
cfg4py.config_server_role(role: str)[source]
cfg4py.get_instance()[source]
cfg4py.get_config_dir()[source]