This is boilerplate/skeleton code for a flask application meant for a RESTful API (with http and json) using Python 3 (tested with 3.6)
- Decent general structure
- Prod/Dev configuration in the environment
- Clevercloud structure, deployment ready
- Rollbar integration
- Endpoint documented with flask-restplus
- CORS ready
- JSON logging on the stdout and logentries
- Test environment: unittest, nose, coverage
- Code quality: flake8, radon
- Convenient Makefile
- Replace mock library by unittest.mock directly
- Have the swagger UI on ghpages ?
This project requires python 3.
make install
make server
make outdated
make clean
DEBUG: boolean
True will enable debug mode, and display full stack trace and an interactive shell in the browserSECRET_KEY: String
Secret key of the application, make sure to change it every time you make a new projectLOGENTRIES_TOKEN: String
Token for logentries service, can be left empty when developing locallyAPP_NAME: String
Application's nameENVIRONMENT: String
Application's environment (staging or production)APP_TOKEN: String
Application's tokenROLLBAR_ACCESS_TOKEN: String
Rollbar's app access token
Endpoints are documented using flask-restplus. The final json document can be reached here
Simple unit tests run
make test-unit
- Linting is done using flake8.
- PEP-8 is followed and asserted using flake8 linter. There is a .flake8 file at the root of app, most IDEs/text editors can use it to determine the preferences.
- Code can be analyzed and metrics extracted through radon. For a more verbose output, you can un-comment the 'radon raw' command.
To lint type
make lint
To get metrics type
make analyze
We have 2 loggers: http-logger
and msg-logger
. Both are using JSON as the output format.
The http-logger
is only used in the after_request
callback, to output full HTTP requests and responses on STDOUT. You should not have to use it yourself.
The msg-logger
is used to send general messages either on STDOUT or logentries if configured (See Environment variables). You can use it the following way:
import logging
logger = logging.getLogger('msg-logger')
logger.info('user retried to login and failed', extra={'user_id': 745, 'retries': 3, 'locked': True})
MIT License