petri.settings module¶
Settings boilerplate, loosely based on flask’s.
-
class
petri.settings.BaseSettings(**values)[source]¶ Bases:
pydantic.env_settings.BaseSettings,abc.ABCBoilerplate for config loading and dotenv handling.
-
BASEPATH= None¶ Absolute path to the project directory
-
DATA= None¶ Absolute path to the package directory
-
INIT_DOT_PY= None¶ Location of the
package/__init__.py.
-
LOG_DEST= None¶ Define allowed destinations for logs
-
LOG_FORMAT= None¶ Define allowed formats for logs.
-
LOG_LEVEL= None¶ Defines the logging level of the Application
-
LOG_STORAGE= None¶ Where to store the log file.
-
PKG_PATH= None¶ Absolute path to the package directory
-
classmethod
from_envvar(pkg_name, init_dot_py, default_config=None)[source]¶ Instantiate settings class.
Parameters: pkg_name (
str) – Name of the package.Raises: KeyError– The received envvar can’t be found.ValueError– A wrong format was used for the envvar.
Return type: Returns: The instantiated class.
-
to_str(dict_kw=None, **dumps_kw)[source]¶ Formats the dictionary version as a string.
Parameters: - dict_kw ([dict], optional) – kwargs for BaseModel.dict. Defaults to {}}.
- dumps_kw – optional kwargs forwarded to pprint.pformat.
Returns: - The formatted string version of the class as a
dictionary.
Return type:
-
classmethod
validate_class(pkg_name, cls_name, config_obj)[source]¶ Make sure an object is a valid petri setting.
Parameters: - pkg_name (
str) – Name of the packege the settings belongs to. Used to define theenv_prefix. See https://pydantic-docs.helpmanual.io/usage/settings/. - cls_name (
str) – Name of the settings class. Used to dynamically create classes which fullfill petri requirements. - config_obj (
Union[Dict[str,Any],type,Type[BaseSettings]]) – Data container: the contents of the settings class.
Raises: NotImplementedError– [description]ValueError– Not supported datatype forconfig_obj.ValueError– Ifconfig_objdefinesConfig.env_prefix
Return type: Returns: - The validated class. It will
- Inherit form BaseSettings,
- Contain
Configwith a petri-definedenv_prefix.
- pkg_name (
-
classmethod
validate_data(v, values)[source]¶ Dynamically defined as
__init__.py’s folder’s sibling.
-
-
petri.settings.Conf= ~Conf¶ Generic variable that can be ‘BaseSettings’, or any subclass.