# fastapi-boilerplate | Benav Labs | Knowledge Base | Instagit

An extendable async API using FastAPI, Pydantic V2, SQLAlchemy 2.0, PostgreSQL and Redis.

GitHub Stars: 1.8k

Repository: https://github.com/benavlabs/fastapi-boilerplate

---

## Articles

### [How to Implement Custom User Authentication Flows in FastAPI Boilerplate](/benavlabs/fastapi-boilerplate/how-to-implement-custom-user-authentication-flows)

Implement custom user authentication flows in FastAPI Boilerplate. Extend the JWT system with custom claims or MFA without breaking endpoints. Learn how to modify security.py for your needs.

- Tags: how-to-guide
- Published: 2026-02-26

### [How to Extend FastCRUD Functionalities in FastAPI Boilerplate](/benavlabs/fastapi-boilerplate/how-to-extend-fastcrud-functionalities)

Enhance FastAPI boilerplate with custom business logic by subclassing FastCRUD. Seamlessly inject type-safe operations while extending core functionalities.

- Tags: how-to-guide
- Published: 2026-02-26

### [How to Run the FastAPI Boilerplate Application Using Docker Compose](/benavlabs/fastapi-boilerplate/how-to-run-the-application-using-docker-compose)

Easily run the FastAPI boilerplate application with Docker Compose. Use the setup script to configure and launch PostgreSQL, Redis, and FastAPI services in one command.

- Tags: how-to-guide
- Published: 2026-02-26

### [How to Implement Token Refresh Logic in FastAPI: A Complete JWT Guide](/benavlabs/fastapi-boilerplate/how-to-implement-token-refresh-logic)

Implement token refresh logic in FastAPI using short-lived access tokens and long-lived refresh tokens. Secure your JWT authentication with this complete guide.

- Tags: how-to-guide
- Published: 2026-02-26

### [How to Use OAuth2PasswordRequestForm for User Login in FastAPI](/benavlabs/fastapi-boilerplate/how-to-use-oauth2passwordrequestform-for-user-login)

Learn to use OAuth2PasswordRequestForm in FastAPI for secure user login. Implement OAuth2 password grants with JWT tokens and HttpOnly cookies for robust authentication.

- Tags: deep-dive
- Published: 2026-02-26

### [How to Set Up File and Console Logging in FastAPI](/benavlabs/fastapi-boilerplate/how-to-set-up-file-and-console-logging)

Learn to set up file and console logging in FastAPI using Python's logging module and structlog. Configure your FastAPI app's logging easily with this guide.

- Tags: how-to-guide
- Published: 2026-02-26

### [How to Manage JWT Settings in FastAPI: Secret Keys and Token Expiration](/benavlabs/fastapi-boilerplate/how-to-manage-jwt-settings-like-secret-key-and-expiration-times)

Easily manage JWT settings in FastAPI secrets and token expiration using environment variables in fastapi-boilerplate. Configure your app securely and efficiently.

- Tags: tutorial
- Published: 2026-02-26

### [How to Configure Redis for Cache, Queue, and Rate Limiting in FastAPI](/benavlabs/fastapi-boilerplate/how-to-configure-redis-for-cache-queue-and-rate-limiting)

Learn to configure Redis for cache queue and rate limiting in FastAPI using benavlabs fastapi boilerplate. Simplify your app performance with Pydantic settings and lifespan events.

- Tags: how-to-guide
- Published: 2026-02-26

### [How to Add Mixins Like UUIDMixin, TimestampMixin, and SoftDeleteMixin to FastAPI Models](/benavlabs/fastapi-boilerplate/how-to-add-mixins-like-uuidmixin-timestampmixin-softdeletemixin-to-models)

Easily add UUIDMixin, TimestampMixin, and SoftDeleteMixin to your FastAPI models by importing and inheriting from benavlabs/fastapi-boilerplate core models. Streamline your development.

- Tags: how-to-guide
- Published: 2026-02-26

### [How to Implement Cookie-Based Refresh Tokens in FastAPI: A Complete Guide](/benavlabs/fastapi-boilerplate/how-to-implement-cookie-based-refresh-tokens)

Learn to implement cookie-based refresh tokens in FastAPI using HttpOnly, Secure cookies. This guide enables stateless JWT renewal and helps mitigate XSS attacks.

- Tags: how-to-guide
- Published: 2026-02-26

### [How to Enable and Configure CORS Middleware in FastAPI Boilerplate](/benavlabs/fastapi-boilerplate/how-to-enable-and-configure-cors-middleware)

Learn to easily enable and configure CORS middleware in your FastAPI boilerplate project. Customize access settings via environment variables or code for robust API security.

- Tags: how-to-guide
- Published: 2026-02-26

### [How to Configure NGINX and Gunicorn for Production Deployment with FastAPI](/benavlabs/fastapi-boilerplate/how-to-configure-nginx-and-gunicorn-for-production-deployment)

Learn to deploy FastAPI to production with NGINX & Gunicorn. Implement TLS termination and multiple Uvicorn workers using the benavlabs fastapi-boilerplate containerized setup for optimal performance.

- Tags: how-to-guide
- Published: 2026-02-26

### [How to Integrate Alembic for Database Migrations in FastAPI Boilerplate](/benavlabs/fastapi-boilerplate/how-to-integrate-alembic-for-database-migrations)

Integrate Alembic for database migrations in FastAPI boilerplate. Learn how to generate and apply changes easily using standard Alembic CLI commands with this pre-configured setup.

- Tags: how-to-guide
- Published: 2026-02-26

### [How to Manage Environment-Specific Configurations in FastAPI: Local, Staging, and Production](/benavlabs/fastapi-boilerplate/how-to-manage-environment-specific-configurations-local-staging-prod)

Master environment-specific FastAPI configurations for local staging and production. Learn to centralize settings with Pydantic, load from env vars or .env files, and control features using the environment flag.

- Tags: how-to-guide
- Published: 2026-02-26

### [How to Customize the Minimal Admin Panel Provided by CRUDAdmin in FastAPI Boilerplate](/benavlabs/fastapi-boilerplate/how-to-customize-the-minimal-admin-panel-provided-by-crudadmin)

Customize the minimal CRUDAdmin panel in FastAPI Boilerplate by editing config and registering views. Control model behavior and global settings effectively.

- Tags: how-to-guide
- Published: 2026-02-26

### [How to Set Up Redis Caching for API Responses in FastAPI](/benavlabs/fastapi-boilerplate/how-to-set-up-redis-caching-for-api-responses)

Effortlessly set up Redis caching for API responses in FastAPI using the boilerplate project. This guide shows you how to automatically store and invalidate responses with a simple decorator.

- Tags: how-to-guide
- Published: 2026-02-26

### [How to Use FastCRUD for Generating CRUD Operations and Pagination in FastAPI](/benavlabs/fastapi-boilerplate/how-to-use-fastcrud-for-generating-crud-operations-and-pagination)

Learn how to use FastCRUD to auto-generate CRUD operations and pagination in FastAPI. This SQLAlchemy wrapper eliminates boilerplate and streamlines your development.

- Tags: how-to-guide
- Published: 2026-02-26

### [How to Define New Database Models Using SQLAlchemy 2.0 in the FastAPI Boilerplate](/benavlabs/fastapi-boilerplate/how-to-define-new-database-models-using-sqlalchemy-2.0)

Learn to define new database models with SQLAlchemy 2.0 in FastAPI boilerplate. Inherit from Base, use Mapped and mapped_column, and set __tablename__.

- Tags: how-to-guide
- Published: 2026-02-26

### [How to Configure Rate Limiting with Free and Pro Tiers in FastAPI Boilerplate](/benavlabs/fastapi-boilerplate/how-to-configure-rate-limiting-with-free-and-pro-tiers)

Learn to configure rate limiting with free and pro tiers in FastAPI Boilerplate. Implement Redis-backed sliding-window counters by defining rules and injecting dependencies.

- Tags: how-to-guide
- Published: 2026-02-26

### [How to Implement JWT Authentication with Access and Refresh Tokens in FastAPI](/benavlabs/fastapi-boilerplate/how-to-implement-jwt-authentication-with-access-and-refresh-tokens)

Learn to implement JWT authentication in FastAPI using access and refresh tokens. Secure your API with short-lived access tokens and http-only cookies for refresh tokens for enhanced security.

- Tags: how-to-guide
- Published: 2026-02-26

