Skip to content

windson/fastapi

 
 

Repository files navigation

Deploy FastAPI on Ubuntu and Serve using Caddy 2 Web Server

FastAPI with Async REST API with PostgreSQL on Ubuntu and Serve using Caddy 2 Web Server

Detailed Tutorials on Development & Deployment

Code 💻 Video 📺 Article 📝
Deploy FastAPI on GCP Deploy FastAPI Python app to Google Cloud Platform on App Engine Deploy FastAPI app on Google Cloud Platform
Deploying fastapi app to Heroku Deploy FastAPI on Heroku in just 6 minutes Create and Deploy FastAPI app to Heroku
FastAPI CRUD Async PostgreSQL Implementing Async REST APIs in Python using FastAPI with PostgreSQL CRUD Implementing Async REST APIs in FastAPI with PostgreSQL CRUD
Deploy FastAPI on Azure How to Deploy FastAPI on Azure App Service in just 30 minutes Deploy FastAPI with CRUD + PostgreSQL on Azure App Service
FastAPI CRUD Async PostgreSQL - Debug FastAPI in VS Code IDE
Deploy FastAPI on Ubuntu and Serve using Caddy 2 Web Server Deploy FastAPI on Ubuntu (FastAPI + CRUD + PostgreSQL + Gunicorn Systemd + Caddy 2) Deploy FastAPI on Ubuntu and Serve using Caddy 2 Web Server

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

Install 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

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

Releases

No releases published

Sponsor this project

 

Packages

 
 
 

Contributors