Boilerplate code for quick docker implementation of REST API with JWT Authentication using FastAPI, PostgreSQL and PgAdmin.

Getting Started


Auth Description
Login Access Token OAuth2 compatible token login, get an access token for future requests
Check Session Test if a user is logged in by checking if a valid access token is in the header
Recover Password Password Recovery
Reset Password Reset your password
User Description
Create New User Create a new user
Get Current User By Id Get current user
Update Current User Update own user
Update Other User (SuperUser) Update a user
Create User (Without Authentication) Create new user without the need to be logged in.


Project setup

# clone the repo
$ git clone

# move to the project folder
$ cd FRDP

Creating virtual environment

  • Install pipenv a global python project pip install pipenv
  • Create a virtual environment for this project
# creating pipenv environment for python 3
$ pipenv --three

# activating the pipenv environment
$ pipenv shell

# if you have multiple python 3 versions installed then
$ pipenv install -d --python 3.8

# install all dependencies (include -d for installing dev dependencies)
$ pipenv install -d

Configured Enviromment


  • Using SQLAlchemy to Connect to our PostgreSQL Database
  • Containerization The Database.
  • Drop your PostgreSQL Configuration at the .env.sample and Don't Forget to change the Name to .env
# example of Configuration for the .env file

# Generate secret key using openssl rand -hex 32

# Email Defaut Intiger ex. 30, 60, 90

# Server Default

# Postgres default username and password

[email protected]

Running the Application

  • To run the Main we need to use uvicorn a lightning-fast ASGI server implementation, using uvloop and httptools.
# To run the Application under a reload enviromment use -- reload
$ uvicorn main:app --reload

Running the Docker Container

  • We have the Dockerfile created in above section. Now, we will use the Dockerfile to create the image of the FastAPI app and then start the FastAPI app container.
docker build
  • list all the docker images and you can also see the image frdp:latest in the list.
docker images
  • run the application at port 5000. The various options used are:
  • -p: publish the container's port to the host port.
  • -d: run the container in the background.
  • -i: run the container in interactive mode.
  • -t: to allocate pseudo-TTY.
  • --name: name of the container
docker container run -p 5000:5000 -dit --name FRDP frdp:latest
  • Check the status of the docker container
docker container ps