AppConfigurator
- class flask_container_scaffold.app_configurator.AppConfigurator(app, relative=True)[source]
Bases:
object
- __init__(app, relative=True)[source]
This class handles loading and parsing of custom configuration for your Flask app.
- Parameters:
app (obj) – An existing Flask application
relative (bool) – Whether filenames found in configuration are assumed to be relative to instance path rather than application root.
BaseScaffold
- class flask_container_scaffold.base_scaffold.BaseScaffold(app=None, name='flask_container_scaffold.base_scaffold', config=None, settings_required=False, instance_path=None, instance_relative_config=True)[source]
Bases:
object
- __init__(app=None, name='flask_container_scaffold.base_scaffold', config=None, settings_required=False, instance_path=None, instance_relative_config=True)[source]
This base class provides a way to dynamically configure a Flask application.
- Parameters:
app (obj) – An existing Flask application, if passed, otherwise we will create a new one
name (str) – The name of the application, defaults to __name__.
config (dict) – A dict of configuration details. This can include standard Flask configuration keys, like ‘TESTING’, or ‘CUSTOM_SETTINGS’ (which can be a string referencing a file with custom configuration, or a dictionary containing any values your application may need) to make them available to the application during runtime
settings_required (bool) – Whether your app requires certain settings be specified in a settings.cfg file
instance_path (str) – Passthrough parameter to flask. An alternative instance path for the application. By default the folder ‘instance’ next to the package or module is assumed to be the instance path.
instance_relative_config (bool) – Passthrough parameter to flask. If set to True relative filenames for loading the config are assumed to be relative to the instance path instead of the application root.
AppScaffold
- class flask_container_scaffold.app_scaffold.AppScaffold(app=None, name='flask_container_scaffold.app_scaffold', config=None, settings_required=False, instance_path=None, instance_relative_config=True)[source]
Bases:
BaseScaffold
- __init__(app=None, name='flask_container_scaffold.app_scaffold', config=None, settings_required=False, instance_path=None, instance_relative_config=True)[source]
This class provides compatibility with versions of scaffold that expect an instance with an ‘app’ attribute. All of the parameters are the same as BaseScaffold and are passed directly through unmodified.
CeleryScaffold
- class flask_container_scaffold.celery_scaffold.CeleryScaffold(flask_app=None, name='flask_container_scaffold.celery_scaffold', config=None, settings_required=False, instance_path=None, instance_relative_config=True)[source]
Bases:
BaseScaffold
- __init__(flask_app=None, name='flask_container_scaffold.celery_scaffold', config=None, settings_required=False, instance_path=None, instance_relative_config=True)[source]
This class provides both a flask ‘app’ and a celery ‘app’ that has been configured via flask. All of the parameters are the same as BaseScaffold. Any naming changes are noted below.
- Parameters:
flask_app (obj) – An existing Flask application, if passed, otherwise we will create a new one using BaseScaffold. This is the same as the app parameter in BaseScaffold.
FlaskRequestFormatter
- class flask_container_scaffold.logging.FlaskRequestFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)[source]
Bases:
Formatter
A Formatter logging class to add IP information to the log records.
Usage example:
from flask_container_scaffold.logging import FlaskRequestFormatter dictConfig({ 'version': 1, 'formatters': { 'default': { '()': FlaskRequestFormatter, 'format': '[%(asctime)s] %(remote_addr)s %(levelname)s: %(message)s', }, }, ... })
- format(record)[source]
Format the specified record as text.
The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.
Util Module
- flask_container_scaffold.util.load_cfg(conf_file)[source]
Load a cfg file
- Parameters:
conf_file (str) – A cfg/ini file to be parsed
- Returns:
A dictionary formed out of the cfg file data
- Raises:
configparser.MissingSectionHeaderError, FileNotFoundError
- flask_container_scaffold.util.load_yaml(filename='config.yml', logger=None)[source]
Convenience wrapper around toolchest.yaml::parse to allow you to parse a file by path+name
- Parameters:
filename (str) – A yaml file to be parsed
logger (Logger) – Optional logger for potential errors
- Returns:
A dictionary formed out of the yaml data
- flask_container_scaffold.util.parse_input(logger, obj, default_return=<class 'flask_container_scaffold.base.BaseApiView'>)[source]
Parses incoming request, returns a serializable object to return to the client in all cases. When there is a failure, the object contains error information.
- Parameters:
logger (Logger) – Instantiated logger object
obj (BaseModel) – An object type based on a pydantic BaseModel to attempt to parse.
default_return (BaseApiView) – An object type that will be returned if validation of obj fails. This object must descend from BaseApiView or implement an errors field of type dict.
- Returns:
Instantiated object of type obj on success, or default_return on failure to parse.