Skip to content

Latest commit

 

History

History
98 lines (72 loc) · 2.92 KB

README.md

File metadata and controls

98 lines (72 loc) · 2.92 KB

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