This package encapsulate all of the common infrastructure required to implement a Flask based microservice with support for OpenAPI 3 and Connexion out-of-the-box.
The SDK is part of the PyBackendBoilerplate package and is used in the example micro-service boilerplate project under that package.
The package is tested on Python 3.8, but Python 3.7 should also work (minimum version though).
The following list describes part of the stack used in the SDK:
- Flask: Web Framework.
- Connexion: OpenAPI Framework.
- Gunicorn: Python WSGI HTTP Server.
- zope.event: Events framework.
The SDK also supports loading configurations from the following options:
- defaults
- .env
- .flaskenv
- gunicorn_conf.py
By default, it will first try to load the .env
and .flaskenv
files.
If N/A, it will use the defaults defined in the code (Notice: There aren't defaults for everything, just the minimum required to run on host and port per defined in the defaults).
To access these values, use class ConfigBase
and class Environment
, e.g:
# This will automatically try to load the environment configurations
# and return a built Environment object.
env: Environment = ConfigBase().active_env
When running with gunicorn, you can use defaults from the src/sdk/config/gunicorn_conf.py.
To override them, just create your own gunicorn_conf.py
file like this and use that when running gunicorn:
import sys
import os
sys.path.append(os.path.join(sys.path[0], 'src'))
from sdk.config.gunicorn_conf import *
# override default sdk values here
bind = '0.0.0.0:5555'
The SDK comes with built-in examples under src/examples which shows how to use the SDK to build the official examples of Flask and Connexion with the SDK's infrastructure.
The SDK is developed in VS Code and provides a .vscode directory with predefined settings to get your VS Code environment ready fast.
The coding style format is according to Google Python Style Guide.
The coding style is automatically formatted with yapf and configured for Google coding style by default. To see the full configurations, check the .style.yapf configuration file.
The documentation is also configured via the provided .vscode settings to Google coding style by default.
Thanks sections for projects which helped me develop this one: