r/FastAPI • • Jul 07 '25

Question Elastic search to implement advanced Search filtering in FastAPI using enhanced query parameters

Post image
28 Upvotes

Hi guys, previous post I did, I received feedback on how to implement filtering sorting and pagination in FastAPI, I actually did implement it by myself using my own query builder and using repository pattern. I got something like this image. Now I would like to implement searching, any ideas?


r/FastAPI • • Sep 01 '24

Question Backend Dev Needs the Quickest & Easiest Frontend Tool! Any Ideas?

28 Upvotes

Hey, I’m a backend developer using Python (FastAPI) and need a fast, easy-to-learn tool to create a frontend for my API. Ideally, something AI-driven or drag-and-drop would be awesome.

Looking to build simple frontends with a login, dashboard, and basic stats. What would you recommend?


r/FastAPI • • Jul 30 '24

Question What are the most helpful tools you use for development?

28 Upvotes

I'm curious what makes your life as a developer much easier and you don't imagine the development process of API without those tools? What parts of the process they enhance?

It may be tools for other technologies from your stack as well, or IDE extension etc. It may be even something obvious for you, but what others may find very functional.

For example, I saw that Redis have desktop GUI, which I don't even know existed. Or perhaps you can't imagine your life without Postman or Warp terminal etc.


r/FastAPI • • Mar 03 '24

Question How to structure FastAPI app so logic is outside routes

28 Upvotes

I've been looking at a variety of FastAPI templates for project structure and notice most of them don't address the question of where the "business logic" code should go. Should business logic just live in the routes? That seems like bad practice (for example in Nest.js it's actively discouraged). How do you all organize your business logic?


r/FastAPI • • Feb 08 '24

Hosting and deployment free fastapi hosting

28 Upvotes

previously I used Heroku for fastapi hosting. but now there is no free tier anymore in Heroku. Does anyone know where I can host Fastapi for free like on Heroku again?


r/FastAPI • • Dec 05 '23

feedback request It's Christmas day. You wake up, run to the tree, tear open the largest package with your name on it... FastAPI has added _____?

28 Upvotes

title


r/FastAPI • • Nov 17 '22

Other MonoBox: a lightweight music player that can stream songs from your computer's local library to your phone's app

28 Upvotes

Hello FastAPI community!

First time here so please be nice 😊

I would like to present to you my latest project, which I have been working on for the past few months, and I would be happy if it gets some exposure.

So Introducing MonoBox: a music player that can stream songs from your computer's local library to your phone's app. 🎡

This is a full-stack application, which I built by combining React Native with FastAPI.

You are invited to read all about MonoBox and form your own opinions, and of course don't forget to star the repo! ⭐

Check out the MonoBox repo!


r/FastAPI • • Apr 04 '26

Question Trying to implement PATCH in FastAPI and Claude told me to use two separate Pydantic models β€” is this actually the way?

27 Upvotes

I'm learning FastAPI and trying to add a PATCH endpoint. Asked Claude about it and it told me to create a second model called `BookUpdate` where every field is Optional, separate from my main `Book` model where everything is required.

Is this really how you guys do it in practice? Feels like a lot of boilerplate just for one endpoint. What's the proper way to handle partial updates in FastAPI?


r/FastAPI • • Mar 28 '26

Other Define your model β†’ get a full SaaS app instantly (FastAPI + React)

27 Upvotes

Every time I start a new project, I end up rewriting the same things:

- authentication

- CRUD endpoints

- pagination & search

- permissions

- frontend API calls

It gets repetitive fast.

So I started building something to fix that β€” FastForge.

It’s a full-stack framework built on FastAPI (+ optional React) where:

β†’ You define your SQLAlchemy model

β†’ Run a command

β†’ Get a complete API + typed frontend client

No boilerplate. No repeating the same setup every time.

Some things it handles out of the box:

- JWT auth + role-based permissions

- multi-tenancy

- audit logging + soft delete

- CRUD with pagination, search, filters

- OpenAPI β†’ TypeScript client generation

- background jobs + event system

Still early, but the goal is simple:

> stop writing the same backend code again and again

Would really appreciate feedback from other devs πŸ™Œ

Repo: https://github.com/Datacrata/fastforge


r/FastAPI • • Jan 31 '26

Question Looking for people learning Python backend (FastAPI) –

27 Upvotes

I’m currently learning Python backend development and focusing on FastAPI.

So far I’ve been working through things like API design, async concepts, authentication, database integration, and general backend structure. Still early in the journey, still figuring out best practices, and still building small projects to understand how everything fits together.

I wanted to hear from people who’ve already gone down this path or are currently on it


r/FastAPI • • Jan 24 '26

feedback request Another modern FastApi template

27 Upvotes

https://github.com/p0llopez/fastapi-template It's my first open template, I use it in my company in a variety of projects. Maybe you find usefult. Feel free to comment, ask questions, or share ideas. Keep in mind it’s my first time using GitHub Actions and Renovate, so there might be some mess and inconsistencies in there. A bit of vibe code too


r/FastAPI • • Dec 30 '25

feedback request Your backend system, in few lines not thousands

27 Upvotes

I’ve been working on enhancing developer experience when building SAAS products. One thing I personally always hated was setting up the basics before digging into the actual problem I was trying to solve for.

Before I could touch the actual product idea, I’d be wiring auth, config, migrations, caching, background jobs, webhooks, and all the other stuff you know you’ll need eventually. Even using good libraries, it felt like a lot of glue code, learning curve and repeated decisions every single time.

At some point I decided to just do this once, cleanly, and reuse it. svc-infra is an open-source Python backend foundation that gives you a solid starting point for a SaaS backend without locking you into something rigid. Few lines of code rather hundreds or thousands. Fully flexible and customizable for your use-case, works with your existing infrustructure. It doesn’t try to reinvent anything, it leans on existing, battle-tested libraries and focuses on wiring them together in a way that’s sane and production-oriented by default.

I’ve been building and testing it for about 6 months, and I’ve just released v1. It’s meant to be something you can actually integrate into a real project, not a demo or starter repo you throw away after a week.

Right now it covers things like:

  • sensible backend structure

  • auth-ready API setup

  • caching integration

  • env/config handling

  • room to customize without fighting the framework

It’s fully open source and part of a small suite of related SDKs I’m working on.

I’m mainly posting this to get feedback from other Python devs what feels useful, what feels unnecessary, and what would make this easier to adopt in real projects.

Links:

Happy to answer questions or take contributions.


r/FastAPI • • Dec 24 '25

Question Is Anyone Else Using FastAPI with AI Agents

27 Upvotes

Hey r/FastAPI community!

With AI agents, assistants, and autonomous workflows becoming the next big thing, I wanted to see how many of you are leveraging FastAPI to serve or integrate with them.I recently built a system where FastAPI acts as the central orchestrator for multiple AI agents (LLM-powered workflows, RAG pipelines, and task-specific autonomous tools). The async capabilities of FastAPI make it incredibly smooth to handle concurrent requests to multiple AI services, webhooks from agent actions, and real-time WebSocket updatesβ€”all without breaking a sweat. I feel like FastAPI’s async-first design, Pydantic integration (for structuring agent inputs/outputs), and automatic OpenAPI docs are almostΒ tailor-madeΒ for AI agent architectures.

If you’re working on something similar:

  • What’s your use case?

  • Any packages or patterns you’re combining with FastAPI (LangChain, LlamaIndex, custom asyncio loops)?

  • Have you run into pitfalls (e.g., long-running agent tasks, WebSocket timeouts)?


r/FastAPI • • Sep 27 '25

Question FastAPI project structure advice needed

27 Upvotes

I'm building an e-commerce platform with FastAPI (products, orders, payments, auth) and trying to decide on project structure. Team of 2-3 people.

Option 1: Detailed Modular (my preference)

ecommerce/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ main.py
β”‚   β”œβ”€β”€ config.py
β”‚   β”œβ”€β”€ database.py
β”‚   β”œβ”€β”€ auth/
β”‚   β”‚   β”œβ”€β”€ models.py
β”‚   β”‚   β”œβ”€β”€ schemas.py
β”‚   β”‚   β”œβ”€β”€ routes.py
β”‚   β”‚   β”œβ”€β”€ services.py
β”‚   β”‚   └── utils.py
β”‚   β”œβ”€β”€ products/
β”‚   β”‚   β”œβ”€β”€ models.py
β”‚   β”‚   β”œβ”€β”€ schemas.py
β”‚   β”‚   β”œβ”€β”€ routes.py
β”‚   β”‚   └── services.py
β”‚   β”œβ”€β”€ orders/
β”‚   β”‚   β”œβ”€β”€ models.py
β”‚   β”‚   β”œβ”€β”€ schemas.py
β”‚   β”‚   β”œβ”€β”€ routes.py
β”‚   β”‚   └── services.py
β”‚   └── shared/
β”‚       β”œβ”€β”€ dependencies.py
β”‚       └── exceptions.py

I love this because each feature is completely self-contained and logical. When working on orders, everything I need is in the orders folder. Easy for team collaboration and future microservices.

Option 2:

e-com/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ main.py                 # FastAPI app initialization
β”‚   β”œβ”€β”€ config.py               # Settings/environment config
β”‚   β”œβ”€β”€ database.py             # Database connection
β”‚   β”œβ”€β”€ dependencies.py         # Shared dependencies
β”‚   β”‚
β”‚   β”œβ”€β”€ core/
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ auth.py            # Authentication logic
β”‚   β”‚   β”œβ”€β”€ security.py        # Password hashing, JWT
β”‚   β”‚   └── exceptions.py      # Custom exceptions
β”‚   β”‚
β”‚   β”œβ”€β”€ models/
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ user.py           # User, Provider models
β”‚   β”‚   β”œβ”€β”€ service.py        # Service categories, listings
β”‚   β”‚   β”œβ”€β”€ booking.py        # Booking, availability
β”‚   β”‚   └── payment.py        # Payment records
β”‚   β”‚
β”‚   β”œβ”€β”€ schemas/
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ user.py           # Pydantic schemas
β”‚   β”‚   β”œβ”€β”€ service.py
β”‚   β”‚   β”œβ”€β”€ booking.py
β”‚   β”‚   └── payment.py
β”‚   β”‚
β”‚   β”œβ”€β”€ api/
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ deps.py           # API dependencies
β”‚   β”‚   └── v1/
β”‚   β”‚       β”œβ”€β”€ __init__.py
β”‚   β”‚       β”œβ”€β”€ router.py     # Main API router
β”‚   β”‚       β”œβ”€β”€ auth.py       # Auth endpoints
β”‚   β”‚       β”œβ”€β”€ users.py      # User management
β”‚   β”‚       β”œβ”€β”€ providers.py  # Provider endpoints
β”‚   β”‚       β”œβ”€β”€ services.py   # Service listings
β”‚   β”‚       β”œβ”€β”€ bookings.py   # Booking management
β”‚   β”‚       └── payments.py   # Payment processing
β”‚   β”‚
β”‚   β”œβ”€β”€ crud/
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ base.py          # Base CRUD operations
β”‚   β”‚   β”œβ”€β”€ user.py          # User CRUD
β”‚   β”‚   β”œβ”€β”€ service.py       # Service CRUD
β”‚   β”‚   └── booking.py       # Booking CRUD
β”‚   β”‚
β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ email_service.py  # Email notifications
β”‚   β”‚   β”œβ”€β”€ payment_service.py # Stripe integration
β”‚   β”‚   β”œβ”€β”€ booking_service.py # Business logic
β”‚   β”‚   └── notification_service.py
β”‚   β”‚
β”‚   └── utils/
β”‚       β”œβ”€β”€ __init__.py
β”‚       β”œβ”€β”€ helpers.py
β”‚       └── validators.py
β”‚
β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ conftest.py
β”‚   └── test_api/
β”‚       β”œβ”€β”€ test_auth.py
β”‚       β”œβ”€β”€ test_bookings.py
β”‚       └── test_services.py
β”‚
β”œβ”€β”€ alembic/                 # Database migrations
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ docker-compose.yml
└── .env

I saw this structure in online blogs and it seems more common.

My questions:

  • Which structure is actually recommended by the FastAPI community for production apps?

  • How do you handle cross-module imports (User model needed in orders, products)?

  • What do most successful FastAPI projects use in practice?

I prefer the modular approach because it's more organized and scalable, but want to make sure I'm following best practices.

What's the most common/recommended approach for FastAPI projects like this?


r/FastAPI • • May 30 '25

feedback request [Show Reddit] I built EduPulse - A Modern Learning Platform (Next.js + FastAPI)

27 Upvotes

Hey Reddit! πŸ‘‹

I'm excited to share my latest project: EduPulse, a modern learning platform I built to help connect students and teachers. Think of it like Udemy, but with a focus on simplicity and user experience.

Note: For now, just adding a youtube video would work

πŸ” What is it?

EduPulse is a full-stack web application where:

  • Teachers can create and manage courses

  • Students can learn at their own pace

  • Admins can keep everything running smoothly

πŸ› οΈ Tech Stack:

  • Frontend: Next.js 14 with TypeScript

  • Backend: FastAPI (Python)

  • Database: PostgreSQL

  • Styling: Bootstrap 4

✨ Cool Features:

  • Easy course creation and management

  • Student progress tracking

  • Course reviews and ratings

  • Shopping cart for course purchases

  • User-friendly dashboard for students

  • Admin panel for platform management

Why I Built This:

I wanted to learn FastAPI more deeply with SQLAlchemy.

πŸ”— GitHub: https://github.com/manjurulhoque/edu-pulse

I'm open to feedback and suggestions! What do you think?


r/FastAPI • • Apr 29 '25

Hosting and deployment Boilerplate to deploy on AWS API Gateway REST + Lambda (Terraform)

27 Upvotes

Hello,

repo : https://github.com/RemyNtshaykolo/fastawsrestapi

I created a boilerplate to deploy your FastAPI application on AWS API Gateway REST API (not HTTP API).

I chose REST API because it allows easy deployment directly from an OpenAPI schema.

The main features are:

  • Lambda docker image build + push on ECR scripts

  • Use uv for dependencies management <3

  • Supports OAuth2 authorization (automatically creates a Cognito User Pool). API Gateway’s native caching feature is enabled on the authorization endpoints to minimize calls to Cognito and protect your application from the recent pricing changes on authentication requests.

  • Supports API Key authorization (usage plans and stages are fully managed).

  • Fine-grained control of caching, throttling, and burst settings directly at the route level, using openapi_extra in your FastAPI endpoints.

The boilerplate automatically injects these settings into the generated OpenAPI schema so that API Gateway REST API can apply them correctly.

Example:

@auth_router.post(
    "/token",
    openapi_extra={
        "x-conf": {
            "caching": {
                "enabled": True,
                "maxTtl": 3600,
                "keys": {"headers": ["Authorization"], "query": ["scope"]},
            }
        }
    },
)

@demo_router.get(
    "/throttled",
    openapi_extra={
        "x-conf": {
            "throttling": {"rateLimit": 0.1, "burstLimit": 1},
        }
    },
)

This allows you to define per-route caching, rate limiting, and bursting strategies directly in your code, without modifying the infrastructure manually.

  • All routes share the same Lambda by default, but you can assign a specific Lambda with more memory if needed (for example, for AI inference).

  • Create and deploy a new version of your API with a single command.

  • Supports API multi-versioning: deploy and maintain APIs like api.yourdomain.com/v1/users and api.yourdomain.com/v2/users independently.

  • Supports deployment across multiple AWS accounts easily (using simple environment configurations).

  • Terraform configuration also deploys a static S3 website hosting the OpenAPI documentation, fully interactive and CORS-compliant (you can test all endpoints directly from the docs).

  • The repository is fully documented, and a set of Makefile commands is provided to make deployments and operations very simple.

I’m planning to make a short YouTube video explaining how to use the boilerplate step-by-step.

Anybody interested ? :)

Feel free to dm or comment if you want more info


r/FastAPI • • Apr 08 '25

feedback request Please provide feedback for my FastAPI project

27 Upvotes

Hello Everyone!

I am a frontend developer now investing time and effort learning FastAPI for Backend Development. I am going through some projects from the roadmap.sh specifically I did the URL Shortening Service.

Here it is: Fast URL Shortner

Can you please give me feedback on:

  • Project Architecture & Structure

  • Clean Code

  • Feedback on the repository pattern implementation.

  • Any other feedback? What to focus on or anything to improve?

Honorable mentions: project setup based on FastAPI-Boilerplate

Thank you in advance


r/FastAPI • • Feb 23 '25

Question try catch everytime is needed?

27 Upvotes

I'm new to this.

I use fastapi and sqlalchemy, and I have a quick question. Everytime I get data from sqlalchemy, for example:

User.query.get(23)

I use those a lot, in every router, etc. do I have to use try catch all the time, like this?:

try:
    User.query.get(23)
catch:
    ....

Code does not look as clean, so I don't know. I have read that there is way to catch every exception of the app, is that the way to do it?.

In fastapi documentation I don't see the try catch.


r/FastAPI • • Dec 18 '24

feedback request I eventually found a way to run unit tests very simply in FastAPI.

27 Upvotes

After struggling with my unit tests architecture, I ended up with a way that seems very simple and efficient to me. Instead of using FastAPI-level dependency overriding, I simply ensure that pytest always run with overrided env vars. In my conftest.py file, I have one fixture to set the test db up, and one fixture for a test itself.

Here is the (partial) code below. Please tell me if you think this sucks and I'm missing something.

conftest.py

@pytest.fixture(autouse=True, scope="session")
def setup_test_database():
    """Prepare the test database before running tests for the whole session."""

    db = settings.POSTGRES_DB
    user = settings.POSTGRES_USER
    password = settings.POSTGRES_PASSWORD
    with admin_engine.connect() as connection:
        terminate_active_connections(connection, db=db)
        drop_database_if_it_exists(connection, db=db)
        drop_role_if_it_exists(connection, user=user)
        create_database_user(connection, user=user, password=password)
        create_database_with_owner(connection, db=db, user=user)

    yield  # Run all tests


@pytest.fixture(autouse=True, scope="function")
def reset_database():
    """
    Drop all tables and recreate them before each test.
    NOTE: this is not performant, as all test functions will run this.
    However, this will prevent from any leakage between test.
    """
    # Drop and recreate tables
    Base.metadata.drop_all(engine)
    Base.metadata.create_all(engine)

    # Run the test
    yield

pyproject.toml

[tool.pytest.ini_options]
# Overrides local settings for tests. Be careful, you could break current env when running tests, if this is not set.
env = [
    "ENVIRONMENT=test",
    "DEBUG=False",
    "POSTGRES_USER=testuser",
    "POSTGRES_PASSWORD=testpwd",
    "POSTGRES_DB=testdb",
]

database.py

engine = create_engine(
    settings.POSTGRES_URI,  # will be overrided when running tests
    echo=settings.DATABASE_ECHO,
)

# Admin engine to manage databases (connects to the "postgres" default database)
# It has its own USER/PASSWORD settings because local one are overrided when running tests
admin_engine = create_engine(
    settings.POSTGRES_ADMIN_URI,
    echo=settings.DATABASE_ECHO,
    isolation_level="AUTOCOMMIT",  # required from operation like DROP DATABASE
)

r/FastAPI • • Apr 10 '24

feedback request Update: FastAPI Gen CLI v1: Generate FastAPI + React/Typescript Application with one command

27 Upvotes

I had posted a while back about my `fastapi-gen` project looking for collaborators, but I wanted to post again to say that I have a POC the project!

  1. https://github.com/nick-roberson/fastapi-gen

The idea here is that using a config to define service and model information, you can generate a service backend and frontend to use as a template for further development! This service will include:

  1. MongoDB Database

  2. FastAPI / Pydantic Backend w/ endpoints for each model

  3. React / Typescript Frontend w/ pages for each model

Additionally it will create:

  1. OpenAPI clients for the frontend code and an extra for any python code that may want to call the backend API

  2. Dockerfiles for the project so you can run using Docker

  3. Some basic README.md files for each component

Let me know what you all think!

I know there are similar tools out there, however I will keep developing this to distinguish it from those by doing the following:

  1. Get this on `pip` once I am able to do more testing

  2. More complex frontend components (Add / Update support are next, then individual model instance pages)

  3. Support for background tasks and/or Celery tasks

  4. Support for Redis caching

  5. Support for multiple Database Types (MySQL is next)


r/FastAPI • • Feb 20 '24

Other How do you monitor your FastAPI apps?

27 Upvotes

As in, keep track of requests, error rates, response times etc.? Curious what tools people use!


r/FastAPI • • May 23 '22

Tutorial How to implement multitenancy with FastAPI, SQLAlchemy and PostgreSQL

Thumbnail mergeboard.com
27 Upvotes

r/FastAPI • • Apr 16 '21

Announcement IMPORTANT: PEP 563, PEP 649 and the future of pydantic Β· Issue #2678 Β· samuelcolvin/pydantic

Thumbnail
github.com
27 Upvotes

r/FastAPI • • May 31 '26

Question Simple JWT Authentication for MVP and steps to Production

26 Upvotes

Hi,

Im fairly new to FastAPI, but have 3.5 YOE with Django, which have a big eco-system and supporting libraries. (and especially for authentication, authorization & permissions)

I started developing a personal project using FastAPI, but my authentication implementation is really basic.

I do have an endpoints for create users and login them using access-token, but when I wanted to implement the 'refresh-token' endpoint I encounter some issues:

  1. The docs in FastAPI not including it... um.. yeah..

  2. There is some basic confusion regarding the terms `JWT authentication', `OAuth[0/2]`, that are confusing.

  3. Tried to search for 2 days implementation ideas/example, but each is different, which just add to the confusion. Do the refresh-token needed to be store in the DB?.
    Do I need rotation and revocation?

Tried to find some course/tutorial that will include those ideas, but didnt find.

Can you help me to understand, which implementation is the preferred one for my situation?
I want it to be simple for MVP, but serious enough that it could feasible for Production..