Skip to content

FastAPI Tutorials & Deployment Methods to Cloud and on-prem infrastructures

License

Notifications You must be signed in to change notification settings

windson/fastapi

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Deploy FastAPI on Azure

FastAPI with Async REST API with PostgreSQL on Azure App Service

Detailed Tutorials on Development & Deployment

Article 📝 Video 📺 Code 💻
Implementing Async REST APIs in FastAPI with PostgreSQL CRUD Implementing Async REST APIs in Python using FastAPI with PostgreSQL CRUD FastAPI CRUD Async PostgreSQL
Deploy FastAPI with CRUD + PostgreSQL on Azure App Service How to Deploy FastAPI on Azure App Service in just 30 minutes Deploy FastAPI on Azure
Debug FastAPI in VS Code IDE - FastAPI CRUD Async PostgreSQL

Setup this Repo on Local PC

In main.py comment the following line

DATABASE_URL = 'postgresql://{}:{}@{}:{}/{}?sslmode={}'.format(db_username,db_password, host_server, db_server_port, database_name, ssl_mode)

and uncomment the following line

DATABASE_URL = "sqlite:///./test.db"

Replace following code

engine = sqlalchemy.create_engine(
    DATABASE_URL, pool_size=20, max_overflow=0
)

with

engine = sqlalchemy.create_engine(
    DATABASE_URL, connect_args={"check_same_thread": False}
)

Windows Users

In command terminal run the following command

python -m venv env
env/Scripts/activate
python -m pip install -U pip
pip install -r requirements.txt

CentOS Users Setup PIP3 and Virtual Environment

In command terminal run the following command

apt install python3-venv
python3 -m venv env
source ./env/bin/activate
python -m pip install -U pip
pip install -r requirements.txt

Ubuntu Users Setup PIP3 and Virtual Environment

In command terminal run the following command

sudo apt install python3-pip
sudo pip3 install virtualenv
virtualenv env
source ./env/bin/activate
python -m pip install -U pip
pip install -r requirements.txt

If you want to use sqlite then install databases module for sqlite as follows

pip install databases[sqlite]

Run this app on Local PC

In command terminal run the following command

uvicorn main:app --reload

Deployment command

gunicorn -w 4 -k uvicorn.workers.UvicornWorker main:app