• Stars
    star
    990
  • Rank 45,921 (Top 1.0 %)
  • Language
    Python
  • License
    MIT License
  • Created over 11 years ago
  • Updated over 1 year ago

Reviews

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

Repository Details

An example of a large scale Flask application using blueprints and extensions.

flasks

flask-bones

An example of a large scale Flask application using blueprints and extensions.

Build Status

Setup

Quickly run the project using docker and docker-compose:

docker-compose up -d

Create the database and seed it with some data:

docker-compose run --rm app flask create-db
docker-compose run --rm app flask populate-db --num_users 5

Download front-end dependencies with yarn:

yarn install --modules-folder ./app/static/node_modules

Configuration

The following environment variables are optional:

Name Purpose
APP_NAME The name of the application. i.e Flask Bones
MAIL_PORT The port number of an SMTP server.
MAIL_SERVER The hostname of an SMTP server.
MEMCACHED_HOST The hostname of a memcached server.
MEMCACHED_PORT The port number of a memcached server.
POSTGRES_HOST The hostname of a postgres database server.
POSTGRES_PASS The password of a postgres database user.
POSTGRES_PORT The port number of a postgres database server.
POSTGRES_USER The name of a postgres database user.
REDIS_HOST The hostname of a redis database server.
REDIS_PORT The port number of a redis database server.
SECRET_KEY A secret key required to provide authentication.
SERVER_NAME The hostname and port number of the server.

Features

Caching with Memcached

from app.extensions import cache

# Cache something
cache.set('some_key', 'some_value')

# Fetch it later
cache.get('some_key')

Email delivery

from app.extensions import mail
from flask_mail import Message

# Build an email
msg = Message('User Registration', sender='[email protected]', recipients=[user.email])
msg.body = render_template('mail/registration.mail', user=user, token=token)

# Send
mail.send(msg)

Asynchronous job scheduling with RQ

RQ is a simple job queue for python backed by redis.

Define a job:

@rq.job
def send_email(msg):
    mail.send(msg)

Start a worker:

flask rq worker

Queue the job for processing:

send_email.queue(msg)

Monitor the status of the queue:

flask rq info --interval 3

For help on all available commands:

flask rq --help

Stupid simple user management

from app.extensions import login_user, logout_user, login_required

# Login user
login_user(user)

# You now have a global proxy for the user
current_user.is_authenticated

# Secure endpoints with a decorator
@login_required

# Log out user
logout_user()

Password security that can keep up with Moores Law

from app.extensions import bcrypt

# Hash password
pw_hash = bcrypt.generate_password_hash('password')

# Validate password
bcrypt.check_password_hash(pw_hash, 'password')

Easily swap between multiple application configurations

from app.config import dev_config, test_config

app = Flask(__name__)

class dev_config():
    DEBUG = True

class test_config():
    TESTING = True

# Configure for testing
app.config.from_object(test_config)

# Configure for development
app.config.from_object(dev_config)

Form validation & CSRF protection with WTForms

Place a csrf token on a form:

{{ form.csrf_token }}

Validate it:

form.validate_on_submit()

Rate-limit routes

from app.extensions import limiter

@limiter.limit("5 per minute")
@auth.route('/login', methods=['GET', 'POST'])
def login():
    # ...
    return 'your_login_page_contents'

Automated tests

Run the test suite:

pytest

Use any relational database using the SQLAlchemy ORM

from app.user.models import User

# Fetch user by id
user = User.get_by_id(id)

# Save current state of user
user.update()

# Fetch a paginated set of users
users = User.query.paginate(page, 50)

Front-end asset management

Download front-end dependencies with yarn:

yarn install --modules-folder ./app/static/node_modules

Merge and compress them together with Flask-Assets:

flask assets build

Version your database schema

Display the current revision:

flask db current

Create a new migration:

flask db revision

Upgrade the database to a later version:

flask db upgrade

Internationalize the application for other languages (i18n)

Extract strings from source and compile a catalog (.pot):

pybabel extract -F babel.cfg -o i18n/messages.pot .

Create a new resource (.po) for German translators:

pybabel init -i i18n/messages.pot -d i18n -l de

Compile translations (.mo):

pybabel compile -d i18n

Merge changes into resource files:

pybabel update -i i18n/messages.pot -d i18n

More Repositories

1

radio

Internet radio as a service with liquidsoap and icecast wrapped with docker.
15
star
2

fluid

Browse your local movies with IMDB data and stream them to a Chromecast.
Python
13
star
3

discogs-buttons

Display your Discogs profile on your website with these three simple social media buttons featuring dynamic collection, inventory, or want-list counts.
HTML
10
star
4

beatport

A python wrapper around the Beatport.com API
Python
10
star
5

regina

Fetch new releases from http://www.juno.co.uk/.
Python
8
star
6

dotfiles

My system configuration.
Shell
7
star
7

docker-bones

Docker, Flask, Gunicorn, Redis, Memcached, and PostgreSQL
Shell
6
star
8

midnightathletics

Commercial free radio featuring contemporary underground dance music from around the world.
HTML
6
star
9

transmogrify

Simple script to convert a YouTube video into an mp3.
Shell
5
star
10

get-waffles

Fetch freeleech torrents from waffles.fm with at least one leecher for automatic ratio gains.
Python
4
star
11

pi-hole

A network-level black hole for internet advertisements running on a Raspberry Pi deployed via BalenaCloud.
4
star
12

halite

My bot for https://halite.io
Python
3
star
13

qr-code-wifi

Generate a QR code containing WIFI credentials.
Python
2
star
14

flask-travis

Easily fetch TravisCI environment variables when testing.
Python
2
star
15

clever-harvest

Gather environmental metrics from an array of sensors connected to a Raspberry Pi deployed via balenaCloud.
Python
2
star
16

pianobar-notify

Pianobar desktop notifications on OSX.
Ruby
2
star
17

vagabond

Search https://www.airbnb.com/ without leaving the prompt.
Python
1
star
18

carcassonne

Asynchronous Carcassonne in the browser.
Python
1
star
19

placepuppy

Quick & cute image placeholders for everyone. Because puppies > kittens.
Python
1
star
20

pwgen_xkcd

Generate an xkcd passphrase randomly selected from a list of words.
Python
1
star
21

blog

This is a deployment of Ghost via Kubernetes.
1
star
22

cs340.data_structures

A collection of assignments from my data structures & algorithm analysis class. Assignments include all of the container classes, iterators and algorithms in the STL.
C++
1
star