/flask-by-example

flask, heroku, environment variables, sqlalchemy, flask-migrate, redis

Primary LanguagePython

Flask by Example

Blog Posts

This is the the repo for the Real Python blog series, Flask by Example -

  1. Part One: Setup a local development environment and then deploy both a staging environment and a production environment on Heroku. (current)**
  2. Part Two: Setup a PostgreSQL database along with SQLAlchemy and Alembic to handle migrations.
  3. Part Three: Add in the back-end logic to scrape and then process the counting of words from a webpage using the requests, BeautifulSoup, and Natural Language Toolkit (NLTK) libraries.
  4. Part Four: Implement a Redis task queue to handle the text processing.
  5. Part Five: Setup Angular on the front-end to continuously poll the back-end to see if the request is done.
  6. Part Six: Push to the staging server on Heroku - setting up Redis, detailing how to run two processes (web and worker) on a single Dyno.
  7. Part Seven: Update the front-end to make it more user-friendly.
  8. Part Eight: Add the D3 library into the mix to graph a frequency distribution and histogram.

Check out http://realpython.com

Quick Start

First steps

# create virtualenvwrapper
$ mkvirtualenv wordcounts`

# install requirements
$ pip install -r requirements.txt

Create Post Activate file

# create the file in vim
vi $VIRTUAL_ENV/bin/postactivate
# add the following to the file
cd ~/path/to/your/project
export APP_SETTINGS="config.DevelopmentConfig"
export DATABASE_URL="postgresql://localhost/wordcount_dev"

Setup Migrations

$ python manage.py db init
$ python manage.py db migrate
$ python manage.py db upgrade

Run

# run redis in new terminal window
$ redis server

# run worker in new terminal window
$ workon wordcounts
$ python worker.py

# run the app
python app.py