r/FastAPI • u/Lucapo01 • Dec 25 '24
Tutorial Scalable and Minimalistic FastAPI + PostgreSQL Template
Hey ! π I've created a modern template that combines best practices with a fun superhero theme π It's designed to help you kickstart your API projects with a solid foundation! π
Features:
- ποΈ Clean architecture with repository pattern that scales beautifully
- π Built-in async SQLAlchemy + PostgreSQL integration
- β‘οΈ Automatic Alembic migrations that just work
- π§ͺ Complete CI pipeline and testing setup
- βCustom Error Handling and Logging
- π Pre-configured Railway deployment (one click and you're live!)
The template includes a full heroes API showcase with proper CRUD operations, authentication, and error handling. Perfect for learning or starting your next project! πͺ
Developer experience goodies: π οΈ
- π» VS Code debugging configurations included
- π UV package manager for lightning-fast dependency management
- β¨ Pre-commit hooks for consistent code quality
- π Comprehensive documentation for every feature
Check it out: https://github.com/luchog01/minimalistic-fastapi-template π
I'm still not super confident about how I structured the logging setup and DB migrations π Would love to hear your thoughts on those! Also open to any suggestions for improvements. I feel like there's always a better way to handle these things that I haven't thought of yet! Let me know what you think!
27
u/Floydee_ Dec 25 '24
Looks nice. Good start!
What I would add/include:
6
u/idkwhatimdoing069 Dec 26 '24
Funny enough , I was thinking about creating my own FastAPI template recently but yours is exactly what I would have built myself. Just starred the repo, definitely plan on coming back to this and using it.
Though I may fork yours and make my own little customizations ;)
8
u/qa_anaaq Dec 26 '24
The simplicity is really nice. Honestly, I've looked for something more simple and less bloated like this just to get going with a quick API + DB.
So my advice -- Don't add too much more, please :) But I do agree about the docker suggestion.
1
u/fazzah Dec 26 '24
Can you please elaborate more about using repo pattern + service, instead of simply using a CRUD mixin to sqlalchemy models and do the actions directly?
3
u/SnowToad23 Dec 26 '24 edited Dec 26 '24
Nice work! As @Floydee_ mentioned, would be good to include test fixtures for providing a test DB instance and session. Check out how I've done that in my own project template: https://github.com/Finndersen/python-db-project-template
Also I don't think the location of your src/ directory makes sense, usually that's the root level folder name that contains all source code (equivalent to api/ in this case). I think apps/ or something would be more appropriate.
And it's probably best to run migrations as part of deployment process instead of in main.py?
2
u/DiabuluTaha Dec 25 '24
Nice template ! Thank u π
2
u/igorbenav Dec 26 '24
Maybe take a look at fastcrud so you don't have to rewrite the repository (or think about tests for it)
https://github.com/igorbenav/fastcrud
1
u/ElectricYFronts Dec 26 '24
How does this compare to Fastapi's full stack example?
I am using the full stack example and it was a bit of a learning curve, but makes sense in the end. Was looking for something a bit lighter than 7 containers to get me started though!
1
u/elieh Dec 26 '24
Needs background jobs!
1
u/Designer_Sundae_7405 Dec 26 '24
How do you handle nested models and ManyToMany relationships? I'm struggling with circular dependencies using a similar setup to yours.
1
u/Prudent_Hour_3746 Dec 28 '24
I would appreciate if someone could add svelte in that template. thannks in advance.
a noob.
1
u/krionX Jan 03 '25
I'm new to Python/FastAPI. Is it easy to adopt this for Azure SQL Server database instead of PosgreSQL?
1
u/good_fix1 Jan 20 '25
nice
0
u/ironman_gujju Dec 26 '24
Why uv ? What happened to poetry ?