• Stars
    star
    226
  • Rank 176,514 (Top 4 %)
  • Language
    CSS
  • License
    BSD 2-Clause "Sim...
  • Created about 6 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Flask starter app with celery, bootstrap, and docker environment

tedivm's flask starter app

Screenshot

This code base serves as starting point for writing your next Flask application.

This package is designed to allow developers to start working on their specific features immediately while also making it simple to deploy the project into production. It contains a number of configured extensions and libraries as well as unique features specifically built for this package. It also is completely dockerized, with both a docker-compose testenv and the ability to easily make images off of the application for pushing into production.

Rob's Awesome Template

If you like this project you may also like my latest template, Rob's Awesome Python Template. It is updated with modern best practices and a variety of optional services.

Code characteristics

  • Tested on Python 3.3, 3.4, 3.5, 3.6, and 3.7
  • Complete docker environment.
  • Images for both the web application and the celery worker.
  • Full user management system.
  • Server side session storage.
  • An API system with API tokens and route decorators.
  • Well organized directories with lots of comments.
  • Includes test framework (py.test and tox)
  • Includes database migration framework (alembic, using Flask-Migrate)
  • Sends error emails to admins for unhandled exceptions

Configured Extensions and Libraries

With thanks to the following Flask extensions and libraries:

  • Beaker for caching and session management.
  • Celery for running asynchronous tasks on worker nodes.
  • Click for the creation of command line tools.
  • Flask the microframework framework which holds this all together.
  • Flask-Login allows users to login and signout.
  • Flask-Migrate integrates Alembic into Flask to handle database versioning.
  • Flask-SQLAlchemy integrates SQLAlchemy into Flask for database modeling and access.
  • Flask-User adds user management and authorization features.
  • Flask-WTF integrates WTForms into Flask to handle form creation and validation.

In addition the front end uses the open source versions of:

Unique Features

  • Database or LDAP Authentication - Applications built with this project can use the standard database backed users or can switch to LDAP authentication with a few configuration settings.

  • API Authentication and Authorization - this project can allow people with the appropriate role to generate API Keys, which in turn can be used with the roles_accepted_api decorator to grant API access to specific routes.

  • Versatile Configuration System - this project can be configured with a combination of configuration files, AWS Secrets Manager configuration, and environmental variables. This allows base settings to be built into the deployment, secrets to be managed securely, and any configuration value to be overridden by environmental variables.

  • A makefile with a variety of options to make common tasks easier to accomplish.

  • A Celery based asynchronous task management system. This is extremely useful for long running tasks- they can be triggered in the web interface and then run on a worker node and take as long as they need to complete.

Setting up a development environment

First we recommend either cloning this repository with the "Use this template" button on Github.

We assume that you have make and docker.

# Clone the code repository into ~/dev/my_app
mkdir -p ~/dev
cd ~/dev
git clone https://github.com/tedivm/tedivms-flask my_app
cd my_app

# For the first run, and only the first run, we need to create the first round of SQLAlchemy models.
make init_db

# Create the 'my_app' virtual environment and start docker containers
make testenv

# Restart docker app container
docker-compose restart app

# Start a shell in the container running the application
docker-compose exec app /bin/bash

Configuration

Application configuration

To set default configuration values on the application level- such as the application name and author- edit ./app/settings.py. This should be done as a first step whenever using this application template.

Configuration File

A configuration file can be set with the environmental variable APPLICATION_SETTINGS.

AWS Secrets Manager

Configuration can be loaded from the AWS Secrets Manager by setting the environmental variables AWS_SECRETS_MANAGER_CONFIG and AWS_SECRETS_REGION.

Environmental Variables

Any environmental variables that have the same name as a configuration value in this application will automatically get loaded into the app's configuration.

Configuring LDAP

Any installation can run with LDAP as its backend with these settings.

USER_LDAP=true
LDAP_HOST=ldap://ldap
LDAP_BIND_DN=cn=admin,dc=example,dc=org
LDAP_BIND_PASSWORD=admin
LDAP_USERNAME_ATTRIBUTE=cn
LDAP_USER_BASE=ou=users,dc=example,dc=org
LDAP_GROUP_OBJECT_CLASS=posixGroup
LDAP_GROUP_ATTRIBUTE=cn
LDAP_GROUP_BASE=ou=groups,dc=example,dc=org
LDAP_GROUP_TO_ROLE_ADMIN=admin
LDAP_GROUP_TO_ROLE_DEV=dev
LDAP_GROUP_TO_ROLE_USER=user
LDAP_EMAIL_ATTRIBUTE=mail

Initializing the Database

# Initialize the database. This will create the `migrations` folder and is only needed once per project.
make init_db

# This creates a new migration. It should be run whenever you change your database models.
make upgrade_models

Running the app

# Start the Flask development web server
make testenv

Point your web browser to http://localhost/

You can make use of the following users:

Running the automated tests

# To run the test suite.
make run_tests

Acknowledgements

Flask-Dash was used as a starting point for this code repository. That project was based off of the Flask-User-starter-app.

Authors

  • Matt Hogan (flaskdash) -- matt AT twintechlabs DOT io
  • Ling Thio (flask-user) -- ling.thio AT gmail DOT com

More Repositories

1

robs_awesome_python_template

A Highly Configurable Python Template: Optionally use FastAPI, SQLAlchemy 2, Pydantic, Typer, Celery, and more depending on your application's needs!
Python
133
star
2

quasiqueue

Multiprocessing Queues Made Easy
Python
99
star
3

paracelsus

Visualize SQLAlchemy Databases using Mermaid or Dot Diagrams.
Python
92
star
4

ec2details

API providing AWS EC2 Instance Type Data
JavaScript
40
star
5

nebula

EC2 Self-Management Portal
Python
34
star
6

jsonsmash

a shell for browsing json files
JavaScript
26
star
7

secretcli

AWS Secrets Manager CLI
Python
21
star
8

Spawn1

JavaScript
18
star
9

fedimapper

An API for the Fediverse - The Software behind the Fediverse Almanac
Python
16
star
10

phpsessionmanager

Automatically exported from code.google.com/p/phpsessionmanager
PHP
13
star
11

ScreepsAutoSpawner

Automatic Respawner for Screeps
Python
13
star
12

action-ecr-publish

12
star
13

github3apps.py

Python
9
star
14

BadThingsDailyBot

Python
8
star
15

jekyll-theme-portfolio

A Portfolio Theme for Jekyll
HTML
8
star
16

gitstars

Python
7
star
17

puppet-hieratic

Create Puppet Resources and Classes Directly in Hiera
Puppet
7
star
18

terraform-general-cloudinit

A cloudinit wrapper module that enables quick machine configuration
HCL
7
star
19

robs_awesome_python_template_examples

Examples from Rob's Awesome Python Template
Makefile
7
star
20

terraform-aws-lambda

A terraform module for managing Lambda Functions
HCL
6
star
21

stash-docs

The documentation for the Stash Cache
Python
6
star
22

ScreepsDashboard

JavaScript
6
star
23

action-python-lockfile-update

A Github Action that uses pip-tools to update a project's lockfiles via a Pull Request.
Shell
5
star
24

puppet-psad

Configure and Control PSAD with Puppet
1C Enterprise
5
star
25

urlparser

Extract information from URLs inside shell scripts
Python
5
star
26

HeadedHome

An IOT Button for leaving the office.
Python
5
star
27

scp_crawler

SCP Wiki Crawler
Python
4
star
28

formations

Playing with Pathfinding
JavaScript
4
star
29

puppet-iscsi

Puppet
4
star
30

Spark

Ignite Your Next Project With Spark
PHP
4
star
31

game_of_life_populations

A Colorful Game of Life
JavaScript
4
star
32

puppet-rsnapshot

This module manages backups using rsnapshot.
Puppet
4
star
33

shinigami-as-a-service

Wraps the Shinigami Eyes extension's data around a simple HTTP Service
JavaScript
4
star
34

robs_wall_clock

CircuitPython RGB Matrix Clock
Python
4
star
35

dapperdata

An opinionated formatter for configuration files
Python
3
star
36

portfolio

SCSS
3
star
37

www.goodguywarren.com

HTML
3
star
38

slack_proxy

Python
3
star
39

osx_start

Shell
3
star
40

puppet-ghebackups

Github Enterprise Backups Controlled By Puppet
Puppet
2
star
41

puppet-inspircd

Puppet
2
star
42

terraformer

Terraformer is a Python wrapper around Terraform.
Python
2
star
43

syntaxhighlighter_yaml

This Wordpress Plugin adds support for the Yaml language to the SyntaxHighlighter Evolved plugin.
PHP
2
star
44

nginx_aws_proxy

AWS SSL Termination via NGINX
Shell
2
star
45

pear.tedivm.com

A pear server for my projects.
1
star
46

Certain

PHP
1
star
47

screeps_marketd

Python
1
star
48

CHOPper

PHP
1
star
49

lambda-ecs-redeploy

Python
1
star
50

chalice-config

1
star
51

schema_transpose

Python
1
star
52

terraform-aws-nat

Terraform module for creating NAT Gateways or Instances and attaching them to a VPC
HCL
1
star
53

nebula-cli

CLI for the Nebula Cloud Dashboard
Python
1
star
54

terraform-aws-dev-vpn

Terraform module for lauching a VPN and configuring the local client
HCL
1
star
55

tfc_version

Terraform Cloud CLI for Managing Workspace Terraform Versions
Python
1
star