Skip to content

Releases: benavlabs/FastAPI-boilerplate

0.16.0

10 Nov 20:29
16271bb

Choose a tag to compare

🚀 FastAPI Boilerplate v0.16.0

We're excited to announce v0.16.0 with major improvements to type safety and developer experience through the latest FastCRUD integration! 🎉

🌟 Key Highlights

  • Enhanced Type Safety: Upgraded to FastCRUD 0.19.1 with improved overloads for better type inference
  • Cleaner Codebase: Removed unnecessary manual type casting across the entire codebase
  • Better Developer Experience: Eliminated union types when using schema-based column selection
  • Health Check Endpoints: New endpoints for monitoring application health
  • Improved Documentation: Updated guides to reflect FastCRUD 0.19.0+ changes

🔧 What's Changed

  • 🔗 Fix: Fixed the discord link by @LucasQR in #203
  • 📚 Documentation: Updated docs to use SQLAlchemy 2.0 syntax by @carlosplanchon in #205
  • 🛠️ Fix: Update pre-commit hooks version to solve InvalidManifestError by @rragundez in #207
  • ⚙️ Enhancement: Update python specifier by @rragundez in #209
  • 🏥 New Feature: Add health check endpoints by @rragundez in #210
  • 📝 Documentation: Added note about falsy values from FastCRUD by @carlosplanchon in #214
  • 📦 Enhancement: Add pre-commit dependency in DEV group by @rragundez in #208
  • 🔄 Refactor: Adapt imports to FastCRUD 0.19.0 pagination structure by @carlosplanchon in #215
  • Major Update: Upgrade to FastCRUD 0.19.1 with better typing by @igorbenav in #217

⚡ FastCRUD 0.19.1 Type Safety Improvements

This release brings significant type safety enhancements through FastCRUD 0.19.1:

Before v0.16.0:

# Required manual casting due to union types
user = await crud_users.get(db=db, username="john", schema_to_select=UserRead)
user = cast(dict[str, Any], user)  # Manual cast needed! 😞
if user["tier_id"] is None:
    # ...

After v0.16.0:

# Direct type-safe access - no casting needed!
user = await crud_users.get(db=db, username="john", schema_to_select=UserRead)
if user["tier_id"] is None:  # Directly type-safe! 😍
    # ...

What This Means:

  • No More Manual Casting: Eliminated all cast(dict[str, Any], result) calls
  • Better IDE Support: Improved autocomplete and error detection
  • Cleaner Code: Removed 25+ unnecessary cast statements across the codebase
  • Type Safety: mypy now properly infers Optional[dict[str, Any]] for schema-based column selection

🏥 Health Check Endpoints

New health monitoring capabilities:

GET /health          # Basic health check
GET /health/detailed # Detailed system health with database status

Perfect for:

  • Load balancer health checks
  • Monitoring system integration
  • Container orchestration readiness probes

🎉 New Contributors

We're grateful to welcome these new contributors to the project:

🔗 Links

🚀 Migration Guide

For Existing Projects:

  1. Update Dependencies:

    # Update pyproject.toml
    fastcrud>=0.19.1
    
    # Sync dependencies
    uv sync
  2. Remove Manual Casts (if you added any):

    # Remove these patterns:
    user = cast(dict[str, Any], user)
    tier = cast(dict[str, Any], tier)
    
    # FastCRUD 0.19.1 overloads handle this automatically!
  3. Update Import Structure:

    # New import structure for pagination
    from fastcrud import PaginatedListResponse, compute_offset, paginated_response
  4. Run Tests:

    uv run pytest
    uv run mypy src/ --config-file pyproject.toml

Benefits You'll Get:

  • Better Type Safety: No more union types for common patterns
  • Cleaner Code: Removed casting boilerplate
  • Enhanced DX: Better IDE support and error detection
  • Future-Proof: Ready for FastCRUD's continued improvements

What's Changed

New Contributors

Full Changelog: v0.15.0...v0.16.0



Powered by Benav Labs - benav.io

0.15.0

09 Oct 19:28
7c58913

Choose a tag to compare

🚀 FastAPI Boilerplate v0.15.0

We're excited to announce the launch of our Discord community! 🎉 Join fellow developers, get help, share projects, and stay updated with the latest FastAPI boilerplate developments.

🌟 Key Highlights

  • Discord Community: Join our new Discord server for real-time discussions and community support
  • UUID v7 Migration: Switched from UUID v4 to v7 for better performance and ordering
  • Enhanced Documentation: Improved documentation structure and added new resources

🔧 What's Changed

🎉 New Contributors

We're grateful to welcome these new contributors to the project:

🔗 Links


What's Changed

New Contributors

Full Changelog: v0.14.0...v0.15.0

0.14.0

02 Jul 04:53
01632e2

Choose a tag to compare

Benav Labs FastAPI boilerplate

Yet another template to speed your FastAPI development up, now with proper docs and an admin panel.

Python FastAPI Pydantic PostgreSQL Redis Docker NGINX


What's Changed

New Contributors

Full Changelog: v0.13.0...v0.14.0

📖 Documentation

📚 Visit our comprehensive documentation at benavlabs.github.io/FastAPI-boilerplate

⚠️ Documentation Status

This is our first version of the documentation. While functional, we acknowledge it's rough around the edges - there's a huge amount to document and we needed to start somewhere! We built this foundation (with a lot of AI assistance) so we can improve upon it.

Better documentation, examples, and guides are actively being developed. Contributions and feedback are greatly appreciated!

This README provides a quick reference for LLMs and developers, but the full documentation contains detailed guides, examples, and best practices.


0. About

FastAPI boilerplate creates an extendable async API using FastAPI, Pydantic V2, SQLAlchemy 2.0 and PostgreSQL:

  • FastAPI: modern Python web framework for building APIs
  • Pydantic V2: the most widely used data Python validation library, rewritten in Rust (5x-50x faster)
  • SQLAlchemy 2.0: Python SQL toolkit and Object Relational Mapper
  • PostgreSQL: The World's Most Advanced Open Source Relational Database
  • Redis: Open source, in-memory data store used by millions as a cache, message broker and more.
  • ARQ Job queues and RPC in python with asyncio and redis.
  • Docker Compose With a single command, create and start all the services from your configuration.
  • NGINX High-performance low resource consumption web server used for Reverse Proxy and Load Balancing.

Tip

There's a SQLModel version as well, but it's no longer updated: SQLModel-boilerplate.

1. Features

  • ⚡️ Fully async
  • 🚀 Pydantic V2 and SQLAlchemy 2.0
  • 🔐 User authentication with JWT
  • 🍪 Cookie based refresh token
  • 🏬 Easy redis caching
  • 👜 Easy client-side caching
  • 🚦 ARQ integration for task queue
  • ⚙️ Efficient and robust queries with fastcrud
  • ⎘ Out of the box offset and cursor pagination support with fastcrud
  • 🛑 Rate Limiter dependency
  • 👮 FastAPI docs behind authentication and hidden based on the environment
  • 🔧 Modern and light admin interface powered by CRUDAdmin
  • 🚚 Easy running with docker compose
  • ⚖️ NGINX Reverse Proxy and Load Balancing

2. Contents

  1. About
  2. Features
  3. Contents
  4. Prerequisites
    1. Environment Variables (.env)
    2. Docker Compose
    3. From Scratch
  5. Usage
    1. Docker Compose
    2. From Scratch
      1. Packages
      2. Running PostgreSQL With Docker
      3. Running Redis with Docker
      4. Running the API
    3. Creating the first superuser
    4. Database Migrations
  6. Extending
    1. Project Structure
    2. Database Model
    3. SQLAlchemy Models
    4. Pydantic Schemas
    5. Alembic Migrations
    6. CRUD
    7. Routes
      1. Paginated Responses
      2. HTTP Exceptions
    8. Caching
    9. More Advanced Caching
    10. ARQ Job Queues
    11. Rate Limiting
    12. JWT Authentication
    13. Admin Panel
    14. Running
    15. Create Application
    16. Opting Out of Services
  7. Running in Production
    1. Uvicorn Workers with Gunicorn
    2. Running With NGINX
      1. One Server
      2. Multiple Servers
  8. Testing
  9. Contributing
  10. References
  11. [Licens...
Read more

0.13.0

09 May 02:54
4c1f9af

Choose a tag to compare

0.13.0 Summary

 🚀Features

 🔎Bug fixes

  • minor mypy and ruff fixes
  • gunicorn bumped, security issue fixed
  • fastcrud bumped to 0.12.0 with bug fixes

What's Changed

Full Changelog: v0.12.4...v0.13.0

0.12.4

22 Feb 08:51
45781d7

Choose a tag to compare

0.12.4 Summary

 🚀Features

  • improved scripts logging

 🔎Bug fixes

  • remove db.commit() from async_get_db - thanks @mithun2003
  • using fastcrud, result from get is no longer a db_row object, so no longer passing it in delete

What's Changed

  • logging added to scripts, get_db fix, endpoints fixed for fastcrud usage by @igorbenav in #121

Full Changelog: v0.12.3...v0.12.4

0.12.3

15 Feb 03:28
b1a8370

Choose a tag to compare

0.12.3

 🔎Bug fixes

What's Changed

New Contributors

Full Changelog: v0.12.2...v0.12.3

0.12.2

11 Feb 21:59
189d5fd

Choose a tag to compare

0.12.2

⚡️Enhancements

  • now using recommended lifespan events instead of startup and shutdown events
  • libs bumped

 🔎Bug fixes

  • wrong .env reference in docker-compose fixed

What's Changed

Full Changelog: v0.11.1...v0.12.2

0.11.1

03 Feb 19:17
444ce98

Choose a tag to compare

0.11.1

 🔎Bug fixes

Warning

Content-Type Header ReDoS - FastAPI vulnerability fixed

Update python-multipart to 0.0.7 as soon as possible.

https://github.com/tiangolo/fastapi/security/advisories/GHSA-qf9m-vfgh-m389

What's Changed

Full Changelog: v0.11.0...v0.11.1

0.11.0

24 Jan 06:19
2694534

Choose a tag to compare

0.11.0 Summary

 🚀Features

  • replaced CRUDBase with fastcrud for more robust operations
  • worker script refactored, thanks @AlessioBugetti
  • print statements removed, thanks @shreyasSarve
  • PGAdmin container for PostgreSQL administration and debugging, thanks @gmirsky
  • create_tables_on_start parameter added in setup function
  • ruff added as pre-commit, thanks @luca-medeiros

📝Docs

  • all docs updated to reflect changes
  • pull request template added
  • Contributing moved to its own file and enhanced
  • Issue template added
  • Code of conduct added

1. fastcrud

Set Up FastAPI and FastCRUD

from fastapi import FastAPI
from fastcrud import FastCRUD, crud_router
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
from sqlalchemy.orm import sessionmaker

# Database setup (Async SQLAlchemy)
DATABASE_URL = "sqlite+aiosqlite:///./test.db"
engine = create_async_engine(DATABASE_URL, echo=True)
async_session = sessionmaker(engine, class_=AsyncSession, expire_on_commit=False)

# FastAPI app
app = FastAPI()

# CRUD operations setup
crud = FastCRUD(Item)

# CRUD router setup
item_router = crud_router(
    session=async_session,
    model=Item,
    crud=crud,
    create_schema=ItemCreateSchema,
    update_schema=ItemUpdateSchema,
    path="/items",
    tags=["Items"]
)

app.include_router(item_router)

Using FastCRUD in User-Defined FastAPI Endpoints

For more control over your endpoints, you can use FastCRUD directly within your custom FastAPI route functions. Here's an example:

Usage:

from fastapi import FastAPI, Depends, HTTPException
from sqlalchemy.ext.asyncio import AsyncSession
from fastcrud import FastCRUD

from yourapp.models import Item
from yourapp.schemas import ItemCreateSchema, ItemUpdateSchema

app = FastAPI()

# Assume async_session is already set up as per the previous example

# Instantiate FastCRUD with your model
item_crud = FastCRUD(Item)

@app.post("/custom/items/")
async def create_item(item_data: ItemCreateSchema, db: AsyncSession = Depends(async_session)):
    return await item_crud.create(db, item_data)

@app.get("/custom/items/{item_id}")
async def read_item(item_id: int, db: AsyncSession = Depends(async_session)):
    item = await item_crud.get(db, id=item_id)
    if not item:
        raise HTTPException(status_code=404, detail="Item not found")
    return item

# You can add more routes for update and delete operations in a similar fashion

To know all available methods, check it in fastcrud readme.

2. create_tables_on_start

If you want to stop tables from being created every time you run the api, you should disable this here:

# app/main.py

from .api import router
from .core.config import settings
from .core.setup import create_application

# create_tables_on_start defaults to True
app = create_application(router=router, settings=settings, create_tables_on_start=False)

 🔎Bug fixes

  • pyproject.toml fixed, thanks @DmitryIo
  • get task endpoint bug fixed
  • deprecated typing classes replaced, thanks @eredden

What's Changed

New Contributors

Full Changelog: v0.10.0...v0.11.0

0.10.0

28 Dec 03:32
ecf206d

Choose a tag to compare

0.10.0 Summary

 🚀Features

  • datetime refactored to be timezone aware #79 #82 (thanks @mithun2003)
  • passlib replaced with bcryptfor password hashing #74
  • pydantic validator moved to v2 field_Validator #72
  • config port data type consistency #69 (thanks @luca-medeiros)
  • pyproject.toml moved to the root folder #65
  • Tests folder moved to core, imports changed to relative imports #65

📝Docs

  • Now there's the option to use a template for .env, docker-compose.yml and Dockerfile:

Tip

If you are in a hurry, you may use one of the following templates (containing a .env, docker-compose.yml and Dockerfile):

Warning

Do not forget to place docker-compose.yml and Dockerfile in the root folder, while .env should be in the src folder.

  • Docs to run with NGINX were revised and are clearer now

🔎Bug fixes

  • CRUDBase count method fixed when kwargs is none #81
  • pydantic allow_reuse removed #70
  • pagination bug fixed #66
  • mypy multiple type hint fixes

What's Changed

New Contributors🎉

Full Changelog: v0.9.0...v0.10.0