Skip to content

Files

Latest commit

5b430e1 · Jul 7, 2024

History

History

FastAPIElasticSearch

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Jul 7, 2024
Jul 7, 2024
Jul 7, 2024
Jul 7, 2024
Jul 7, 2024
Jul 7, 2024
Jul 7, 2024
Jul 7, 2024
Jul 7, 2024
Jul 7, 2024

FastAPI

FastAPI is a Python API Application with FastAPI, JWT Authentication, Elastic search, 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.
  • 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.
  • Elasticsearch is a distributed search and analytics engine built on Apache Lucene. Since its release in 2010, Elasticsearch has quickly become the most popular search engine and is commonly used for log analytics, full-text search, security intelligence, business analytics, and operational intelligence use cases.

How to use it

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: