encommon.config package#
Submodules#
encommon.config.config module#
- class encommon.config.config.Config(files: PATHABLE | None = None, *, paths: PATHABLE | None = None, cargs: dict[str, Any] | None = None, sargs: dict[str, Any] | None = None, valid: Callable | None = None)[source]#
Bases:
objectContain the configurations from the arguments and files.
Note
Configuration loaded from files is validated with the Pydantic model
encommon.config.Params.Example#
>>> config = Config() >>> config.config {'enconfig': None, 'encrypts': None, 'enlogger': None}
- param files:
Complete or relative path to config files.
- param paths:
Complete or relative path to config paths.
- param cargs:
Configuration arguments in dictionary form, which will override contents from the config files.
- param sargs:
Additional arguments on the command line.
- param valid:
Override default config validation model.
- property files: ConfigFiles#
Return the value for the attribute from class instance.
- Returns:
Value for the attribute from class instance.
- property paths: ConfigPaths#
Return the value for the attribute from class instance.
- Returns:
Value for the attribute from class instance.
- property cargs: dict[str, Any]#
Return the value for the attribute from class instance.
- Returns:
Value for the attribute from class instance.
- property sargs: dict[str, Any]#
Return the value for the attribute from class instance.
- Returns:
Value for the attribute from class instance.
- property basic: dict[str, Any]#
Return the configuration source loaded from the objects.
- Returns:
Configuration source loaded from the objects.
- property merge: dict[str, Any]#
Return the configuration source loaded from the objects.
- Returns:
Configuration source loaded from the objects.
- property valid: Callable#
Return the value for the attribute from class instance.
- Returns:
Value for the attribute from class instance.
- property params: Params#
Return the Pydantic model containing the configuration.
- Returns:
Pydantic model containing the configuration.
- property config: dict[str, Any]#
Return the configuration dumped from the Pydantic model.
- Returns:
Configuration dumped from the Pydantic model.
- property logger: Logger#
Initialize the Python logging library using parameters.
- Returns:
Instance of Python logging library created.
encommon.config.files module#
- class encommon.config.files.ConfigFile(path: str | Path)[source]#
Bases:
objectContain the configuration content from filesystem path.
- Parameters:
path – Complete or relative path to configuration.
- class encommon.config.files.ConfigFiles(paths: PATHABLE, force: bool = False)[source]#
Bases:
objectEnumerate files and store the contents on relative path.
Note
Class can be empty in order to play nice with parent.
- Parameters:
paths – Complete or relative path to config files.
force – Force the merge on earlier files by later.
- config: dict[str, ConfigFile]#
encommon.config.logger module#
- class encommon.config.logger.Message(level: Literal['critical', 'debug', 'error', 'info', 'warning'], time: PARSABLE | None = None, **kwargs: Any)[source]#
Bases:
objectFormat the provided keyword arguments for logging output.
Note
Log messages are expected to contain string or numeric.
Example#
>>> message = Message('info', '1970-01-01', foo='bar') >>> strip_ansi(message.stdo_output) 'level="info" time="1970-01-01T00:00:00Z" foo="bar"'
- param level:
Severity which log message is classified.
- param time:
What time the log message actually occurred.
- param kwargs:
Keyword arguments for populating message.
- property level: Literal['critical', 'debug', 'error', 'info', 'warning']#
Return the value for the attribute from class instance.
- Returns:
Value for the attribute from class instance.
- property time: Time#
Return the value for the attribute from class instance.
- Returns:
Value for the attribute from class instance.
- property fields: dict[str, str]#
Return the value for the attribute from class instance.
- Returns:
Value for the attribute from class instance.
- class encommon.config.logger.FileFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)[source]#
Bases:
FormatterSupplement class for built-in logger exception formatter.
Note
Input parameters are not defined, check parent class.
- class encommon.config.logger.Logger(params: LoggerParams | None = None, *, stdo_level: Literal['critical', 'debug', 'error', 'info', 'warning'] | None = None, file_level: Literal['critical', 'debug', 'error', 'info', 'warning'] | None = None, file_path: str | Path | None = None)[source]#
Bases:
objectManage the file and standard output with logging library.
Note
Uses keyword name for levels in Pyton logging library.
Numeric
Keyword
10
debug
20
info
30
warning
40
error
50
critical
Example#
>>> logger = Logger(stdo_level='info') >>> logger.start() >>> logger.log_i(message='testing')
- param stdo_level:
Minimum level for the message to pass.
- param file_level:
Minimum level for the message to pass.
- param file_path:
Enables writing to the filesystem path.
- param params:
Parameters used to instantiate the class.
- property params: LoggerParams#
Return the Pydantic model containing the configuration.
- Returns:
Pydantic model containing the configuration.
- property stdo_level: Literal['critical', 'debug', 'error', 'info', 'warning'] | None#
Return the value for the attribute from class instance.
- Returns:
Value for the attribute from class instance.
- property file_level: Literal['critical', 'debug', 'error', 'info', 'warning'] | None#
Return the value for the attribute from class instance.
- Returns:
Value for the attribute from class instance.
- property file_path: Path | None#
Return the value for the attribute from class instance.
- Returns:
Value for the attribute from class instance.
- property started: bool#
Return the value for the attribute from class instance.
- Returns:
Value for the attribute from class instance.
- property logger_stdo: Logger#
Return the value for the attribute from class instance.
- Returns:
Value for the attribute from class instance.
- property logger_file: Logger#
Return the value for the attribute from class instance.
- Returns:
Value for the attribute from class instance.
- log(level: Literal['critical', 'debug', 'error', 'info', 'warning'], *, exc_info: Exception | None = None, **kwargs: Any) None[source]#
Prepare keyword arguments and log to configured output.
- Parameters:
exc_info – Optional exception included with trace.
kwargs – Keyword arguments for populating message.
- log_c(**kwargs: Any) None[source]#
Prepare keyword arguments and log to configured output.
- Parameters:
kwargs – Keyword arguments for populating message.
- log_d(**kwargs: Any) None[source]#
Prepare keyword arguments and log to configured output.
- Parameters:
kwargs – Keyword arguments for populating message.
- log_e(**kwargs: Any) None[source]#
Prepare keyword arguments and log to configured output.
- Parameters:
kwargs – Keyword arguments for populating message.
encommon.config.params module#
- class encommon.config.params.ConfigParams[source]#
Bases:
BaseModelProcess and validate the core configuration parameters.
- class encommon.config.params.LoggerParams[source]#
Bases:
BaseModelProcess and validate the core configuration parameters.
Fields# Field
Type
Required
Default
Constraints
Literal[‘critical’, ‘debug’, ‘error’, ‘info’, ‘warning’] |NoneNo
Nonemin_length=1
No
Nonemin_length=1
Literal[‘critical’, ‘debug’, ‘error’, ‘info’, ‘warning’] |NoneNo
Nonemin_length=1
- stdo_level: Annotated[Literal['critical', 'debug', 'error', 'info', 'warning'] | None, FieldInfo(annotation=NoneType, required=False, default=None, description='Minimum logging message level', metadata=[MinLen(min_length=1)])]#
- class encommon.config.params.Params[source]#
Bases:
BaseModelProcess and validate the core configuration parameters.
Fields# Field
Type
Required
Default
No
NoneNo
NoneNo
None- enconfig: Annotated[ConfigParams | None, FieldInfo(annotation=NoneType, required=False, default=None, description='Parameters for Config instance')]#
- enlogger: Annotated[LoggerParams | None, FieldInfo(annotation=NoneType, required=False, default=None, description='Parameters for Logger instance')]#
- encrypts: Annotated[CryptsParams | None, FieldInfo(annotation=NoneType, required=False, default=None, description='Parameters for Crypts instance')]#
encommon.config.paths module#
- class encommon.config.paths.ConfigPath(path: str | Path)[source]#
Bases:
objectContain the configuration content from filesystem path.
- Parameters:
path – Complete or relative path to configuration.
- config: dict[str, ConfigFile]#
- class encommon.config.paths.ConfigPaths(paths: PATHABLE, force: bool = False)[source]#
Bases:
objectEnumerate paths and store the contents on relative path.
Note
Class can be empty in order to play nice with parent.
- Parameters:
paths – Complete or relative path to config paths.
force – Force the merge on earlier files by later.
- config: dict[str, ConfigPath]#
encommon.config.utils module#
- encommon.config.utils.config_load(path: str | Path) dict[str, Any][source]#
Load configuration using the directory or file provided.
- Parameters:
path – Complete or relative path to configuration.
- Returns:
New resolved filesystem path object instance.
- encommon.config.utils.config_path(path: str | Path) Path[source]#
Resolve the provided path replacing the magic keywords.
Note
This function simply wraps one from utils subpackage.
- Parameters:
path – Complete or relative path for processing.
- Returns:
New resolved filesystem path object instance.
- encommon.config.utils.config_paths(paths: PATHABLE) tuple[Path, ...][source]#
Resolve the provided paths replacing the magic keywords.
Note
This function simply wraps one from utils subpackage.
- Parameters:
paths – Complete or relative paths for processing.
- Returns:
New resolved filesystem path object instances.
Module contents#
- class encommon.config.Config(files: PATHABLE | None = None, *, paths: PATHABLE | None = None, cargs: dict[str, Any] | None = None, sargs: dict[str, Any] | None = None, valid: Callable | None = None)[source]#
Bases:
objectContain the configurations from the arguments and files.
Note
Configuration loaded from files is validated with the Pydantic model
encommon.config.Params.Example#
>>> config = Config() >>> config.config {'enconfig': None, 'encrypts': None, 'enlogger': None}
- param files:
Complete or relative path to config files.
- param paths:
Complete or relative path to config paths.
- param cargs:
Configuration arguments in dictionary form, which will override contents from the config files.
- param sargs:
Additional arguments on the command line.
- param valid:
Override default config validation model.
- property files: ConfigFiles#
Return the value for the attribute from class instance.
- Returns:
Value for the attribute from class instance.
- property paths: ConfigPaths#
Return the value for the attribute from class instance.
- Returns:
Value for the attribute from class instance.
- property cargs: dict[str, Any]#
Return the value for the attribute from class instance.
- Returns:
Value for the attribute from class instance.
- property sargs: dict[str, Any]#
Return the value for the attribute from class instance.
- Returns:
Value for the attribute from class instance.
- property basic: dict[str, Any]#
Return the configuration source loaded from the objects.
- Returns:
Configuration source loaded from the objects.
- property merge: dict[str, Any]#
Return the configuration source loaded from the objects.
- Returns:
Configuration source loaded from the objects.
- property valid: Callable#
Return the value for the attribute from class instance.
- Returns:
Value for the attribute from class instance.
- property params: Params#
Return the Pydantic model containing the configuration.
- Returns:
Pydantic model containing the configuration.
- property config: dict[str, Any]#
Return the configuration dumped from the Pydantic model.
- Returns:
Configuration dumped from the Pydantic model.
- property logger: Logger#
Initialize the Python logging library using parameters.
- Returns:
Instance of Python logging library created.
- class encommon.config.ConfigFile(path: str | Path)[source]#
Bases:
objectContain the configuration content from filesystem path.
- Parameters:
path – Complete or relative path to configuration.
- class encommon.config.ConfigFiles(paths: PATHABLE, force: bool = False)[source]#
Bases:
objectEnumerate files and store the contents on relative path.
Note
Class can be empty in order to play nice with parent.
- Parameters:
paths – Complete or relative path to config files.
force – Force the merge on earlier files by later.
- config: dict[str, ConfigFile]#
- class encommon.config.ConfigParams[source]#
Bases:
BaseModelProcess and validate the core configuration parameters.
- class encommon.config.ConfigPath(path: str | Path)[source]#
Bases:
objectContain the configuration content from filesystem path.
- Parameters:
path – Complete or relative path to configuration.
- config: dict[str, ConfigFile]#
- class encommon.config.ConfigPaths(paths: PATHABLE, force: bool = False)[source]#
Bases:
objectEnumerate paths and store the contents on relative path.
Note
Class can be empty in order to play nice with parent.
- Parameters:
paths – Complete or relative path to config paths.
force – Force the merge on earlier files by later.
- config: dict[str, ConfigPath]#
- class encommon.config.Logger(params: LoggerParams | None = None, *, stdo_level: Literal['critical', 'debug', 'error', 'info', 'warning'] | None = None, file_level: Literal['critical', 'debug', 'error', 'info', 'warning'] | None = None, file_path: str | Path | None = None)[source]#
Bases:
objectManage the file and standard output with logging library.
Note
Uses keyword name for levels in Pyton logging library.
Numeric
Keyword
10
debug
20
info
30
warning
40
error
50
critical
Example#
>>> logger = Logger(stdo_level='info') >>> logger.start() >>> logger.log_i(message='testing')
- param stdo_level:
Minimum level for the message to pass.
- param file_level:
Minimum level for the message to pass.
- param file_path:
Enables writing to the filesystem path.
- param params:
Parameters used to instantiate the class.
- property params: LoggerParams#
Return the Pydantic model containing the configuration.
- Returns:
Pydantic model containing the configuration.
- property stdo_level: Literal['critical', 'debug', 'error', 'info', 'warning'] | None#
Return the value for the attribute from class instance.
- Returns:
Value for the attribute from class instance.
- property file_level: Literal['critical', 'debug', 'error', 'info', 'warning'] | None#
Return the value for the attribute from class instance.
- Returns:
Value for the attribute from class instance.
- property file_path: Path | None#
Return the value for the attribute from class instance.
- Returns:
Value for the attribute from class instance.
- property started: bool#
Return the value for the attribute from class instance.
- Returns:
Value for the attribute from class instance.
- property logger_stdo: Logger#
Return the value for the attribute from class instance.
- Returns:
Value for the attribute from class instance.
- property logger_file: Logger#
Return the value for the attribute from class instance.
- Returns:
Value for the attribute from class instance.
- log(level: Literal['critical', 'debug', 'error', 'info', 'warning'], *, exc_info: Exception | None = None, **kwargs: Any) None[source]#
Prepare keyword arguments and log to configured output.
- Parameters:
exc_info – Optional exception included with trace.
kwargs – Keyword arguments for populating message.
- log_c(**kwargs: Any) None[source]#
Prepare keyword arguments and log to configured output.
- Parameters:
kwargs – Keyword arguments for populating message.
- log_d(**kwargs: Any) None[source]#
Prepare keyword arguments and log to configured output.
- Parameters:
kwargs – Keyword arguments for populating message.
- log_e(**kwargs: Any) None[source]#
Prepare keyword arguments and log to configured output.
- Parameters:
kwargs – Keyword arguments for populating message.
- class encommon.config.LoggerParams[source]#
Bases:
BaseModelProcess and validate the core configuration parameters.
Fields# Field
Type
Required
Default
Constraints
Literal[‘critical’, ‘debug’, ‘error’, ‘info’, ‘warning’] |NoneNo
Nonemin_length=1
No
Nonemin_length=1
Literal[‘critical’, ‘debug’, ‘error’, ‘info’, ‘warning’] |NoneNo
Nonemin_length=1
- stdo_level: Annotated[Literal['critical', 'debug', 'error', 'info', 'warning'] | None, FieldInfo(annotation=NoneType, required=False, default=None, description='Minimum logging message level', metadata=[MinLen(min_length=1)])]#
- class encommon.config.Message(level: Literal['critical', 'debug', 'error', 'info', 'warning'], time: PARSABLE | None = None, **kwargs: Any)[source]#
Bases:
objectFormat the provided keyword arguments for logging output.
Note
Log messages are expected to contain string or numeric.
Example#
>>> message = Message('info', '1970-01-01', foo='bar') >>> strip_ansi(message.stdo_output) 'level="info" time="1970-01-01T00:00:00Z" foo="bar"'
- param level:
Severity which log message is classified.
- param time:
What time the log message actually occurred.
- param kwargs:
Keyword arguments for populating message.
- property level: Literal['critical', 'debug', 'error', 'info', 'warning']#
Return the value for the attribute from class instance.
- Returns:
Value for the attribute from class instance.
- property time: Time#
Return the value for the attribute from class instance.
- Returns:
Value for the attribute from class instance.
- property fields: dict[str, str]#
Return the value for the attribute from class instance.
- Returns:
Value for the attribute from class instance.
- class encommon.config.Params[source]#
Bases:
BaseModelProcess and validate the core configuration parameters.
Fields# Field
Type
Required
Default
No
NoneNo
NoneNo
None- enconfig: Annotated[ConfigParams | None, FieldInfo(annotation=NoneType, required=False, default=None, description='Parameters for Config instance')]#
- enlogger: Annotated[LoggerParams | None, FieldInfo(annotation=NoneType, required=False, default=None, description='Parameters for Logger instance')]#
- encrypts: Annotated[CryptsParams | None, FieldInfo(annotation=NoneType, required=False, default=None, description='Parameters for Crypts instance')]#
- encommon.config.config_load(path: str | Path) dict[str, Any][source]#
Load configuration using the directory or file provided.
- Parameters:
path – Complete or relative path to configuration.
- Returns:
New resolved filesystem path object instance.
- encommon.config.config_path(path: str | Path) Path[source]#
Resolve the provided path replacing the magic keywords.
Note
This function simply wraps one from utils subpackage.
- Parameters:
path – Complete or relative path for processing.
- Returns:
New resolved filesystem path object instance.
- encommon.config.config_paths(paths: PATHABLE) tuple[Path, ...][source]#
Resolve the provided paths replacing the magic keywords.
Note
This function simply wraps one from utils subpackage.
- Parameters:
paths – Complete or relative paths for processing.
- Returns:
New resolved filesystem path object instances.