r/FastAPI • • Mar 02 '26

Question Front end options for my API

21 Upvotes

I’m building a backend for a package tracking system with FastAPI and I was wondering what would be considered the best option for the front end specifically the mobile app based on what you’ve worked on in the past. I’m already leaning towards React but wanted to know what issues others may have faced. This would be my first time working with React.


r/FastAPI • • Dec 23 '25

Question How much did FastAPI’s "Bus Factor" actually matter in your production choice?

21 Upvotes

Hi everyone,

I'm currently in the middle of a framework debate for a new project at work. We love FastAPI, but the "Bus Factor" (the project being heavily tied to a single maintainer) is the #1 point of pushback from our senior architects.

For those of you running FastAPI in enterprise/production environments:

  • Was the governance model a dealbreaker for your team? If so, how did you get past it?

  • Do you view the "Bus Factor" as a real risk in 2025, or do you feel the underlying stability of Starlette/Pydantic makes it a non-issue?

  • Did anyone choose Litestar specifically because of its community-governed model? Any regrets or "grass is greener" moments?

I'm less interested in the technical features and more in the institutional trust side. How do you justify building a long-term company asset on a project that still feels very centralized?

Curious to hear if this was a "real world" problem for you or just a theoretical one that managers worry about.


r/FastAPI • • Nov 21 '25

Tutorial Build Powerful Search Features in FastAPI with Elasticsearch

Thumbnail
youtube.com
21 Upvotes

In this video, we build a production-ready blog search API using FastAPI and Elasticsearch. We cover everything from Docker setup to implementing advanced search features like fuzzy matching, field boosting, and relevance scoring.


r/FastAPI • • Oct 17 '25

pip package holm: NextJS-like developer experience for SSR and HTMX with FastAPI

21 Upvotes

Hi guys,

I've first released holm (https://volfpeter.github.io/holm/) a couple of weeks ago. Plenty of new features, guides, documentation improvements dropped since that first version. I haven't shared the project here before, the 0.4 release felt like a good opportunity to do it.

Summary: think FastHTML on steroids (thanks to FastAPI of course), with the convenience of NextJS.

  • Standard FastAPI everywhere, you just write dependencies.

  • Unopinionated and minimalist: you can keep using all the features of FastAPI and rely on its entire ecosystem.

  • NextJS-like file-system based routing, automatic layout and page composition, automatic HTML rendering.

  • Async support everywhere, even in UI components.

  • First-class HTMX support.

  • Typed, JSX-like component syntax.

For a quick glance, you can check out the quick start guide: https://volfpeter.github.io/holm/guides/quick-start-guide

The project is still very new, there is a long way to go. I plan features like automatic form generation from Pydantic models, "server actions", and even deeper HTMX integration.

I hope you'll find the lib interesting :)


r/FastAPI • • Aug 14 '25

Question Getting started on a work project with FastAPI would like to hear your opinions.

21 Upvotes

I'm currently working for a startup where the CTO has already set some of the stack. I'm mainly an infra engineer with some backend stuff here and there but I haven't worked a lot with Databases apart from a few SQL queries.

I've worked with Python before but mostly on a scripting and some very light modules which ran in production but the code wasn't the best and I was mainly doing maintenance work so didn't have time to spend a lot of time fixing it.

I'm jumping into this FastAPI world and it makes a lot of sense to me and I'm feeling slightly optimistic for in developing the backend but I am worried as there's a lot of stuff I don't know.

I've already set up all the infra and ci/cd pipelines etc, so now I can focus on building the FastAPI apps images and the DB.

I would like to hear your opinions on a few topics.

  1. I've been reading about Pydantic and SQLAlchemy as ORMs and I saw there's also a SQLModel library which can be used to reduce boilerplate code, but I'm still not completely sure what is the recommended approach for applications. We have a very tight deadline(around 2 months) to fully finish building out the backend so I'm leaning towards SQLModel since it seems like it may be the fastest, but I'm worried if there's any cons, specifically performance issues that may arise during production. (Although with this timeline, not sure if that even matters that much )

  2. When working with these ORMs etc, are you still able to use SQL queries on the side and try to obtain data a different way if ever this ORM is too slow etc.

  3. For FastAPI, I'm wondering if there's a set directory structure or if it's ok to just wing it. I'm a type of person who likes working small and then building from there, but I'm not sure if there's already a specific structure that I should use for best practices etc.

  4. If you have any type of advise etc, please let me hear it !

Thanks!


r/FastAPI • • Jun 22 '25

Question When should you make a method async in FastAPI?

21 Upvotes

Hey! So I’ve been migrating my .NET WCF to FastAPI over the past few months — it’s my first real project and things are going well so far. I haven’t made any of my methods async though, and I was wondering… what’s the general rule of thumb for when you should make a method async?

Breakdown:

  • It's going to be hosted in a Docker container in our local kuberneties.

  • I'm currently using sqlalchemy and pydantic to connect to my existing SSMS database. (eg user = do.query(UserTable).filter(UserTable.userid=1).scalar()

  • Basic workflow is save transaction to database generate doc of transaction and send email of doc.


r/FastAPI • • May 02 '25

pip package PgQueuer – PostgreSQL-native job & schedule queue, gathering ideas for 1.0 🎯

Thumbnail
reddit.com
21 Upvotes

r/FastAPI • • Mar 03 '25

pip package Ludic finally supports FastAPI: Typed HTML/Components with Python

21 Upvotes

Hi,

I just added support for FastAPI for Ludic.

Ludic is a framework/library for web development in Python with type-guided components rendering as HTML. It is similar to FastUI, Reflex, but web framework independent. But it uses HTMX instead of web sockets + React.

I think it is good for building small apps, blogs. Good also for beginners who don't know javascript and want to build we apps. Here is the documentation + GitHub:

Here is an example of FastAPI app:

Feedback would be highly appreciated.


r/FastAPI • • Sep 17 '24

Tutorial Beta Acid open sourced its FastAPI reference architecture

Thumbnail
github.com
21 Upvotes

r/FastAPI • • Aug 02 '24

Tutorial Deploy FastAPI applications with Render [tutorial]

21 Upvotes

Hello everyone! There are always questions in this and other subs about how to deploy FastAPI and other types of applications. The truth is, there are many different ways to deploy FastAPI applications.

A good choice these days is Render. For those who don't have much experience with DevOps and don't want to/can't go through the whole process of setting up an account on AWS, GCP, and Azure, and setting up all the infrastructure, or configuring and managing their own server, Render is a good choice.

To deploy to Render, you simply create a database and a web service, link your GitHub repository to Render, and ready to go. It auto-deploys on every new commit to the main branch. You don't have to manage anything.

Render isn't the right choice for every project, but most personal projects can probably do with Render. I run a few of my own projects on Render and have used Render for a few clients in the past too.

If you want to know how it works, I put together a quick tutorial: https://youtu.be/nOP8khZhjhk

The code for the tutorial is here: https://github.com/abunuwas/short-tutorials/tree/main/fastapi-render

Hope you enjoy the tutorial and find it useful!


r/FastAPI • • Mar 28 '23

pip package New release of FastKafka supporting Redpanda

21 Upvotes

We were searching for something like FastAPI for Kafka-based service we were developing, but couldn’t find anything similar. So we shamelessly made one by reusing beloved paradigms from FastAPI and we shamelessly named it FastKafka. The point was to set the expectations right - you get pretty much what you would expect: function decorators for consumers and producers with type hints specifying Pydantic classes for JSON encoding/decoding, automatic message routing to Kafka brokers and documentation generation.

https://github.com/airtai/fastkafka

This new release implements a number of feature requests coming from the community, the most significant one being adding support for Redpanda (https://github.com/redpanda-data/redpanda/) broker for both testing and deployment. Here is a detailed guide on how to use FastKafka/Redpanda combo:

https://fastkafka.airt.ai/0.3.1/guides/Guide_31_Using_redpanda_to_test_fastkafka/

Please take a look at the framework and let us know how to make it better.


r/FastAPI • • Sep 10 '22

pip package starlette-admin: Simple and extensible admin interface framework for Starlette/FastApi

21 Upvotes

Hi FastAPI users! just to share with you this admin interface framework for Starlette/FastApi (https://github.com/jowilf/starlette-admin)

Documentation: https://jowilf.github.io/starlette-admin

Online demo avalaible here

The key features are:

  • Flexibility : The biggest feature of Starlette-Admin is flexibility. Start with autogenerated CRUD-views of your model and customize those views & forms as the need arises.

  • Datatables : Starlette-Admin use Datatables to render list. Main Features included are:

    • Multi-column ordering: Sort data by multiple columns at once.

    • Full-text search: Filter results by text search with highlight.

    • Search Builder: Filter results by complex query including AND and OR conditions.

    • Many Export options: Export your data to CSV, PDF, Excel and Browser Print.

    • You can easily include any other features you need from datatables. Read Datatables documentation for more information.

  • Files Handling : Easily attach files to your model. Thanks to SQLAlchemy-file for SQLAlchemy integration

  • Multiple admin : Expose multiple admin interfaces.

  • Modern UI using Tabler

This project is inspired by Flask-Admin and the main goal is to provide similar tool for Starlette/FastApi.

Starlette-Admin is designed to work with any ORM and have currently built-in support for:


r/FastAPI • • Apr 23 '22

Other PSA: I think this JSON to Pydantic converter is extremely useful for boilerplate model creation

Thumbnail jsontopydantic.com
21 Upvotes

r/FastAPI • • Mar 15 '22

Tutorial FastAPI Microservices Full Course

Thumbnail
youtube.com
21 Upvotes

r/FastAPI • • Dec 07 '21

Question Why is my FastAPI application able to make several hundred HTTP requests/second when the requests are synchronous?

21 Upvotes

I created a small project for benchmarking sync/async operations in FastAPI APIs.

It seems that calls that should be blocking (e.g. open() or requests.get()) are running perfectly in parallel.

This seems great because it means I don't really need async and async libraries when I thought I did. However, I'm not familiar enough with FastAPI to make that judgement yet. Can someone explain what's going on here? And if using async even makes sense if synchronous calls run in parallel?

I put the code for reproducing my experiments on a public repository here. Repo contains a quick start guide for running the stress tests.

Experiments

General settings for all experiments:

  • Simple FastAPI application with two routes

    • /sync/... for synchronous operations

    • /async/... for asynchronous operations

  • API is run under Gunicorn with a single worker

    • Worker class set to uvicorn.workers.UvicornWorker

  • API is stress tested using Locust

    • Only one endpoint per test

    • 500 users @ 50 users/sec spawn rate

    • Each user waits 1 second between requests

    • Tests run for 1 minute

Loading JSON from disk

Users hit an endpoint that loads a small JSON file from disk and returns it. The /sync/json endpoint uses the standard open() method to read the file (should be blocking). The /async/json endpoint uses aiofiles.open() instead.

/sync/json statistics:

  • Num. requests: 15550

  • Avg. response time: 745 ms

  • Avg. requests/second: 259.16

/async/json statistics:

  • Num. requests: 15304

  • Avg. response time: 778 ms

  • Avg. requests/second: 255.06

With an avg. response time of 745 ms, it's simply not possible for open() to be blocking with 15550 requests successfully handled in 1 minute.

Making HTTP requests

Users hit an endpoint that makes a GET request to https://jsonplaceholder.typicode.com/todos/1 and returns the result. The /sync/http endpoint uses the httpx.Client() synchronous client, which should be blocking. Was also tested with requests.get() with similar results. The /async/http endpoint uses the httpx.AsyncClient() asynchronous client.

/sync/http statistics:

  • Num. requests: 6422

  • Avg. response time: 917 ms

  • Avg. requests/second: 107.03

/async/http statistics:

  • Num. requests: 3946

  • Avg. response time: 5951 ms (I did not switch up sync/async here)

  • Avg. requests/second: 65.76

Again, with the average request taking 917 ms to complete, httpx.Client.get() can not be blocking when it successfully made 6422 GET requests in 1 minute.

Also interestingly, the synchronous HTTP client seems to perform much, much better than the asynchronous one. No requests failed in either case, and the tests were run several times to ensure that one wasn't being rate-limited while the other was.

Hope someone can help me clear this up, thanks in advance!


r/FastAPI • • Nov 25 '21

Tutorial Moving from Flask to FastAPI

Thumbnail
testdriven.io
21 Upvotes

r/FastAPI • • Feb 11 '21

Question Project structure for scalable fastapi project.

21 Upvotes

What would be the project structure for scalable large fast api project? What should I use orm or async postgress library?


r/FastAPI • • Dec 08 '20

Tutorial Securing FastAPI with JWT Token-based Authentication

Thumbnail
testdriven.io
21 Upvotes

r/FastAPI • • 18d ago

Other A code-first approach to auto-generated docs for FastAPI WebSockets (my AsyncAPI Conf 2026 talk)

20 Upvotes

Hi all,

I recently gave a talk at AsyncAPI Conf 2026 (online), and the demo app was FastAPI, so I thought it fits here.

The short version: I love that a FastAPI route gives you validation, OpenAPI and /docs just from type hints. @app.websocket gives you none of that. You receive_json(), check data["action"], send_json() back, and the only place the message shapes exist is in your head. Then you copy the ConnectionManager from the docs, and it works until you run a second worker haha.

That bit me for real. My backend sent the chat text as content, the React side read body. Both sides' tests passed, nothing threw, the UI just showed an empty space. Took me most of a day.

So in the talk I treat a WebSocket handler like a route, where the signature is the contract:

@channel(name="chat", description="Room chat")
class ChatConsumer(AsyncJsonWebsocketConsumer):
    groups = ["lobby"]

    @ws_handler(output_type=ChatNotification)
    async def handle_chat(self, message: ChatMessage) -> None:
        await self.broadcast_message(ChatNotification(payload=message.payload))

ChatMessage and ChatNotification are Pydantic models. From handlers like this the app serves an AsyncAPI 3 document plus a docs page (basically /openapi.json and /docs for the socket), and from that document I generate a Python client and a TypeScript client and commit them. When someone renames a field, the frontend type check fails in the PR.

The library is chanx, which I wrote and use at work (open source, BSD, sorry for the plug). Besides the docs, the parts I'd miss most on a plain @app.websocket: a bad payload gets a structured error reply before my handler runs, groups go through Redis (via fast-channels) so broadcasts reach every worker, and I can push to a room from a normal route or a background task with await ChatConsumer.broadcast_event(...). There's also a test communicator, so socket tests don't need sleep(), and chanx-js generates the frontend client with React, Vue, Svelte or Solid bindings.

English isn't my first language, so if I explain something badly in the video, ask here and I'll try again. And I'm curious how you handle this today: hand-written docs, a shared types package, or just the ConnectionManager and hope?


r/FastAPI • • May 28 '26

pip package fastapi-storages: S3 and filesystem storage support for FastAPI

20 Upvotes

I wanted to share fastapi-storages, a small library for integrating FastAPI with storage backends like S3 and filesystem storage:

https://github.com/aminalaee/fastapi-storages

The project is inspired by the simplicity and developer experience of django-storages, but designed for FastAPI applications.

Supports things like:

  • S3-compatible storage

  • local filesystem storage

  • SQLAlchemy integration

  • Pewee integration

  • sync and async (where possible)

Would love feedback from people building FastAPI backends or handling uploads/storage in production.


r/FastAPI • • Apr 19 '26

feedback request FastAPI BackgroundTasks with retries, a live dashboard, persistence, and no broker.

20 Upvotes

A few weeks ago I posted about fastapi-taskflow, a library that adds retries, a live dashboard, persistence, and task visibility on top of FastAPI's native BackgroundTasks without replacing it or requiring a broker.

Since then I have added more features and I want to get real feedback from people actually building with FastAPI before I keep adding more features.

Give it a try and let me know what you think.

pip install fastapi-taskflow

Source: https://github.com/Attakay78/fastapi-taskflow

Docs: https://attakay78.github.io/fastapi-taskflow/

A quick summary of what it does today:

  • Retries with delay and exponential backoff per function

  • Task IDs and lifecycle tracking: PENDING, RUNNING, SUCCESS, FAILED, INTERRUPTED

  • Live dashboard at /tasks/dashboard with filtering, search, per-task logs, and stack traces

  • SQLite out of the box, Redis as an optional extra

  • Pending tasks at shutdown are re-dispatched on next startup

  • Idempotency keys to prevent duplicate runs

  • Argument encryption for tasks carrying sensitive data

  • Concurrency controls: opt-in semaphore for async tasks, dedicated thread pool for sync tasks

It is not a distributed task queue. No broker, no separate workers. It does support multi-instance deployments with SQLite on the same host or Redis across hosts, with atomic requeue claiming and shared task history. But tasks still run inside the web process, not on dedicated workers.

If you use BackgroundTasks in production and give it a try, I would love to hear what works, what does not, and what you wish it did differently.


r/FastAPI • • Mar 24 '26

pip package [Update] FastKit Core + CLI — we shipped proper documentation

20 Upvotes

Hey everyone! A couple of months ago, I posted about FastKit Core, an open-source toolkit for FastAPI. The feedback was encouraging, so we kept building — and today we finally have full documentation at fastkit.org.

FastKit Core gives you a production-ready structure for FastAPI apps: Repository pattern, Service layer with lifecycle hooks, and a few things you won't easily find elsewhere — built-in TranslatableMixin for multilingual models, and standardized HTTP response formatting that makes microservice communication consistent out of the box.

We also shipped FastKit CLI — run fastkit make module Invoice and you get a complete module: model, schema, repository, service, and router with all CRUD endpoints wired up and ready to go. One command, six files, zero boilerplate.

What's included:

  • Repository pattern for database operations (sync + async)

  • Service layer with before_create, after_update and other lifecycle hooks

  • TranslatableMixin — multi-language support built directly into SQLAlchemy models

  • Validation with structured, translated error messages

  • HTTP utilities for consistent API responses across services

  • CLI scaffolding — generate complete modules, run migrations, seed your database

Links:

If you've tried it — or tried it and hit something that doesn't work — we'd really love to hear about it. And if it looks useful, a star on GitHub means a lot for a small open source project.


r/FastAPI • • Jan 26 '26

Hosting and deployment 200ms latency for a simple FastAPI ping endpoint on a Hetzner VPS? Please help.

20 Upvotes

Stack

I'm hosting a simple FastAPI backend behind Gunicorn and Nginx, on a 8GB Hetzner Cost-Optimized VPS (but I tried scaling up to a 32GB VPS and the result is the same). This is my /etc/nginx/sites-available/default file:

server {
    listen 443 ssl http2;
    server_name xxxx.xxxx.com;

    ssl_certificate /etc/letsencrypt/live/xxxx.xxxx.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/xxxx.xxxx.com/privkey.pem;

    location / {
        proxy_pass http://127.0.0.1:8000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

this is the systemd gunicorn service /etc/systemd/system/gunicorn.service:

[Unit]
After=network.target

[Service]
User=myuser
Group=myuser
WorkingDirectory=/opt/myapp
Restart=always
ExecStart=/opt/myapp/.venv/bin/gunicorn \
--workers=4 \
--timeout 60 \
--umask 007 \
--log-level debug \
--capture-output \
--bind http://127.0.0.1:8000 \
--worker-class uvicorn.workers.UvicornWorker \
--access-logfile /var/log/myapp/app.log \
--error-logfile /var/log/myapp/app.log \
--log-file /var/log/myapp/app.log \
app.main:app

[Install]
WantedBy=multi-user.target

and this is the bare-bone FastAPI app

from fastapi import FastAPI

app = FastAPI()

.get("/ping")
async def ping():
    return {"ping": "pong"}

I am proxying requests through CloudFlare, although that doesn't seem to be the issue as I experience the same latency when disabling the proxy.

The problem

While I believe that, with this kind of stack, a simple ping endpoint should have a maximum latency of 50-70ms, the actual average latency, obtained in Python by measuring time.perf_counter() before and after requests.get() and subtracting them, is around 200ms. Any idea what I am doing wrong?


r/FastAPI • • Dec 26 '25

pip package I developed a Python library called typed-pytest

20 Upvotes

I developed a Python library called typed-pytest during the Christmas holiday. It's now available on PyPI (v0.1.7).

What My Project Does:

typed-pytest is a type-safe mocking library for pytest. When you use MagicMock(MyClass) in pytest, your IDE loses all autocomplete - you can't see the original class methods, and mock assertions like assert_called_once_with() have no type hints.

typed-pytest fixes this by providing:

- Full IDE autocomplete for both original class methods and mock assertion methods

- Lint-time typo detection - misspelled method names are caught by type checkers before tests run

- Type-checked mock properties - return_value, side_effect, call_count are properly typed

- Stub generator CLI - generates project-specific type stubs for your classes

from typed_pytest_stubs import typed_mock, UserService

mock = typed_mock(UserService)

mock.get_usr # ❌ Caught by type checker: "get_usr" is not a known member

mock.get_user.assert_called_once_with(1) # ✅ Autocomplete + type-checked!

Type Checker Support:

We've tested and verified compatibility with 4 major Python type checkers:

- ✅ mypy

- ✅ pyright

- ✅ pyrefly (Meta's new type checker)

- ✅ ty (Astral's new type checker)

All pass with 0 errors in our CI pipeline.

Target Audience:

Python developers who use pytest with mocks and want better IDE support and type safety. Especially useful for those practicing TDD or working with AI coding assistants where fast feedback on syntax errors is important.

Comparison:

The standard unittest.mock.MagicMock provides no type information - your IDE treats everything as Any. Some developers use cast() to recover the original type, but then you lose access to mock-specific methods like assert_called_with().

typed-pytest gives you both: original class signatures AND mock method type hints, all with full IDE autocomplete.

Coming Soon:

I'm planning to provide Claude Code Skills in a separate repository, so you can easily integrate typed-pytest into your AI-assisted development workflow.

Check out the project at: https://github.com/tmdgusya/typed-pytest

Feedback, contributions, and ⭐ are all appreciated!