Member-only story
Build and Deploy Your Flask API With a Postgres Database
A useful template to help you spin up your next project and start building

We often find ourselves rewriting the same boilerplate code — like configuration, structure, and the build and deployment setup — when writing a Flask web service. The goal of this article is to help you minimise doing eating the same thing over and over in your next Flask API project. You will also learn how to deploy your Flask web service with a database live on Render.com. If you don’t use Render, no problem — this cookiecutter also uses Docker to help facilitate build and deployment on other platforms.
What’s Included in the Template
- 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.
High-level structure
Below is the structure of our Flask API. We will go through each file or component in the next section.

Breakdown of the structure
Let’s dissect and learn about the structure of our cookiecutter template.
main.py — where everything starts
This is the entry point of the API request.
- It contains the API endpoint and CLI declarations. It uses
Flask-Restful
for its APIs. - Creates the Flask app instance.
- Uses
Flask-Migrate
to run SQLAlchemy migrations. - Imports the API resources.
We might want to move the CLI functions when the file gets bigger.