Releases: benavlabs/FastAPI-boilerplate
0.16.0
🚀 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 statusPerfect 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:
- @LucasQR made their first contribution in #203
- @rragundez made their first contribution in #207
🔗 Links
- Documentation: benavlabs.github.io/FastAPI-boilerplate
- Discord Community: Join our Discord server
- Full Changelog: v0.15.0...v0.16.0
🚀 Migration Guide
For Existing Projects:
-
Update Dependencies:
# Update pyproject.toml fastcrud>=0.19.1 # Sync dependencies uv sync
-
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!
-
Update Import Structure:
# New import structure for pagination from fastcrud import PaginatedListResponse, compute_offset, paginated_response
-
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
- Fixed the discord link by @LucasQR in #203
- Updating docs/user-guide/development.md to use SQLAlchemy 2.0 syntax. by @carlosplanchon in #205
- Update pre-commit hooks version to solve InvalidManifestError by @rragundez in #207
- Update python specifier by @rragundez in #209
- Add health check endpoints by @rragundez in #210
- Adding note on exceptions.md about falsy values possibly coming from FastCRUD in the future. by @carlosplanchon in #214
- 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
- update to fastcrud 0.19.1, better typing by @igorbenav in #217
New Contributors
- @LucasQR made their first contribution in #203
- @rragundez made their first contribution in #207
Full Changelog: v0.15.0...v0.16.0
0.15.0
🚀 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
- 🐛 Bugfix: Ensure user lookup returns model instance in write_post endpoint by @blackyau in #185
- 🔧 Fix: User create admin functionality by @igorbenav in #188
- ⚡ Performance: Switch from UUID v4 to v7 by @Saiyashwanth7 in #186
- 📚 Documentation: Add DeepWiki docs URL to README.md by @carlosplanchon in #192
- 🧹 Cleanup: Remove unused Redis SSL setting from admin init by @defp in #196
- 📖 Documentation: Issue documentation improvements by @emiliano-gandini-outeda in #199
- 🎮 Community: Add Discord community by @igorbenav in #200
🎉 New Contributors
We're grateful to welcome these new contributors to the project:
- @blackyau made their first contribution in #185
- @Saiyashwanth7 made their first contribution in #186
- @carlosplanchon made their first contribution in #192
- @defp made their first contribution in #196
- @emiliano-gandini-outeda made their first contribution in #199
🔗 Links
- Discord Community: Join our Discord server
- Full Changelog: v0.14.0...v0.15.0
What's Changed
- bugfix: ensure user lookup returns model instance in write_post endpoint by @blackyau in #185
- Fix user create admin by @igorbenav in #188
- Add fastroai banner by @igorbenav in #189
- add analytics to mkdocs by @igorbenav in #191
- Switch from UUID v4 to v7 by @Saiyashwanth7 in #186
- Adding DeepWiki docs URL to README.md. by @carlosplanchon in #192
- Remove unused Redis SSL setting from admin init by @defp in #196
- Issue documentation improvements by @emiliano-gandini-outeda in #199
- add discord community by @igorbenav in #200
New Contributors
- @blackyau made their first contribution in #185
- @Saiyashwanth7 made their first contribution in #186
- @carlosplanchon made their first contribution in #192
- @defp made their first contribution in #196
- @emiliano-gandini-outeda made their first contribution in #199
Full Changelog: v0.14.0...v0.15.0
0.14.0
Benav Labs FastAPI boilerplate
Yet another template to speed your FastAPI development up, now with proper docs and an admin panel.
What's Changed
- warning plus import for db migrations by @igorbenav in #140
- Update ARQ Job Queues documentation and add database session by @leonardovida in #141
- Fixes default expire time in creating access token by @KennethTV in #143
- Fixes by @igorbenav in #144
- enhance test setup by @arab0v in #148
- Update Dockerfile to install additional Poetry plugin by @sujithkupen in #154
- rate limiter changed from module to class by @igorbenav in #158
- blacklist both tokens for logout by @igorbenav in #159
- fastcrud bump, dependencies fixed by @igorbenav in #160
- remove comments by @igorbenav in #161
- bug fix by @igorbenav in #163
- bugfix: syntax error by @LongDinhh in #164
- Replace hardcoded localhost with POSTGRES_SERVER env var. by @epinapala in #166
- Dynamically importing app models by @geekashu in #167
- Tied the version of Python to 3.11 to fix Greenlet compatibility by @Harry-Tom in #174
- Updated the SECRET_KEY config item to use the SecretStr class by @Harry-Tom in #173
- added unused create_tables function to lifespan_factory by @oliwertrzeciak in #172
- Update env.py by @naaive in #171
- add banner by @igorbenav in #175
- Migrate to UV, Workflows, Bump Gunicorn by @igorbenav in #176
- initial documentation by @igorbenav in #177
- Add warning to docs, fix url by @igorbenav in #178
- add CRUDAdmin for admin panel by @igorbenav in #180
New Contributors
- @leonardovida made their first contribution in #141
- @KennethTV made their first contribution in #143
- @arab0v made their first contribution in #148
- @sujithkupen made their first contribution in #154
- @LongDinhh made their first contribution in #164
- @epinapala made their first contribution in #166
- @geekashu made their first contribution in #167
- @Harry-Tom made their first contribution in #174
- @oliwertrzeciak made their first contribution in #172
- @naaive made their first contribution in #171
Full Changelog: v0.13.0...v0.14.0
📖 Documentation
📚 Visit our comprehensive documentation at benavlabs.github.io/FastAPI-boilerplate
⚠️ Documentation StatusThis 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 APIsPydantic V2: the most widely used data Python validation library, rewritten in Rust(5x-50x faster)SQLAlchemy 2.0: Python SQL toolkit and Object Relational MapperPostgreSQL: The World's Most Advanced Open Source Relational DatabaseRedis: Open source, in-memory data store used by millions as a cache, message broker and more.ARQJob queues and RPC in python with asyncio and redis.Docker ComposeWith a single command, create and start all the services from your configuration.NGINXHigh-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
0.13.0
0.13.0 Summary
🚀Features
- SQLModel version of boilerplate added 🎉
- fastcrud paginated added
🔎Bug fixes
- minor mypy and ruff fixes
- gunicorn bumped, security issue fixed
- fastcrud bumped to 0.12.0 with bug fixes
What's Changed
- README.md broken link fix by @igorbenav in #122
- Fastcrud paginated by @igorbenav in #123
- minor mypy and ruff fixes, fastcrud bumped to 0.10.0 by @igorbenav in #128
- bump fastcrud to 0.11.0 by @igorbenav in #129
- Update README.md by @igorbenav in #131
- Update README.md by @igorbenav in #133
- gunicorn bumped by @igorbenav in #134
- fastcrud bumped to 0.12.0 with bug fixes by @igorbenav in #135
- Update README.md by @igorbenav in #136
- SQLModel version link added by @igorbenav in #137
Full Changelog: v0.12.4...v0.13.0
0.12.4
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
0.12.3
🔎Bug fixes
- docs not generated bug fix #118 by @luca-medeiros
- spelling fix #115 by @rememberlenny
What's Changed
- Fix default.conf spelling by @rememberlenny in #115
- bug: fix missing router when creating application by @luca-medeiros in #118
New Contributors
- @rememberlenny made their first contribution in #115
Full Changelog: v0.12.2...v0.12.3
0.12.2
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
- Lifespan Events, Libs bumped, .env fix by @igorbenav in #114
- fastcrud bumped to 0.6.0 by @igorbenav in #116
Full Changelog: v0.11.1...v0.12.2
0.11.1
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
- upgrade python multipart, fastapi, fastcrud by @igorbenav in #112
Full Changelog: v0.11.0...v0.11.1
0.11.0
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_startparameter added in setup functionruffadded aspre-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 fashionTo 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
- Add ruff linter by @luca-medeiros in #83
- Added the comment and in the docs to change docker-compose.yml for migrations by @igorbenav in #85
- create_tables_on_start created, docs added by @igorbenav in #86
- Add PGAdmin container for PostgreSQL administration and debugging by @gmirsky in #75
- Removed deprecated typing classes and replaced with native Python dict, list, type, etc. by @eredden in #90
- add pre-commit configs by @luca-medeiros in #92
- Remove all print statements #93 by @shreyasSarve in #95
- Move worker script by @AlessioBugetti in #97
- Fix for get task endpoint bug by @igorbenav in #99
- Fix of pyproject.toml by @DmitryIo in #101
- Create CODE_OF_CONDUCT.md by @igorbenav in #102
- Update issue templates by @igorbenav in #103
- Create CONTRIBUTING.md by @igorbenav in #104
- Update CONTRIBUTING.md by @igorbenav in #105
- Create PULL_REQUEST_TEMPLATE.md by @igorbenav in #106
- Update README.md by @igorbenav in #107
- Fast crud by @igorbenav in #109
- Update README.md by @igorbenav in #110
New Contributors
- @gmirsky made their first contribution in #75
- @eredden made their first contribution in #90
- @shreyasSarve made their first contribution in #95
- @AlessioBugetti made their first contribution in #97
- @DmitryIo made their first contribution in #101
Full Changelog: v0.10.0...v0.11.0
0.10.0
0.10.0 Summary
🚀Features
datetimerefactored to be timezone aware #79 #82 (thanks @mithun2003)passlibreplaced withbcryptfor password hashing #74- pydantic
validatormoved to v2field_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.ymlandDockerfile:
Tip
If you are in a hurry, you may use one of the following templates (containing a .env, docker-compose.yml and Dockerfile):
- Running locally with uvicorn
- Runing in staging with gunicorn managing uvicorn workers
- Running in production with NGINX
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_reuseremoved #70 - pagination bug fixed #66
- mypy multiple type hint fixes
What's Changed
- Update README.md by @igorbenav in #64
- Folder structure by @igorbenav in #65
- pagination bug fixed by @igorbenav in #66
- config.py port datatype consistency by @luca-medeiros in #69
- pydantic allow_reuse removed, one less warning for tests by @igorbenav in #70
- commented non essential services in docker compose by @igorbenav in #71
- pydantic validators migrated to v2 by @igorbenav in #72
- added return type hint to rate limit validator by @igorbenav in #73
- passlib replaced with bcrypt for password hashing by @igorbenav in #74
- Update README.md by @igorbenav in #77
- Update README.md by @igorbenav in #78
- CRUDBase count method bug fix by @igorbenav in #81
- Refactor datetime.utcnow() to datetime.now(timezone.utc) by @mithun2003 in #80
- 79 datetimeutcnow is deprecated as of python 312 by @igorbenav in #82
New Contributors🎉
- @luca-medeiros made their first contribution in #69
- @mithun2003 made their first contribution in #80
Full Changelog: v0.9.0...v0.10.0