Supercharge your FastAPI development. A backend for perfectionists with deadlines and lovers of asynchronous programming.
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.
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.
- 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.
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.
Poetry is a dependency manager for Python. Follow the steps below to install Poetry:
-
Open a terminal.
-
Run the following command to install Poetry using pip:
pip install poetry
-
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.
To streamline the usage of this boilerplate, we've provided a convenient CLI tool. From the root project directory, execute the following steps:
- Clone the repository, running the following command:
git clone https://github.com/joaoflaviosantos/fastapi-async-sqlmodel-boilerplate.git
- Navigate to the cloned repository:
cd fastapi-async-sqlmodel-boilerplate
- 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.
- FastAPI Boilerplate by Igor Magalhรฃes
- FastAPI Alembic SQLModel Async by Jonathan Vargas
- The Ultimate FastAPI Async Setup by Evgeniy Tretyakov
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! ๐