r/FastAPI • • Apr 23 '25

Question Why is there no T3 (https://create.t3.gg/) for FastAPI? (Or have I just missed it)

47 Upvotes

I love FastAPI — it's my go-to Python API framework. However, every time I start a new project, there's a fair bit of boilerplate to deal with: project structure and scaffolding, tests, long-running tasks (Celery, Airflow, etc.), databases, migrations (Alembic, etc.), logging, exception handling, observability, payments, auth, deployment, CI/CD — the list goes on depending on the project.

There are a lot of boilerplate projects out there. Personally, my go-to has been the Netflix Dispatch repo, and I recently came across a great formalization of it: fastapi-best-practices.

I get that FastAPI is intentionally unopinionated — and I love that. But sometimes I just want to say “I need X, Y, and Z” and generate a project where all the boilerplate is already wired up. Like a T3-style experience, but for FastAPI.

I’m tempted to build something myself and open-source it — just wanted to check I’m not missing an existing solution or a reason why no one would find this useful.


r/FastAPI • • Jan 26 '25

Question Pydantic Makes Applications 2X Slower

47 Upvotes

So I was bench marking a endpoint and found out that pydantic makes application 2X slower.
Requests/sec served ~500 with pydantic
Requests/sec server ~1000 without pydantic.

This difference is huge. Is there any way to make it at performant?

@router.get("/")
async def bench(db: Annotated[AsyncSession, Depends(get_db)]):
    users = (await db.execute(
        select(User)
        .options(noload(User.profile))
        .options(noload(User.company))
    )).scalars().all()
    
    # Without pydantic - Requests/sec: ~1000
    # ayushsachan@fedora:~$ wrk -t12 -c400 -d30s --latency http://localhost:8000/api/v1/bench/
    # Running 30s test @ http://localhost:8000/api/v1/bench/
    #   12 threads and 400 connections
    #   Thread Stats   Avg      Stdev     Max   +/- Stdev
    #     Latency   402.76ms  241.49ms   1.94s    69.51%
    #     Req/Sec    84.42     32.36   232.00     64.86%
    #   Latency Distribution
    #      50%  368.45ms
    #      75%  573.69ms
    #      90%  693.01ms
    #      99%    1.14s 
    #   29966 requests in 30.04s, 749.82MB read
    #   Socket errors: connect 0, read 0, write 0, timeout 8
    # Requests/sec:    997.68
    # Transfer/sec:     24.96MB

    x = [{
        "id": user.id,
        "email": user.email,
        "password": user.hashed_password,
        "created": user.created_at,
        "updated": user.updated_at,
        "provider": user.provider,
        "email_verified": user.email_verified,
        "onboarding": user.onboarding_done
    } for user in users]
    
    # With pydanitc - Requests/sec: ~500
    # ayushsachan@fedora:~$ wrk -t12 -c400 -d30s --latency http://localhost:8000/api/v1/bench/
    # Running 30s test @ http://localhost:8000/api/v1/bench/
    #   12 threads and 400 connections
    #   Thread Stats   Avg      Stdev     Max   +/- Stdev
    #     Latency   756.33ms  406.83ms   2.00s    55.43%
    #     Req/Sec    41.24     21.87   131.00     75.04%
    #   Latency Distribution
    #      50%  750.68ms
    #      75%    1.07s 
    #      90%    1.30s 
    #      99%    1.75s 
    #   14464 requests in 30.06s, 188.98MB read
    #   Socket errors: connect 0, read 0, write 0, timeout 442
    # Requests/sec:    481.13
    # Transfer/sec:      6.29MB

    x = [UserDTO.model_validate(user) for user in users]
    return x

r/FastAPI • • May 18 '26

Question Coming from ExpressJS, I love FastAPI but... do we really need two sets of models?

46 Upvotes

Coming from ExpressJS, I’ve been loving how fast and easy FastAPI is. In my Node ecosystem, I usually use Prisma with PostgreSQL, which means I don't strictly need separate models for data i/o. While I can define validation schemas (like Zod) if needed, it’s not forced on a model-by-model basis. If it's a non-mission-critical project and I know what's in the payload, I can skip validation entirely.

But in FastAPI, it feels like I'm forced to maintain two separate models: a Pydantic model for request/response validation, and a SQLAlchemy model for the database.

Does it always have to be this way? Can it just be a single model, and what is the actual industry standard here?


r/FastAPI • • Oct 03 '25

Tutorial Bigger Applications - Multiple Files Lesson

46 Upvotes

I just shipped something big on FastAPI Interactive – support for multi-file hands-on lessons!

Why this matters:

  • You’re no longer stuck with a single file → now you can work in real project structures.

  • This opens a way for full-fledged tutorials of various difficulties (beginner → advanced).

  • First example is the new 34th lesson, covering “Bigger Applications” from the official FastAPI docs, but in a practical, hands-on way.

You can now explore projects with a file explorer + code editor right in the browser. This is the direction I’m heading: advanced, project-based tutorials that feel closer to real-world work.

Would love feedback if you give it a try!


r/FastAPI • • Oct 19 '24

Other Share your FastAPI Projects!

46 Upvotes

Hey guys!

Recently I did a post asking about projects best practices and there was a few people sharing their own projects and I thought that was really nice! I really enjoy and also benefit from seeing other people projects ideas, code style, project file structure, etc.

So I thought about making this post so you can share you projects and maybe even get some feedback (if you're open to it).

Unfortunately I'm really new to FastAPI and still on the studying phase, but hope to share something with you guys soon!


r/FastAPI • • Sep 04 '25

Other Would you settle for FastAPI or Django in the long run?

45 Upvotes

Would you settle for FastAPI or Django in the long run as per a single framework for all your task or would django be it the one ?

What are your views because django(betteries included) has its own benifits and fastapi(simplicity) as its own and also some packages that give fastapi some batteries already that’s already being used in industry.

What are your thoughts on choosing one over other and will you settle down for one?


r/FastAPI • • Apr 09 '25

Tutorial NVIDIA Drops a Game-Changer: Native Python Support Hits CUDA

Thumbnail
frontbackgeek.com
45 Upvotes

r/FastAPI • • Dec 10 '25

pip package Built a "batteries included" FastAPI starter - auth, jobs, webhooks in one function call

Thumbnail nfrax.com
44 Upvotes

I've rewritten the same FastAPI boilerplate probably 10+ times across different projects. Auth setup, background jobs, webhook handling, caching... it's always the same stuff.

Finally extracted it all into a package. Here's what it looks like now:

from svc_infra.api.fastapi.ease import easy_service_app
from svc_infra.api.fastapi.auth.add import add_auth_users
from svc_infra.jobs.easy import easy_jobs

app = easy_service_app(name="MyAPI", release="1.0.0")
add_auth_users(app)  # boom, full auth
queue, scheduler = easy_jobs()  # background jobs done

That one add_auth_users() call gives you:

  • JWT + sessions

  • OAuth (Google, GitHub, etc.)

  • MFA/TOTP

  • API keys

  • Password policies, account lockout, the works

The jobs thing uses Redis under the hood, has retries with backoff, dead letter queue, scheduler for cron stuff.

Also has webhooks (HMAC signing, delivery retries), caching decorators, rate limiting, Prometheus metrics... basically everything I kept copy-pasting between projects.

The catch: It's opinionated. Assumes PostgreSQL, Redis, certain patterns. But everything's overridable if you need different defaults.

Documentation and integration: https://www.nfrax.com/ GitHub: https://github.com/nfraxlab/svc-infra

We also built companion packages for AI stuff (agents, RAG) and fintech (Plaid/Teller) if anyone's into that.

MIT licensed. Curious what patterns other FastAPI devs keep rewriting.


r/FastAPI • • Aug 25 '25

Question 💡 Best auth system for React + FastAPI? BetterAuth or something else?

44 Upvotes

Hey everyone,

I’m working on a personal project with React on the frontend and a small FastAPI backend that already handles my frontend and has a basic role system (admin, user, etc.).

Now I’m wondering about authentication:
👉 What would you recommend as a secure, reliable, and easy-to-maintain solution?
I’ve been looking at BetterAuth, which looks modern and promising, but I’m not sure if it’s the best fit with FastAPI, or if I should go with something else (OAuth2, JWT, Auth0, etc.).

My goal is to have a setup where I can feel confident about security and functionality (persistent sessions, role management, smooth integration with the frontend).

I’d love to hear your experiences and advice! 🙏


r/FastAPI • • Aug 11 '25

Question Example Production Grade Project?

44 Upvotes

I'm looking for production grade FastAPI project that uses sqlalchemy, pydantic models, alembic for db migratio, session or token based RBAC, to learn to build a robust backend, can you please suggest one?
I'm aware there are https://github.com/fastapi/full-stack-fastapi-template and zhanymkanov/fastapi-best-practices: FastAPI Best Practices and Conventions we used at our startup, but I'm not looking for a template but a mature and complete implementation.

Thank you so much.


r/FastAPI • • Dec 19 '25

feedback request Helix – Dynamic API mocking built with FastAPI, Starlette Middleware, and Redis. Features Chaos Engineering and strict schema validation.

43 Upvotes

Hi r/fastapi!

I wanted to share an open-source tool I've been building with FastAPI: Helix. It's a dynamic API mocking server that generates realistic data on the fly using LLMs (Ollama, DeepSeek, etc.).

Why I built it: I often find myself blocked on the frontend while waiting for the backend implementation. Static JSON mocks are tedious to maintain, so I wanted something dynamic but reliable.

The FastAPI Stack:

  • Core: FastAPI handles dynamic routing for undefined endpoints.

  • Middleware: I rely heavily on Starlette middleware for "Chaos Engineering" (simulating latency/errors) and request logging.

  • Async/Await: Critical for handling AI inference without blocking the main event loop.

  • Schema Enforcement: Since we all love Pydantic/Types here, I implemented a "Strict Mode" where the AI output is forced to match a specific JSON Schema or TypeScript interface. This ensures type safety even with LLM generation.

Key Features:

  • Zero-config setup (Docker).

  • Works 100% offline with Ollama (Llama 3.2).

  • Strict Schema Enforcement (no random AI hallucinations breaking the frontend).

  • Chaos Mode (inject random 500s or delays).

It's fully open source (AGPLv3). I'd love to hear your feedback on the architecture or features!

Repo: https://github.com/ashfromsky/helix


r/FastAPI • • Jul 06 '24

Question I'm a Python Backend Developer, How to Create a Modern and Fast Frontend?

43 Upvotes

Hi everyone,

I'm a backend developer working with Python and I'm looking for a simple and quick way to create a modern and clean frontend (web app) for my Python APIs.

I've been learning Next.js, but I find it a bit difficult and perhaps overkill for what I need.

Are there any tools or platforms for creating simple and modern web apps?
Has anyone else been in the same situation? How did you resolve it?
Do you know of any resources or websites for designing Next.js components without having to build them from scratch?

Thanks in advance for your opinions and recommendations!


r/FastAPI • • Dec 23 '23

feedback request Gymhero - FastAPI Project Example

43 Upvotes

Hello guys,

A couple of weeks ago, I got the itch to build something with FastAPI. As I am a Data Engineer I didn't have a ton of experience with API development - In the past, I only developed the "reading" part of API to expose some database tables, KPIs, etc. But I've always wanted to give it a try to build a full CRUD app. So I thought that it would be a fun project to learn the basics of building a backend app with full CRUD functionality.

I was originally planning on using Flask, but when I saw FastAPI and all its nifty features, like typing hints, Pydantic, and Depends, I knew I had to give it a go. Turns out, it was a great decision. FastAPI is a really powerful framework, and it's a joy to work with, I highly recommend using it. It's a great choice and it has great documentation and the developer experience is awesome.

Here is GitHub with the project: https://github.com/JakubPluta/gymhero

My project is pretty simple and it's still in development - probably there are some mistakes and some "better ways" to do something, but still, I am happy that I managed to write it from scratch. I just only regret I didn't start with async, so it will be harder to migrate it, but I have it in plans :)

To give a short description of my project there are a couple of words:Gymhero is a simple application to manage your gym training workouts. You have the flexibility to create your own exercises, you can develop custom training units and these units can be easily integrated into personalized training plans. You can manage your training units by adding or removing exercises as needed. By default application contains database od more than 1000 exercises.

Core technologies

  • FastAPI - web framework for building APIs with Python 3.8+ based on standard Python type hints.

  • SQLAlchemy - Object Relational Mapper

  • Pydantic - Data validation library for Python and FastAPI models

  • Uvicorn - ASGI web server implementation for Python

  • Alembic - lightweight database migration tool for usage with the SQLAlchemy Database Toolkit for Python.

  • Docker - tool to package and run an application in a loosely isolated environment

  • Docker Compose - tool for defining and running multi-container Docker applications

  • Postgres - open source object-relational database

  • For testing:

    • pytest

    • pytest-cov

    • pytest-mock

  • For development

    • precommit-hook

    • pylint

    • black

    • ruff

    • poetry

    • venv

Some implemented functionalities:

  • JWT Authentication

  • Password Hashing

  • Login & Register Endpoints

  • ORM Objects representing SQL tables and relationships

  • Pydantic schemas

  • CRUD module for reading, updating, and deleting objects in/from the database

  • Pagination

  • Dependencies - superuser, active user, database

  • Initialization scripts

  • Separate database and env for testing

You can find more in Readme https://github.com/JakubPluta/gymhero/blob/main/README.md

To run the project locally in docker container simply clone the repository, navigate to cloned directory, and run the: make dev or make install command, or if you don't have make installed just use docker commands

docker compose build
docker compose up -d 
docker exec -it app alembic upgrade head
docker exec -it app python -m scripts.initdb --env=dev

For more details just go through the README file.I would love to get some opinions from you, especially from experienced FastAPI users :). Please let me know what should I improve, what I did wrong, and what could be done in a better way.


r/FastAPI • • Feb 05 '22

Other FastAPI #1 on the Top 100 Developer Tools

Thumbnail
stackshare.io
43 Upvotes

r/FastAPI • • Jul 13 '20

Other FastAPI is everything I ever wanted from Python and more.

43 Upvotes

FastAPI is everything I ever wanted from a Python web framework. The overhead of Go is too high for me for personal projects. JavaScript gets too expressive and spaghetti-like over time. Python is the language that I want but I've felt limited by Flask and Django. Django is too bulky and cumbersome, and Flask hasn't really improved in 7 or 8 years to keep up with high performance web apps (which is totally fine - just not for me).
FastAPI has everything that I've wanted. How can something so lightweight have so many useful features? 10/10, will be teaching my coworkers about this in a lunch and learn.


r/FastAPI • • Mar 06 '26

Question Fastapi and database injections

42 Upvotes

I haven't been active in Python for a few years and I mainly come from a Django background. I'm trying to understand why Fastapi best practices seems to be to inject the database into the api calls so you have all the database procedures in the api code. This is the kind of thing I would normally put in a service because if the database logic starts getting hairy, I'd rather have that abstracted away. I know I can pass the database session to a service to do the hairy work, but why? To my thinking the api doesn't need to know there is a database, it shouldn't care how the item is created/read/updated/deleted.

Is this just how fastapi apps are supposed to be organized or am I just not digging deep enough? Does anyone have a link to an example repo or blog that organizes things differently?


r/FastAPI • • Jan 05 '26

Tutorial techniques to make your fastapi backend super fast

42 Upvotes

hey guys, i've compiled some of the most important learnings i've gained up to this point about building a better and faster backend service into an article.

please review it and provide feedback. also, suggest any techniques i have missed, and you've found interesting.x

https://blog.coffeeinc.in/why-your-backend-is-slow-and-what-to-do-about-it-d008d7ae9566


r/FastAPI • • Nov 18 '25

Tutorial Async vs Sync in FastAPI + SQLAlchemy: Which Should You Use?

Thumbnail
youtube.com
42 Upvotes

In this video, we benchmark Sync vs Async in FastAPI + SQLAlchemy to see which approach actually performs better. We walk through real results and break down when each method makes sense in real-world apps.


r/FastAPI • • Oct 11 '25

pip package [UPDATE] AuthTuna: My production-ready FastAPI security framework now has comprehensive DOCUMENTATION and better examples!

42 Upvotes

Hey everyone,

A month ago, I posted about AuthTuna, my production-ready, async security framework for FastAPI. I had some great feedback and realized i did not have sufficient docs for the RBAC system and other things.

I'm happy to announce that AuthTuna now has a complete, official documentation site! (still dosent document everything but does things to a level, like those are the high level things and recommended to use those, others i still dont recommend so havent documented those yet will do in future)

I've put in a lot of work to make it easy to understand while still being a solid reference for advanced users.

I am still working on enhancing its features and usability and ease of use.

I plan on implementing Organizations and teams features and make usage even simpler than directly managing permissions and roles. allowing for Organization("Org name") and other things basically feature enhancement.

I is still under development but there will not be any breaking changes (atm) and you can always lock to current version on pip or have latest version by the git repo.

After i release v1.0.0 (planned to release by jan) it will be fully stable (currently also stable) i.e no high frequency updates like rn and a guarantee of no highly breaking changes between minor version changes (i.e v1.x.x) (if v2.x.x comes it will not be before mid 2027, if i have highly breaking changes then only move to v2)

You can check out the documentation at: http://authtuna.shashstorm.in/

You can also look at my deployed version at: https://auth.shashstorm.in/

It is being used at: https://weaver.shashstorm.in/


r/FastAPI • • Sep 10 '25

feedback request My minimalist full-stack template: FastAPI + React

42 Upvotes

Since one year, I was mastering my frontend skills, and as a result I developed my full-stack template inspired by official fastapi template but with some adjustments.

Backend: FastAPI, SQLAlchemy, Pydantic

Frontend: React, Material UI, Nginx

I have tested this template across my three commercial projects, as for now, it works well.

Online demo is available (see link in the repo below, http is not allowed on Reddit I guess).

In READMEs, I provide instructions, sources and some learning materials.

The template itself: https://github.com/konverner/full-stack-template

Feel free to ask questions or propose improvements.


r/FastAPI • • Jul 11 '25

pip package FastAPI with SQLite connection pool for high-performance

42 Upvotes

If you use SQLite with (FastAPI, background jobs, etc.), you might notice performance drops when your app gets busy.

Opening and closing connections for every query is fast, but not free and SQLite’s concurrency model allows only one writer.

I built aiosqlitepool to help with this. It’s a small, MIT-licensed library that:

  • Pools and reuses connections (avoiding open/close overhead)

  • Keeps SQLite’s in-memory cache “hot” for faster queries

  • Allows your application to process significantly more database queries per second under heavy load

Officially released in PyPI.

Enjoy! :))


r/FastAPI • • Jan 29 '25

Tutorial Resources to become an expert at writing APIs

42 Upvotes

Hi guys, I want to learn how to design and write APIs and I’m prepared to spend as long as it takes to become an expert (I’m currently clueless on how to write them)

So please point me to resources that have helped you or you recommend so I can learn and get better at it.


r/FastAPI • • Mar 19 '23

Tutorial FastAPI with async SQLAlchemy 2.0 (and alembic migrations too)

42 Upvotes

I've just published a new blog post showing how to use FastAPI and the new async functionalities of SQLAlchemy 2.0:

https://praciano.com.br/fastapi-and-async-sqlalchemy-20-with-pytest-done-right.html

Hope the community enjoys it! I'm also open for any feedback.


r/FastAPI • • Mar 29 '26

Question Am I missing something

41 Upvotes

I see a ton of people in this sub asking like, where they can find good examples, boilerplate or simply documentation around fastapi.

I keep feeling like Im missing something. I always tought of Fastapi as this really thin layer letting my expose my code as a web api.

Truly, how much is there to know beyond maybe 3/4 concepts that are pretty simple and generic anyway.

Setting up the app itself is something you do once and it takes 2 minutes, and pretty much everything else is so simple and intuitive you almost forget that it's there. Most of the code I write in my backend has no link whatsoever with Fastapi