Skip to content

Latest commit

 

History

History

FastAPISQLModel

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

FastAPI-SQLModel

FastAPI-SQLModel is a Python API Application with FastAPI, JWT Authentication, Postgresql, SQLModel, Docker and Jenkins Pipeline

Features

  • Full Docker integration (Docker based).
  • Production ready Python web server using Uvicorn and Gunicorn.
  • Python FastAPI backend:
    • Fast: Very high performance, on par with NodeJS and Go (thanks to Starlette and Pydantic).
    • Intuitive: Great editor support. Completion everywhere. Less time debugging.
    • Easy: Designed to be easy to use and learn. Less time reading docs.
    • Short: Minimize code duplication. Multiple features from each parameter declaration.
    • Robust: Get production-ready code. With automatic interactive documentation.
    • Standards-based: Based on (and fully compatible with) the open standards for APIs: OpenAPI and JSON Schema.
    • Many other features including automatic validation, serialization, interactive documentation, authentication with OAuth2 JWT tokens, etc.
  • Secure password hashing by default.
  • JWT token authentication.
  • SQLModel new SQL ORM.
  • Basic starting models for users (modify and remove as you need).
  • CORS (Cross Origin Resource Sharing).
  • Load balancing between frontend and backend with Nginx, so you can have both under the same domain, separated by path, but served by different containers.
  • Let's Encrypt HTTPS certificates automatic generation.

How to use it

psycopg2

psycopg2 is postgresql adapter for sqlalchamy this can't be installed directly in linux using pip, use below command to install

sudo apt-get install python3-psycopg2
sudo apt-get install libpq-dev python3-dev

JWT token authentication

JWT-Signature using RSA256 algorithm.

You can generate a 2048-bit RSA key pair with the following commands:

openssl genpkey -algorithm RSA -out rsa_private.pem -pkeyopt rsa_keygen_bits:2048
openssl rsa -in rsa_private.pem -pubout -out rsa_public.pem

Create SSL Certificates using Certbot

Generate SSL cerificates from trusted thirdparty or openssl

For Open SSL use Certbot (Let'sencrypt)
sudo apt-get update
sudo apt-get install software-properties-common
sudo add-apt-repository universe
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get install certbot python3-certbot-nginx

sudo certbot -d example.com certonly

certificates will be found in "/etc/letsencrypt/live/example.com/"

Generate a set of 4096-bit diffie-hellman parameters to improve security for some types of ciphers.

sudo mkdir -p /etc/nginx/ssl
sudo openssl dhparam -out /etc/nginx/ssl/dhp-4096.pem 4096

Deployment

FastAPI Backend can be deployed using docker. Use below docker image for deployment.

tiangolo/uvicorn-gunicorn-fastapi-docker - Docker image with Uvicorn managed by Gunicorn for high-performance FastAPI web applications in Python 3.6 and above with performance auto-tuning. Optionally with Alpine Linux.

References

The fundamental repositories: