encommon.config package#

Subpackages#

Submodules#

encommon.config.config module#

Functions and routines associated with Enasis Network Common Library.

This file is part of Enasis Network software eco-system. Distribution is permitted, for more information consult the project license file.

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, model: Callable | None = None)[source]#

Bases: object

Contain 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 model:

Override default config validation model.

property basic: dict[str, Any]#

Return the configuration source loaded from the objects.

Returns:

Configuration source loaded from the objects.

property cargs: dict[str, Any]#

Return the value for the attribute from class instance.

Returns:

Value for the attribute from class instance.

property config: dict[str, Any]#

Return the configuration dumped from the Pydantic model.

Returns:

Configuration dumped from the Pydantic model.

property crypts: Crypts#

Initialize the encryption instance using the parameters.

Returns:

Instance of the encryption instance created.

property files: ConfigFiles#

Return the value for the attribute from class instance.

Returns:

Value for the attribute from class instance.

property jinja2: Jinja2#

Return the value for the attribute from class instance.

Returns:

Value for the attribute from class instance.

property logger: Logger#

Initialize the Python logging library using parameters.

Returns:

Instance of Python logging library created.

property merge: dict[str, Any]#

Return the configuration source loaded from the objects.

Returns:

Configuration source loaded from the objects.

property model: 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 paths: ConfigPaths#

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.

encommon.config.files module#

Functions and routines associated with Enasis Network Common Library.

This file is part of Enasis Network software eco-system. Distribution is permitted, for more information consult the project license file.

class encommon.config.files.ConfigFile(path: str | Path)[source]#

Bases: object

Contain the configuration content from filesystem path.

Parameters:

path – Complete or relative path to configuration.

config: dict[str, Any]#
path: Path#
class encommon.config.files.ConfigFiles(paths: PATHABLE, force: bool = False)[source]#

Bases: object

Enumerate 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]#
property merge: dict[str, Any]#

Return the configuration in dictionary format for files.

Returns:

Configuration in dictionary format for files.

paths: tuple[Path, ...]#

encommon.config.logger module#

Functions and routines associated with Enasis Network Common Library.

This file is part of Enasis Network software eco-system. Distribution is permitted, for more information consult the project license file.

class encommon.config.logger.FileFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)[source]#

Bases: Formatter

Supplement class for built-in logger exception formatter.

Note

Input parameters are not defined, check parent class.

formatException(ei: Any) str[source]#

Specifically overrides method for formatting exceptions.

Parameters:

ei – Exception information provided by the logger.

Returns:

String representation for the filesystem path.

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: object

Manage 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 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.

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.

log_i(**kwargs: Any) None[source]#

Prepare keyword arguments and log to configured output.

Parameters:

kwargs – Keyword arguments for populating message.

log_w(**kwargs: Any) None[source]#

Prepare keyword arguments and log to configured output.

Parameters:

kwargs – Keyword arguments for populating message.

property logger_file: Logger#

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 params: LoggerParams#

Return the Pydantic model containing the configuration.

Returns:

Pydantic model containing the configuration.

start() None[source]#

Initialize the Python logging library using parameters.

property started: bool#

Return the value for the attribute from class instance.

Returns:

Value for the attribute from class instance.

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.

stop() None[source]#

Deinitialize the Python logging library using parameters.

class encommon.config.logger.Message(level: Literal['critical', 'debug', 'error', 'info', 'warning'], time: PARSABLE | None = None, **kwargs: Any)[source]#

Bases: object

Format 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 fields: dict[str, str]#

Return the value for the attribute from class instance.

Returns:

Value for the attribute from class instance.

property file_output: str#

Format keyword arguments for writing to filesystem path.

Returns:

String representation for the filesystem path.

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 stdo_output: str#

Format keyword arguments for writing to standard output.

Returns:

String representation for the standard output.

property time: Time#

Return the value for the attribute from class instance.

Returns:

Value for the attribute from class instance.

encommon.config.params module#

Functions and routines associated with Enasis Network Common Library.

This file is part of Enasis Network software eco-system. Distribution is permitted, for more information consult the project license file.

pydantic model encommon.config.params.ConfigParams[source]#

Bases: BaseModel

Process and validate the core configuration parameters.

Show JSON schema
{
   "title": "ConfigParams",
   "description": "Process and validate the core configuration parameters.",
   "type": "object",
   "properties": {
      "paths": {
         "anyOf": [
            {
               "items": {
                  "type": "string"
               },
               "minItems": 1,
               "type": "array"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "description": "Location of configuration files",
         "title": "Paths"
      }
   },
   "additionalProperties": false
}

Config:
  • extra: str = forbid

Fields:
field paths: Annotated[list[str] | None, FieldInfo(annotation=NoneType, required=False, default=None, description='Location of configuration files', metadata=[MinLen(min_length=1)])] = None#

Location of configuration files

Constraints:
  • min_length = 1

pydantic model encommon.config.params.LoggerParams[source]#

Bases: BaseModel

Process and validate the core configuration parameters.

Show JSON schema
{
   "title": "LoggerParams",
   "description": "Process and validate the core configuration parameters.",
   "type": "object",
   "properties": {
      "stdo_level": {
         "anyOf": [
            {
               "enum": [
                  "critical",
                  "debug",
                  "error",
                  "info",
                  "warning"
               ],
               "minLength": 1,
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "description": "Minimum logging message level",
         "title": "Stdo Level"
      },
      "file_level": {
         "anyOf": [
            {
               "enum": [
                  "critical",
                  "debug",
                  "error",
                  "info",
                  "warning"
               ],
               "minLength": 1,
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "description": "Minimum logging message level",
         "title": "File Level"
      },
      "file_path": {
         "anyOf": [
            {
               "minLength": 1,
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "description": "Enable output to the log file",
         "title": "File Path"
      }
   },
   "additionalProperties": false
}

Config:
  • extra: str = forbid

Fields:
field file_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)])] = None#

Minimum logging message level

Constraints:
  • min_length = 1

field file_path: Annotated[str | None, FieldInfo(annotation=NoneType, required=False, default=None, description='Enable output to the log file', metadata=[MinLen(min_length=1)])] = None#

Enable output to the log file

Constraints:
  • min_length = 1

field 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)])] = None#

Minimum logging message level

Constraints:
  • min_length = 1

pydantic model encommon.config.params.Params[source]#

Bases: BaseModel

Process and validate the core configuration parameters.

Show JSON schema
{
   "title": "Params",
   "description": "Process and validate the core configuration parameters.",
   "type": "object",
   "properties": {
      "enconfig": {
         "anyOf": [
            {
               "$ref": "#/$defs/ConfigParams"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "description": "Parameters for Config instance"
      },
      "enlogger": {
         "anyOf": [
            {
               "$ref": "#/$defs/LoggerParams"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "description": "Parameters for Logger instance"
      },
      "encrypts": {
         "anyOf": [
            {
               "$ref": "#/$defs/CryptsParams"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "description": "Parameters for Crypts instance"
      }
   },
   "$defs": {
      "ConfigParams": {
         "additionalProperties": false,
         "description": "Process and validate the core configuration parameters.",
         "properties": {
            "paths": {
               "anyOf": [
                  {
                     "items": {
                        "type": "string"
                     },
                     "minItems": 1,
                     "type": "array"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Location of configuration files",
               "title": "Paths"
            }
         },
         "title": "ConfigParams",
         "type": "object"
      },
      "CryptParams": {
         "additionalProperties": false,
         "description": "Process and validate the core configuration parameters.",
         "properties": {
            "phrase": {
               "description": "Passphrase for the operations",
               "minLength": 1,
               "title": "Phrase",
               "type": "string"
            }
         },
         "required": [
            "phrase"
         ],
         "title": "CryptParams",
         "type": "object"
      },
      "CryptsParams": {
         "additionalProperties": false,
         "description": "Process and validate the core configuration parameters.",
         "properties": {
            "phrases": {
               "additionalProperties": {
                  "$ref": "#/$defs/CryptParams"
               },
               "description": "Passphrases for the operations",
               "minProperties": 0,
               "title": "Phrases",
               "type": "object"
            }
         },
         "required": [
            "phrases"
         ],
         "title": "CryptsParams",
         "type": "object"
      },
      "LoggerParams": {
         "additionalProperties": false,
         "description": "Process and validate the core configuration parameters.",
         "properties": {
            "stdo_level": {
               "anyOf": [
                  {
                     "enum": [
                        "critical",
                        "debug",
                        "error",
                        "info",
                        "warning"
                     ],
                     "minLength": 1,
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Minimum logging message level",
               "title": "Stdo Level"
            },
            "file_level": {
               "anyOf": [
                  {
                     "enum": [
                        "critical",
                        "debug",
                        "error",
                        "info",
                        "warning"
                     ],
                     "minLength": 1,
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Minimum logging message level",
               "title": "File Level"
            },
            "file_path": {
               "anyOf": [
                  {
                     "minLength": 1,
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Enable output to the log file",
               "title": "File Path"
            }
         },
         "title": "LoggerParams",
         "type": "object"
      }
   },
   "additionalProperties": false
}

Config:
  • extra: str = forbid

Fields:
field enconfig: Annotated[ConfigParams | None, FieldInfo(annotation=NoneType, required=False, default=None, description='Parameters for Config instance')] = None#

Parameters for Config instance

field encrypts: Annotated[CryptsParams | None, FieldInfo(annotation=NoneType, required=False, default=None, description='Parameters for Crypts instance')] = None#

Parameters for Crypts instance

field enlogger: Annotated[LoggerParams | None, FieldInfo(annotation=NoneType, required=False, default=None, description='Parameters for Logger instance')] = None#

Parameters for Logger instance

encommon.config.paths module#

Functions and routines associated with Enasis Network Common Library.

This file is part of Enasis Network software eco-system. Distribution is permitted, for more information consult the project license file.

class encommon.config.paths.ConfigPath(path: str | Path)[source]#

Bases: object

Contain the configuration content from filesystem path.

Parameters:

path – Complete or relative path to configuration.

config: dict[str, ConfigFile]#
path: Path#
class encommon.config.paths.ConfigPaths(paths: PATHABLE, force: bool = False)[source]#

Bases: object

Enumerate 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]#
property merge: dict[str, Any]#

Return the configuration in dictionary format for paths.

Returns:

Configuration in dictionary format for paths.

paths: tuple[Path, ...]#

encommon.config.utils module#

Functions and routines associated with Enasis Network Common Library.

This file is part of Enasis Network software eco-system. Distribution is permitted, for more information consult the project license file.

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, replace: REPLACE | None = None) 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.

  • replace – Optional values to replace in the path.

Returns:

New resolved filesystem path object instances.

Module contents#

Functions and routines associated with Enasis Network Common Library.

This file is part of Enasis Network software eco-system. Distribution is permitted, for more information consult the project license file.

class encommon.config.Config(files: PATHABLE | None = None, *, paths: PATHABLE | None = None, cargs: dict[str, Any] | None = None, sargs: dict[str, Any] | None = None, model: Callable | None = None)[source]#

Bases: object

Contain 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 model:

Override default config validation model.

property basic: dict[str, Any]#

Return the configuration source loaded from the objects.

Returns:

Configuration source loaded from the objects.

property cargs: dict[str, Any]#

Return the value for the attribute from class instance.

Returns:

Value for the attribute from class instance.

property config: dict[str, Any]#

Return the configuration dumped from the Pydantic model.

Returns:

Configuration dumped from the Pydantic model.

property crypts: Crypts#

Initialize the encryption instance using the parameters.

Returns:

Instance of the encryption instance created.

property files: ConfigFiles#

Return the value for the attribute from class instance.

Returns:

Value for the attribute from class instance.

property jinja2: Jinja2#

Return the value for the attribute from class instance.

Returns:

Value for the attribute from class instance.

property logger: Logger#

Initialize the Python logging library using parameters.

Returns:

Instance of Python logging library created.

property merge: dict[str, Any]#

Return the configuration source loaded from the objects.

Returns:

Configuration source loaded from the objects.

property model: 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 paths: ConfigPaths#

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.

class encommon.config.ConfigFile(path: str | Path)[source]#

Bases: object

Contain the configuration content from filesystem path.

Parameters:

path – Complete or relative path to configuration.

config: dict[str, Any]#
path: Path#
class encommon.config.ConfigFiles(paths: PATHABLE, force: bool = False)[source]#

Bases: object

Enumerate 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]#
property merge: dict[str, Any]#

Return the configuration in dictionary format for files.

Returns:

Configuration in dictionary format for files.

paths: tuple[Path, ...]#
pydantic model encommon.config.ConfigParams[source]#

Bases: BaseModel

Process and validate the core configuration parameters.

Show JSON schema
{
   "title": "ConfigParams",
   "description": "Process and validate the core configuration parameters.",
   "type": "object",
   "properties": {
      "paths": {
         "anyOf": [
            {
               "items": {
                  "type": "string"
               },
               "minItems": 1,
               "type": "array"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "description": "Location of configuration files",
         "title": "Paths"
      }
   },
   "additionalProperties": false
}

Config:
  • extra: str = forbid

Fields:
field paths: Annotated[list[str] | None, FieldInfo(annotation=NoneType, required=False, default=None, description='Location of configuration files', metadata=[MinLen(min_length=1)])] = None#

Location of configuration files

Constraints:
  • min_length = 1

class encommon.config.ConfigPath(path: str | Path)[source]#

Bases: object

Contain the configuration content from filesystem path.

Parameters:

path – Complete or relative path to configuration.

config: dict[str, ConfigFile]#
path: Path#
class encommon.config.ConfigPaths(paths: PATHABLE, force: bool = False)[source]#

Bases: object

Enumerate 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]#
property merge: dict[str, Any]#

Return the configuration in dictionary format for paths.

Returns:

Configuration in dictionary format for paths.

paths: tuple[Path, ...]#
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: object

Manage 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 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.

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.

log_i(**kwargs: Any) None[source]#

Prepare keyword arguments and log to configured output.

Parameters:

kwargs – Keyword arguments for populating message.

log_w(**kwargs: Any) None[source]#

Prepare keyword arguments and log to configured output.

Parameters:

kwargs – Keyword arguments for populating message.

property logger_file: Logger#

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 params: LoggerParams#

Return the Pydantic model containing the configuration.

Returns:

Pydantic model containing the configuration.

start() None[source]#

Initialize the Python logging library using parameters.

property started: bool#

Return the value for the attribute from class instance.

Returns:

Value for the attribute from class instance.

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.

stop() None[source]#

Deinitialize the Python logging library using parameters.

pydantic model encommon.config.LoggerParams[source]#

Bases: BaseModel

Process and validate the core configuration parameters.

Show JSON schema
{
   "title": "LoggerParams",
   "description": "Process and validate the core configuration parameters.",
   "type": "object",
   "properties": {
      "stdo_level": {
         "anyOf": [
            {
               "enum": [
                  "critical",
                  "debug",
                  "error",
                  "info",
                  "warning"
               ],
               "minLength": 1,
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "description": "Minimum logging message level",
         "title": "Stdo Level"
      },
      "file_level": {
         "anyOf": [
            {
               "enum": [
                  "critical",
                  "debug",
                  "error",
                  "info",
                  "warning"
               ],
               "minLength": 1,
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "description": "Minimum logging message level",
         "title": "File Level"
      },
      "file_path": {
         "anyOf": [
            {
               "minLength": 1,
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "description": "Enable output to the log file",
         "title": "File Path"
      }
   },
   "additionalProperties": false
}

Config:
  • extra: str = forbid

Fields:
field file_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)])] = None#

Minimum logging message level

Constraints:
  • min_length = 1

field file_path: Annotated[str | None, FieldInfo(annotation=NoneType, required=False, default=None, description='Enable output to the log file', metadata=[MinLen(min_length=1)])] = None#

Enable output to the log file

Constraints:
  • min_length = 1

field 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)])] = None#

Minimum logging message level

Constraints:
  • min_length = 1

class encommon.config.Message(level: Literal['critical', 'debug', 'error', 'info', 'warning'], time: PARSABLE | None = None, **kwargs: Any)[source]#

Bases: object

Format 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 fields: dict[str, str]#

Return the value for the attribute from class instance.

Returns:

Value for the attribute from class instance.

property file_output: str#

Format keyword arguments for writing to filesystem path.

Returns:

String representation for the filesystem path.

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 stdo_output: str#

Format keyword arguments for writing to standard output.

Returns:

String representation for the standard output.

property time: Time#

Return the value for the attribute from class instance.

Returns:

Value for the attribute from class instance.

pydantic model encommon.config.Params[source]#

Bases: BaseModel

Process and validate the core configuration parameters.

Show JSON schema
{
   "title": "Params",
   "description": "Process and validate the core configuration parameters.",
   "type": "object",
   "properties": {
      "enconfig": {
         "anyOf": [
            {
               "$ref": "#/$defs/ConfigParams"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "description": "Parameters for Config instance"
      },
      "enlogger": {
         "anyOf": [
            {
               "$ref": "#/$defs/LoggerParams"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "description": "Parameters for Logger instance"
      },
      "encrypts": {
         "anyOf": [
            {
               "$ref": "#/$defs/CryptsParams"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "description": "Parameters for Crypts instance"
      }
   },
   "$defs": {
      "ConfigParams": {
         "additionalProperties": false,
         "description": "Process and validate the core configuration parameters.",
         "properties": {
            "paths": {
               "anyOf": [
                  {
                     "items": {
                        "type": "string"
                     },
                     "minItems": 1,
                     "type": "array"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Location of configuration files",
               "title": "Paths"
            }
         },
         "title": "ConfigParams",
         "type": "object"
      },
      "CryptParams": {
         "additionalProperties": false,
         "description": "Process and validate the core configuration parameters.",
         "properties": {
            "phrase": {
               "description": "Passphrase for the operations",
               "minLength": 1,
               "title": "Phrase",
               "type": "string"
            }
         },
         "required": [
            "phrase"
         ],
         "title": "CryptParams",
         "type": "object"
      },
      "CryptsParams": {
         "additionalProperties": false,
         "description": "Process and validate the core configuration parameters.",
         "properties": {
            "phrases": {
               "additionalProperties": {
                  "$ref": "#/$defs/CryptParams"
               },
               "description": "Passphrases for the operations",
               "minProperties": 0,
               "title": "Phrases",
               "type": "object"
            }
         },
         "required": [
            "phrases"
         ],
         "title": "CryptsParams",
         "type": "object"
      },
      "LoggerParams": {
         "additionalProperties": false,
         "description": "Process and validate the core configuration parameters.",
         "properties": {
            "stdo_level": {
               "anyOf": [
                  {
                     "enum": [
                        "critical",
                        "debug",
                        "error",
                        "info",
                        "warning"
                     ],
                     "minLength": 1,
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Minimum logging message level",
               "title": "Stdo Level"
            },
            "file_level": {
               "anyOf": [
                  {
                     "enum": [
                        "critical",
                        "debug",
                        "error",
                        "info",
                        "warning"
                     ],
                     "minLength": 1,
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Minimum logging message level",
               "title": "File Level"
            },
            "file_path": {
               "anyOf": [
                  {
                     "minLength": 1,
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Enable output to the log file",
               "title": "File Path"
            }
         },
         "title": "LoggerParams",
         "type": "object"
      }
   },
   "additionalProperties": false
}

Config:
  • extra: str = forbid

Fields:
field enconfig: Annotated[ConfigParams | None, FieldInfo(annotation=NoneType, required=False, default=None, description='Parameters for Config instance')] = None#

Parameters for Config instance

field encrypts: Annotated[CryptsParams | None, FieldInfo(annotation=NoneType, required=False, default=None, description='Parameters for Crypts instance')] = None#

Parameters for Crypts instance

field enlogger: Annotated[LoggerParams | None, FieldInfo(annotation=NoneType, required=False, default=None, description='Parameters for Logger instance')] = None#

Parameters for Logger 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, replace: REPLACE | None = None) 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.

  • replace – Optional values to replace in the path.

Returns:

New resolved filesystem path object instances.