Steps for Building a Flask API Application with Python 3

Below are the basic steps for building out a basic Flask API app.

It makes the assumption that you have Pipenv installed on your system for managing dependencies. (Pipenv tutorial)

Step 1 - Setup the Python Project with Pipenv

pipenv --three

Step 2 - Import Flask as a Dependency

pipenv install flask

Step 3 - Create file


Step 4 - Add Basic Code to Test Setup

Step 5 - Start Pipenv Shell

pipenv shell

Step 6 - Run Flask Server


Step 7 - Test in Browser

Go to localhost:5000 and you should see a screen like this (I have it zoomed in to make it easier to read):

Step 8 - Install Database and API Libraries

(Note the change in the name forĀ Flask-SQLAlchemy)

pipenv install Flask-SQLAlchemy
pipenv install flask-marshmallow
pipenv install marshmallow-sqlalchemy

Step 9 - Build Out CRUD API Actions

Step 10 - Setup SQLite Database and Tables

Enter Python shell:


>>> from crud import db
>>> db.create_all()

Step 11 - Start Server and Test API

Using a tool like Postman, you can: create, read, update, and delete users. One example is below: