Skip to content


Repository files navigation


Cookiecutter for Flask API with Postgres

Project template for Flask API.

Medium post: A useful template to help you spin up your next project and start building.

What's included

  • Go live with a Continuous Deployment Pipeline using GitHub and Render's Infrastructure as Code. See sample IaC file here.
  • Works with SQLAlchemy / Postgres DB out of the box.
  • Uses mypy for static type checks.

Reference app

There is a sample reference package generated from our cookiecutter which you can refer to in here:

Deploy the Sample Repo built from this cookiecutter to

  • Check the deployed API: <API URL>/healthcheck
  • Ensure that you have deleted your resources from Render when you're done.


  1. Install cookiecutter

     pip install cookiecutter
  2. Cookie cut the template.

  3. Enter the values accordingly. Pick your project name.

  4. Change the working directory to the generated folder, same name as the project slug.

     cd <project_slug>

Run locally with docker

Use docker-compose

docker-compose up

Run the flask app outside docker

Bring up the Postgres DB container

docker-compose up -d db

Install requirements. mypy takes some time to install

pip install -r requirements.txt

⚠️ For Mac users: Make sure you run brew install postgresql. Stackoverflow

Initialise environment variables. The .env is used in docker-compose.yml.

export FLASK_APP="src/"
export POSTGRES_URL=""
export POSTGRES_DB="mydb"
export POSTGRES_USER="postgres"
export POSTGRES_PASSWORD="example"

Run migrations

chmod +x

Run flask

# initialise environment variables
flask run

Run tests

py.test -vv

Run with gunicorn

For production.

cd src && gunicorn main:app

Build and run commands in

Build command

pip install -r requirements.txt && ./

Run the app

cd src && gunicorn app:app