FastAPI with Async REST API with PostgreSQL on Azure App Service
Detailed Tutorials on Development & Deployment
- Development: Implementing Async REST APIs in FastAPI with PostgreSQL CRUD
- Debugging in VS Code: Debug FastAPI in VS Code IDE
- Deployment Deploy FastAPI on Azure App Service
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}
)
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
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
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]
In command terminal run the following command
uvicorn main:app --reload
gunicorn -w 4 -k uvicorn.workers.UvicornWorker main:app