petri.settings module

Settings boilerplate, loosely based on flask’s.

class petri.settings.BaseSettings(**values)[source]

Bases: pydantic.env_settings.BaseSettings, abc.ABC

Boilerplate for config loading and dotenv handling.

BASEPATH = None

Absolute path to the project directory

class Config[source]

Bases: object

env_prefix = 'PETRI_'
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:

BaseSettings

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:

str

classmethod validate_basepath(v, values)[source]

Dynamically defined as __init__.py’s folder.

classmethod validate_class(pkg_name, cls_name, config_obj)[source]

Make sure an object is a valid petri setting.

Parameters:
Raises:
Return type:

Type[BaseSettings]

Returns:

The validated class. It will
  1. Inherit form BaseSettings,
  2. Contain Config with a petri-defined env_prefix.

classmethod validate_data(v, values)[source]

Dynamically defined as __init__.py’s folder’s sibling.

classmethod validate_log_storage(v, values)[source]

Dynamically defined in __init__.py’s folder’s sibling.

classmethod validate_pkg_path(v, values)[source]

Dynamically defined as __init__.py’s folder’s parent.

petri.settings.Conf = ~Conf

Generic variable that can be ‘BaseSettings’, or any subclass.

class petri.settings.DevelopmentLog[source]

Bases: object

Log [WARNING] (or more severe) as [COLORED TXT] to [CONSOLE].

LOG_DEST = 'CONSOLE'
LOG_FORMAT = 'COLOR'
LOG_LEVEL = 30
class petri.settings.ProductionLog[source]

Bases: object

Log [EVERYTHING] as [JSON] to [CONSOLE].

LOG_DEST = 'CONSOLE'
LOG_FORMAT = 'JSON'
LOG_LEVEL = 1