Skip to main content
  1. Projects/

fastapi-postgresql-boilerplate

··311 words·2 mins
Detail codes on Github

Introduction #

FPBP (fastapi-postgresql-boilerplate) is a boilerplate that can serve as a base for FastAPI with PostgreSQL.

🚀 FastAPI is a modern, fast (high-performance) web framework for building APIs with Python 3.6+ based on standard Python-type hints.
I made and used this boilerplate for projects that I’m working on. 🧑‍💻
it was powerful for building data-driven applications using schema for data validation, serialization, and documentation. 📝

Technology Stacks #

  • Python 3.10 - A programming language that lets you work quickly and integrate systems more effectively.
  • FastAPI A modern, fast (high-performance), web framework for building APIs with Python 3.8+ based on standard Python type hints.
  • Docker A platform designed to help developers build, share, and run container applications.
  • PostgreSQL An open-source object-relational database system.
  • SQLAlchemy the Python SQL toolkit and Object Relational Mapper.
  • Poetry A tool for dependency management and packaging in Python.
  • Pytest A framework that makes writing small, readable tests easy.
  • Ruff A fast Python linter and code formatter written in Rust.

Development Features #

  • JWT authentication, to ensure secure access to the API.
  • A Layered architecture (Controller, Service, Repository, Model).
  • Dependency injection for better code organization.
  • Swagger and Redoc for API documentation and testing.
  • ♻️ Schema validation, to ensure that input and output data conform to the defined schema.

Challenges and Solutions #

Dependency Injection is a powerful pattern for decoupling components and making them easier to test.
But sadly almost python frameworks don’t support it except FastAPI.
So, I chose FastAPI with many reasons, like performance, type hints, and also dependency injection. in Auth part and connection to the database, I used dependency injection to make it easier to test and maintain.

Conclusion #

Although it may not suit everyone’s needs, I hope this boilerplate will be helpful for those interested in building projects with FastAPI and PostgreSQL 🥸.

What’s next? #

  • Handle scheduled tasks with Celery