Skip to content

hnb2/flask-boilerplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

Current features:

  • 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

Some goals/wanted features:

Installation

This project requires python 3.

make install

Run

make server

Follow up on dependencies

make outdated

Clean the dependencies

make clean

Environment variables

  • DEBUG: boolean True will enable debug mode, and display full stack trace and an interactive shell in the browser
  • SECRET_KEY: String Secret key of the application, make sure to change it every time you make a new project
  • LOGENTRIES_TOKEN: String Token for logentries service, can be left empty when developing locally
  • APP_NAME: String Application's name
  • ENVIRONMENT: String Application's environment (staging or production)
  • APP_TOKEN: String Application's token
  • ROLLBAR_ACCESS_TOKEN: String Rollbar's app access token

Documentation

Endpoints are documented using flask-restplus. The final json document can be reached here

Tests

Nose documentation

Simple unit tests run

make test-unit

Code style, quality and Linting

  • 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

Logging

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})

License

MIT License

About

No description or website provided.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published