Skip to content

joaoflaviosantos/fastapi-async-sqlmodel-boilerplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

98 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

FastAPI Async SQLModel Boilerplate

Supercharge your FastAPI development. A backend for perfectionists with deadlines and lovers of asynchronous programming.

White and blue rocket with FastAPI text on it. A Python logo floating next to the rocket.

Python FastAPI SQLModel Pydantic SQLAlchemy PostgreSQL Redis Docker NGINX

๐Ÿ” Project Overview

This FastAPI boilerplate for high-performance APIs leverages async programming alongside libraries such as SQLModel, Redis, ARQ, NGINX, and Docker. It follows a Django-inspired folder structure for a clear, modular codebase. Key areas like system/tiers, admin/users and blog/posts showcase the optimal balance between modularity and clarity.

It aims to provide a robust structure while serving as an excellent tool for quick POC (Proof of Concept) validations and MVP (Minimum Viable Product) launches. Crafted to attract enthusiasts who appreciate how Django operates, this project offers a solid foundation for API development, incorporating a blend of cutting-edge technologies and structural principles.

๐ŸŒŸ Key Features

This project seeks to provide a strong foundation for API development, incorporating a blend of cutting-edge technologies and structural principles:

  • โšก๏ธ Fully Async: Leverage the power of asynchronous programming.
  • ๐Ÿš€ FastAPI: Utilize FastAPI for rapid API development.
  • ๐Ÿงฐ SQLModel: Seamlessly integrates with SQLAlchemy 2.0 for versatile Python SQL operations, reducing the mapping between persistence and transport classes. Using Pydantic v2 can result in performance improvements from 5x to 50x compared to Pydantic v1.
  • ๐Ÿ” JWT User Authentication: Secure user authentication using JSON Web Tokens.
  • ๐Ÿช Cookie-based Refresh Token: Implement a refresh token mechanism using cookies.
  • ๐Ÿฌ Easy Redis Caching: Utilize Redis for simple and effective caching.
  • ๐Ÿ‘œ Client-side Caching: Facilitate easy client-side caching for improved performance.
  • ๐Ÿšฆ ARQ Integration: Seamlessly integrate ARQ for efficient task queue management.
  • โš™๏ธ Efficient Querying: Optimize database queries by fetching only what's needed, with support for joins.
  • โŽ˜ Pagination Support: Out-of-the-box pagination support for enhanced data presentation.
  • ๐Ÿ›‘ Rate Limiter Dependency: Implement a rate limiter for controlled API access.
  • ๐Ÿ‘ฎ Secure FastAPI Docs: Restrict FastAPI docs behind authentication and hide based on the environment.
  • ๐Ÿฆพ Easily Extendable: Extend and customize the project effortlessly.
  • ๐Ÿคธโ€โ™‚๏ธ Flexible: Adapt the boilerplate to suit your specific needs.
  • ๐Ÿšš Docker Compose: Easily run the project with Docker Compose.
  • โš–๏ธ NGINX Reverse Proxy and Load Balancing: Enhance scalability with NGINX reverse proxy and load balancing.

๐ŸŽฏ Project Goals

  • Leverage the power of FastAPI for building high-performance APIs.
  • Implement asynchronous programming wherever applicable for optimal performance.
  • Integrate Redis for caching, rate limiting, and improving data access speed.
  • Utilize ARQ for handling background tasks asynchronously.
  • Implement a robust logging system to track and manage application events efficiently.
  • Manage database migrations seamlessly using Alembic.
  • Develop comprehensive unit tests for API endpoints using pytest.
  • Implement using SQLModel to streamline the interaction between the database and the API.
  • Provide a CLI tool for easy project execution and management.
  • Provide diverse deployment options to ensure flexibility and accessibility.

๐Ÿ“‹ Prerequisites

Before you begin, ensure you have the following prerequisites installed and configured:

  • PostgreSQL: Set up a PostgreSQL database.
  • Redis: Install and configure a Redis server.
  • Python: Make sure to have Python 3.11 or a newer version installed on your system.
  • Poetry: Install Poetry for managing dependencies.

Note: Soon, there will be an additional option for development using Docker containers.

Installing Poetry

Poetry is a dependency manager for Python. Follow the steps below to install Poetry:

  1. Open a terminal.

  2. Run the following command to install Poetry using pip:

    pip install poetry
  3. Verify the installation by running:

    poetry --version

    This should display the installed Poetry version.

Now that the requirements are met, you can begin working on your project.

๐Ÿค– Running the Project CLI

To streamline the usage of this boilerplate, we've provided a convenient CLI tool. From the root project directory, execute the following steps:

  1. Clone the repository, running the following command:
git clone https://github.com/joaoflaviosantos/fastapi-async-sqlmodel-boilerplate.git
  1. Navigate to the cloned repository:
cd fastapi-async-sqlmodel-boilerplate
  1. Run the setup (CLI tool) command:
python3 setup.py

This command automates various setup tasks, making it easier to get started with the project.

For more details for a manual setup, please refer to the Backend README section.

๐ŸŒ Reference Projects

Feel free to use this boilerplate as a starting point for your own projects, and adapt it based on your specific requirements and use cases. Happy coding! ๐ŸŒŸ

About

A fully asynchronous FastAPI boilerplate. Built for extensibility and speed, it incorporates FastAPI, SQLModel, Alembic, PostgreSQL, Redis, and ARQ. ๐Ÿš€

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages