• This repository has been archived on 03/Jun/2019
  • Stars
    star
    354
  • Rank 120,042 (Top 3 %)
  • Language
    Python
  • License
    MIT License
  • Created almost 9 years ago
  • Updated almost 7 years ago

Reviews

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

Repository Details

🚀 Fully fledged Flask boilerplate code

Flask boilerplate code

License

I didn't really like the Flask starter projects I found searching the web. I really like Flask and I use it for quite a few projects so I decided to make a clean, readable, documented starter project. I didn't include any makefile or fabric as I feel it imposes a choice to the user of this project, I rather keep things simple (even though the word is subject to interpretation).

Features

  • User account sign up, sign in, password reset, all through asynchronous email confirmation.
  • Form generation.
  • Error handling.
  • HTML macros and layout file.
  • "Functional" file structure.
  • Python 3.x compliant.
  • Asynchronous AJAX calls.
  • Application factory.
  • Administration panel.
  • Static file bundling, automatic SCSS to CSS conversion and automatic minifying.
  • Websockets (for example for live chatting)
  • Virtual environment example.
  • Digital Ocean deployment example.
  • Tests.
  • Logging.
  • Language selection.
  • Automatic API views.
  • API key generator.

If you have any suggestions or want to help, feel free to drop me a line at [email protected] or to create an issue.

Libraries

Backend

Frontend

Structure

I did what most people recommend for the application's structure. Basically, everything is contained in the app/ folder.

  • There you have the classic static/ and templates/ folders. The templates/ folder contains macros, error views and a common layout.
  • I added a views/ folder to separate the user and the website logic, which could be extended to the the admin views.
  • The same goes for the forms/ folder, as the project grows it will be useful to split the WTForms code into separate files.
  • The models.py script contains the SQLAlchemy code, for the while it only contains the logic for a users table.
  • The toolbox/ folder is a personal choice, in it I keep all the other code the application will need.
  • Management commands should be included in manage.py. Enter python manage.py -? to get a list of existing commands.
  • I added a Makefile for setup tasks, it can be quite useful once a project grows.

Setup

Vanilla

  • Install the requirements and setup the development environment.

    make install && make dev

  • Create the database.

    python manage.py initdb

  • Run the application.

    python manage.py runserver

  • Navigate to localhost:5000.

Virtual environment

pip install virtualenv virtualenv venv venv/bin/activate (venv\scripts\activate on Windows) make install make dev python manage.py initdb python manage.py runserver

Deployment

The current application can be deployed with Docker in a few commands.

cd ~/path/to/application/
docker-machine create -d virtualbox --virtualbox-memory 512 --virtualbox-cpu-count 1 dev
docker-machine env dev
eval "$(docker-machine env dev)"
docker-compose build
docker-compose up -d
docker-compose run web make dev
docker-compose run web python3 manage.py initdb

Then access the IP address given by docker-machine ip dev et voilà. This is exactly how OpenBikes's API is being deployed.

Configuration

The goal is to keep most of the application's configuration in a single file called config.py. I added a config_dev.py and a config_prod.py who inherit from config_common.py. The trick is to symlink either of these to config.py. This is done in by running make dev or make prod.

I have included a working Gmail account to confirm user email addresses and reset user passwords, although in production you should't include the file if you push to GitHub because people can see it. The same goes for API keys, you should keep them secret. You can read more about secret configuration files here.

Read this for information on the possible configuration options.

Examples

Inspiration

Other possibilities

License

The MIT License (MIT). Please see the license file for more information.

More Repositories

1

prince

👑 Multivariate exploratory data analysis in Python — PCA, CA, MCA, MFA, FAMD, GPA
Python
1,245
star
2

eaopt

🍀 Evolutionary optimization library for Go (genetic algorithm, partical swarm optimization, differential evolution)
Go
881
star
3

xam

🎯 Personal data science and machine learning toolbox
Python
362
star
4

chime

🎵 Python sound notifications made easy
Python
294
star
5

sorobn

🧮 Bayesian networks in Python
Python
234
star
6

kaggle-recruit-restaurant

🏆 Kaggle 8th place solution
Jupyter Notebook
106
star
7

procedural-art

🌌 Procedural art with vanilla JavaScript
HTML
96
star
8

pytorch-resample

🎲 Iterable dataset resampling in PyTorch
Python
89
star
9

xgp

🔮 Symbolic regression library
Go
61
star
10

flask-sse-no-deps

An example of server-sent events in Flask without extra dependencies
Python
59
star
11

clavier

🔤 Measure edit distance based on keyboard layout
Python
58
star
12

halfgone

🔳 Black and white digital halftoning
Go
47
star
13

taxi-demo-rp-mz-rv-rd-st

🚕 Self-contained demo using Redpanda, Materialize, River, Redis, and Streamlit to predict taxi trip durations
Python
44
star
14

pointu

✏️ Pointillisme tool based on Weighted Voronoi Stippling
Go
37
star
15

carre

👌 Image simplifier
Go
33
star
16

kaggle-vsb-power

⚡ 13th place solution
Jupyter Notebook
31
star
17

arcgonaut

🌀 Golang arc diagrams
Go
29
star
18

eaopt-examples

🍀 eaopt examples
Go
28
star
19

starboost

⭐🚀 Gradient boosting on steroids
Python
26
star
20

naked

The simplest way to deploy a machine learning model
Python
23
star
21

idao-2020-qualifier

Solution of team "Data O Plomo" to the qualification phase of the 2020 edition of the International Data Analysis Olympiad (IDAO)
Jupyter Notebook
18
star
22

genetic-curve-fitting

📈
Python
17
star
23

orc

🧌 Parsing structured information from OCR outputs
Jupyter Notebook
17
star
24

myriade

✨🌲 Hierarchical extreme multiclass and multi-label classification.
Python
16
star
25

bike-sharing-history

🚲 Git scraping for bike sharing APIs
Python
16
star
26

data-science-tutorials

Jupyter Notebook
15
star
27

maxhalford.github.io

🏡 Personal website
HTML
13
star
28

tuna

🐟 A streaming ETL for fish
Go
13
star
29

bbc-weather-honolulu

☀️ Measuring the accuracy of BBC weather forecasts in Honolulu, USA
Python
12
star
30

yamp

Yet Another MkDocs Parser
Python
11
star
31

tartine

🍞 Manipulate dynamic spreadsheets with arbitrary layouts using Python
Python
11
star
32

spotgeo-challenge

🛰️ My solution to the Kelvins spotGEO challenge
Python
10
star
33

openbikes

🚲 Collecting and publishing bike sharing data stored at https://github.com/MaxHalford/openbikes-data
Python
9
star
34

gago

Old version of eaopt, will eventually be removed
Go
9
star
35

project-euler-python

🐍
Python
9
star
36

ikea-store-locations

🇸🇪 Retrieval and analysis of IKEA store locations
Python
9
star
37

directory-architecture

📁 Mimicking the tree command
Python
8
star
38

xgp-python

XGP Python package with a scikit-learn interface
Python
8
star
39

idao-2020-final

Solution of team "Data O Plomo" to the final phase of the 2020 edition of the International Data Analysis Olympiad (IDAO)
Jupyter Notebook
7
star
40

svg2stl

🛹 Turn an SVG into an STL for stencil creation purposes
Python
6
star
41

inverted-index-search-engine

Python
5
star
42

streaming-cdf-benchmark

A benchmark to compare algorithms for estimating cumulative density functions (CDF) on streaming data
Python
5
star
43

vose

Cython implementation of Vose's Alias method
Cython
5
star
44

jan

💤 Just Another Neural network
Python
5
star
45

bitcoin-analysis-m1sid

💰 Master 1 project
Python
5
star
46

kaggle-march-madness-2019

🏀 Men and women solutions for the 2019 edition of the Kaggle March Madness competition
Jupyter Notebook
4
star
47

kaggle-DSG18-qualifier

Jupyter Notebook
3
star
48

kaggle-DSG17-qualifier

Python
3
star
49

kaggle-plasticc-astro-classification

Jupyter Notebook
3
star
50

andor-faq-llm

🎲 Answering tabletop game questions using an LLM
Python
2
star
51

kaggle-answer-correctness

🤔 Solution to the Riiid! Answer Correctness Prediction competition on Kaggle
Python
2
star
52

postgres-job-docker

🐳 Docker setup for PostgreSQL + Join Order Benchmark (JOB)
Shell
2
star
53

dotfiles

🧘 Because it's the healthy thing to do
Shell
2
star
54

ziboinboin.com

🍂 Old Ziboinboin website
HTML
1
star
55

openbikes-data

🚲 Git storage for https://github.com/MaxHalford/openbikes
1
star
56

where-to-live

Jupyter Notebook
1
star
57

cochleas-L3SID

Python
1
star
58

chrome-infinite-scrolling-robot

JavaScript
1
star
59

kaggle-avito-demand

Python
1
star
60

tldks-2020

Jupyter Notebook
1
star