Small framework built on top of Flask to provide basic functionality common to all of our internal projects.
Note
This is meant for internal use at Continuum Analytics and is released only in the hopes that others might find it useful.
Add the following to your environment.yml file you're using conda-env:
channels:
- continuumio
dependencies:
- continuum-flaskOtherwise, install it directly with conda like this:
conda install -c continuumio continuum-flaskReplace the flask.Flask module with continuum_flask.Flask. This assumes
you have a settings module along side your application that will be
imported. That can be overridden by providing an explicit settings kwarg
when instantiating Flask.
The normal directory structure looks like this:
application/
- __init__.py
- settings.py
Your application/__init__.py should look something like this:
from continuum_flask import Flask
def create_app():
return Flask(__name__)You can now run this in something like gunicorn from the command line with:
gunicorn application:create_appsettings- This is a string representing the module with your settings in it. If this is not provided, it assumes it is in the same module as the server that's been initialized.
blueprintsAn array of strings to import when and register. It assumes each of these modules has an attribute called
blueprintthat should be registered. This is registered inside the app context, so you have access to any objects that are added to the application viacurrent_app.If the values added to
blueprintsare a string, they are registered at the via a simpleregister_blueprint(some_module)call. However, you can specify bothargsandkwargsto register via this syntax:('some_blueprint', ('arg1', 'arg2'), {'kwarg1': 'foo', 'kwarg2': 'bar'}) ('some_other', ('arg1', 'arg2')) ('yet_another', {'kwarg1': 'foo', 'kwarg2': 'bar'})
The first value is the name of the module that is imported inside the app context, the second argument is an optional iterable list of args and the third value is an optional dictionary of kwargs. You can omit either the args or the kwargs.