headwinds / forge

Flask API built with Blueprints standing on the shoulders of Flaskex

Home Page:https://scout.now.sh

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Forge a modular Python API with blueprints, csrf protection, and recaptcha

so you want to build a simple Flask based python API with Flaskex and deploy it with now?

Built on top of the Flaskex starter, I added the following:

  • registration with recaptcha
  • verify registration account via email confirmation
  • more modular blueprint routes so that you can serve json or html templates
  • a route which performs a database join
  • routes that perform all the REST verbs: GET, POST, PUT, DELETE, PATCH
  • redesigned the landing page flow and added a few new pages
  • offline dev: so that you can code without wifi
  • offline sync: the end user could do work in a native app and sync later

Getting Started

After you have setup your recaptcha keys, you can either begin with either the remote or local deployment.

Local deployment

Then let's dig into the code base and run it locally.

  1. create a virtual environment called env
python -m venv tutorial-env 
  1. install the requirements.
$ source env/bin/activate 
$ python install -r requirements.txt
  1. rename .env-sample to .env and edit the local database connection uri to match your local setup
DATABASE_URI = "postgresql+psycopg2://testuser:testpassword@localhost:5432/postgres"

If this fails, you will probably need to create a test user on your postgres DB.

  1. run the app
$ python app.py 

Open your browswer to http://localhost:5000

Remote deployment

Let's deploy it right away in 3 steps.

  1. setup your remote postgreSQL database.

I went with ElephantSQL which has a nice free tier for hobbyists. Once you create your database, find that database from the list all instances drop down at the top. On the details screen, you should be able to find your url.

  1. Add your zeit secrets
now secret add flashex-db-uri 'postgresql+psycopg2://username:password@dbhost:dbport/dbname' 
now secret add flaskex-secret-key 'flaskex' 
  1. deploy
now

Open your browswer then copy and paste the url it provided to your clipboard.

WSGI Server - Zeit supports Waitress

Flask & Waitress

Credit

This codebase is mainly based on the original Flaskex sample with inspiration taken from the now flaskex example which for me went too far. I decided I didn't want a separate flask app running for each route and thought it easier for someone learning python to concentrate on the single app approach.

I also wanted to this example to work completely offline so that I could tinker with it during my subway commute.

Other nice flask starter projects

About

Flask API built with Blueprints standing on the shoulders of Flaskex

https://scout.now.sh

License:MIT License


Languages

Language:Python 100.0%