r/FastAPI • • Aug 23 '25

Question Public Github projects of high quality FastAPI projects with rate limiting and key auth?

18 Upvotes

I'm trying to learn how to build commercial APIs and therefore I'm building an API with rate limiting and key authentication. I'm looking for public Github projects I can use as a reference. Are there any good examples?


r/FastAPI • • Aug 23 '25

Question Analyzing Web Frameworks

18 Upvotes

I am a Python developer. Now I do have experience in various Python frameworks like Django, Flask & FastAPI. Now, however in every interview the interviewer asks me how would you choose between these three if you had to build a large-scale web application, I fumble. I have looked all over the web for answers and haven't found a convincing one. How do we evaluate web frameworks for any requirement of a web application?


r/FastAPI • • Jul 23 '25

Tutorial FARM Stack Guide: How to Build Full-Stack Apps with FastAPI, React & MongoDB

Thumbnail datacamp.com
18 Upvotes

r/FastAPI • • Apr 01 '25

Question Exploring FastAPI and Pydantic in a OSS side project called AudioFlow

18 Upvotes

Just wanted to share AudioFlow (https://github.com/aeonasoft/audioflow), a side project I've been working on that uses FastAPI as the API layer and Pydantic for data validation. The idea is to convert trending text-based news (like from Google Trends or Hacker News) into multilingual audio and send it via email. It ties together FastAPI with Airflow (for orchestration) and Docker to keep things portable. Still early, but figured it might be interesting to folks here. Would be interested to know what you guys think, and how I can improve my APIs. Thanks in advance 🙏


r/FastAPI • • Mar 12 '25

Question Full stack or Frontend?Need advice!!

18 Upvotes

I have 3+ years in ReactJS & JavaScript as a frontend dev. For 7–8 months, I worked on backend with Python (FastAPI), MongoDB, Redis, and Azure services (Service Bus, Blob, OpenAI, etc.).

I haven’t worked on authentication, authorization, RBAC, or advanced backend topics.

Should I continue as a frontend specialist, or transition into full-stack? If full stack, what advanced backend concepts should I focus on to crack interviews?

Would love advice from those who have made this switch!


r/FastAPI • • Mar 01 '25

Question In FastAPI can we wrap route response in a Pydantic model for common response structure?

18 Upvotes

I am learning some FastAPI and would like to wrap my responses so that all of my endpoints return a common data structure to have data and timestamp fields only, regardless of endpoint. The value of data should be whatever the endpoint should return. For example:

from datetime import datetime, timezone
from typing import Any

from fastapi import FastAPI
from pydantic import BaseModel, Field

app = FastAPI()


def now() -> str:
    return datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S")


class Greeting(BaseModel):
    message: str


class MyResponse(BaseModel):
    data: Any
    timestamp: str = Field(default_factory=now)


@app.get("/")
async def root() -> Greeting:
    return Greeting(message="Hello World")

In that, my endpoint returns Greeting and this shows up nicely in the /docs - it has a nice example, and the schemas section contains the Greeting schema.

But is there some way to define my endpoints like that (still returning Greeting) but make it to return MyResponse(data=response_from_endpoint)? Surely it is a normal idea, but manually wrapping it for all endpoints is a bit much, and also I think that would show up in swagger too.


r/FastAPI • • Nov 28 '24

Question Is there a way to limit the memory usage of a gunicorn worker with FastAPI?

18 Upvotes

This is my gunicorn.conf.py file. I’d like to know if it’s possible to set a memory limit for each worker. I’m running a FastAPI application in a Docker container with a 5 GB memory cap. The application has 10 workers, but I’m experiencing a memory leak issue: one of the workers eventually exceeds the container's memory limit, causing extreme slowdowns until the container is restarted. Is there a way to limit each worker's memory consumption to, for example, 1 GB? Thank you in advance.

  • gunicorn.conf.py

import multiprocessing

bind = "0.0.0.0:8000"
workers = 10
worker_class = "uvicorn.workers.UvicornWorker"
timeout = 120
max_requests = 100
max_requests_jitter = 5
proc_name = "intranet"
  • Dockerfile

# Dockerfile.prod

# pull the official docker image
FROM python:3.10.8-slim

ARG GITHUB_USERNAME
ARG GITHUB_PERSONAL_ACCESS_TOKEN

# set work directory
WORKDIR /app

RUN mkdir -p /mnt/storage
RUN mkdir /app/logs

# set enviroments
ENV GENERATE_SOURCEMAP=false
ENV TZ="America/Sao_Paulo"

RUN apt-get update \
  && apt-get -y install git \
  && apt-get clean

# install dependencies
COPY requirements.txt .
RUN pip install -r requirements.txt


# copy project
COPY . .

EXPOSE 8000

CMD ["gunicorn", "orquestrador:app", "-k", "worker.MyUvicornWorker"]

I looked at the gunicorn documentation, but I didn't find any mention of a worker's memory limitation.


r/FastAPI • • Nov 14 '24

Question Rate limit

18 Upvotes

I have a scenario where I am using workers and need to rate limit the APIs that's specification single users, if I use slowapi or anything else with a middle ware the workers will be of an issue...I am currently using db or memcachinh...is there any other possible way to do this?


r/FastAPI • • Oct 09 '23

Question Do you know any quality FastAPI starter projects?

18 Upvotes

Do you know any? If yes, please post links. Either backend or full-stack.

Here is what I could find so far:

https://github.com/zhanymkanov/fastapi_production_template

https://github.com/kamranabdicse/fastapi-postgres-boilerplate

https://github.com/jonra1993/fastapi-alembic-sqlmodel-async

https://github.com/testdrivenio/fastapi-sqlmodel-alembic

https://github.com/innovatorved/whisper.api

https://github.dev/AdrianPayne/fastapi-rocket-boilerplate

Here is the official one, but I find it unpractical to use because of large number of arguments needed for cookiecutter right at the beginning, and the code is difficult to understand without them. Also this project is heavily outdated.

https://github.com/tiangolo/full-stack-fastapi-postgresql


r/FastAPI • • Sep 20 '22

Tutorial ToDo App in FastAPI with Jinja2 Template

Thumbnail
codesnail.com
18 Upvotes

r/FastAPI • • Jun 19 '22

Other An Interview with Sebastián Ramírez, Founder of FastAPI

Thumbnail
console.substack.com
18 Upvotes

r/FastAPI • • Feb 26 '22

Question Microservices architecture with FastAPI

18 Upvotes

Hi all,

I need some advice in regards to a microservices app design.

I have started to work on a new project to practice system design/architecture.
It's going to be a very simple payments API.

I want the app to have 2 main services:

  1. Users service

  2. Payment service

The user's service will be responsible for user login and registration, and the payment service will be responsible for sending payments to other people.

The stack I am going to use: Python, FastAPI, Docker, Nginx.

My questions are:

  1. What will be the best way to put the services together? Each service will be in a different Docker container?

  2. When it comes to networking between the containers, is there's anything I need to consider?

  3. In regards to the database, should have one database (say Postgres)?

  4. If I should have only one database, how both services will be able to access it?

Thanks!


r/FastAPI • • Sep 06 '21

Question Books on FastAPI

18 Upvotes

Some chapters of Fluent Python 2e, O'Reilly show some FastAPI examples but is there an entire book dedicated to it? I am reading official documents and have a bit of Flask and Plotly-Dash experience.


r/FastAPI • • Apr 21 '21

Tutorial Developing and Testing an Asynchronous API with FastAPI and Pytest

Thumbnail
testdriven.io
18 Upvotes

r/FastAPI • • Apr 19 '21

Other Upcoming PyCon talk about the FastAPI packages powering OPAl.ac

Post image
18 Upvotes

r/FastAPI • • Mar 16 '21

Tutorial Streaming video with FastAPI

Thumbnail
stribny.name
18 Upvotes

r/FastAPI • • Feb 18 '21

Question ORM or Pydantic model?

18 Upvotes

Hi, I am building a FastAPI application, but am quite new to this sort of development (making the jump from physics scientific software)--so I have a question about best practices.

I'll lay out an example first and hopefully, my question will be more clear.

from pydantic import BaseModel
from tortoise import fields, models

# ORM model (tortoise)
class User(models.Model):
    firstname: fields.CharField(max_length=64)
    surname: fields.CharField(max_length=64)
    username: fields.CharField(max_length=64)

# Pydantic model (ignore lack of str length constraints)
class User_Pydantic(BaseModel):
    firstname: str
    surname: str
    username: str

Now, consider some crude user registration using a POST /register. What is considered best practise? Reading in as a Pydantic model or ORM model? Is it just a matter of choice? I know I can generate Pydantic models from ORM models.

Why I've been thinking about this?

This could be where my inexperience shows, but for my current project, I have defined some tortoise models. The base model is very similar to above. I then have 2 additional models that inherit from the base model. One for storing in the DB--has a hashed password field--and the other is for expected input at /register endpoint--has a plain-text password field (obvs wouldn't want to store this in a DB).

Now, when I run my program, I noticed I have tables in my DB for UserBase, UserInDB and UserIn. I only want the UserInDB table in my DB. So essentially, is there a way to only create the UserInDB table. Or, as I eluded to previously, should I use Pydantic models and only convert to ORM model when interacting with DB (i.e. creating record).

Any questions, please ask. Pretty much never used reddit and I'm not sure why!


r/FastAPI • • Oct 24 '26

feedback request Running stateless SQLite FTS5 + HTMX on FastAPI Cloud (zero Redis/Postgres, zero JS framework) — DAG route compiler showcase

17 Upvotes

Wanted to share an architectural pattern from an open-source project I just deployed to FastAPI Cloud using FastAPI + Jinja2 + HTMX + SQLite FTS5:

1. The Ephemeral Worker Problem

When deploying a hobby/community app to serverless or ephemeral container workers platform, spinning up a managed Postgres + Redis instance just to store user checklist/session state is overkill — and writing user state to a local SQLite file breaks as soon as containers scale or restart.

The Solution — Read-Only Bundled SQLite FTS5 + Cookie-Backed State:

  • Immutable Catalog (ngplus.db): The SQLite database (1,241 catalog items, fts5 search index with porter unicode61, and 82 DAG quest rules) is baked into the deployment image and opened strictly read-only at runtime. Zero write locks (SQLITE_BUSY), sub-millisecond local FTS5 queries on GET /search.

  • Stateless Cookie Sessions (er_order & er_steps): All mutable user state is serialized into two compact httponly cookies (30-day TTL) plus GET /export (StreamingResponse) and POST /import JSON endpoints for cross-device portability. Any ephemeral Uvicorn worker can wake up cold and serve any user's request with zero server-side session storage.

2. Zero-JS-Framework Reactivity (FastAPI + HTMX)

  • All state mutations (POST /order/add, /order/toggle, /step/toggle) compute the new DAG state and return a single server-rendered Jinja2 partial (templates/partials/workspace.html).

  • Responses attach HX-Trigger: refreshSearch (so the FTS5 typeahead dropdown automatically re-syncs queued badges) and strict Cache-Control: no-store, no-cache, must-revalidate, max-age=0 headers so browser back/forward navigation never serves stale partial state.

3. The Domain Problem: Dependency-Inverted DAG (compiler.py)

The app itself solves "Miyazaki's Quest Knot" in Elden Ring: quests form an inverted dependency web where early steps have no obvious lockouts, but downstream steps 20 hours later are gated by irreversible world-state triggers (Points of No Return / PONRs).

  • Users pick terminal leaf items (T) they want on their run.

  • compile_run_plan() walks each item's prerequisite chain in reverse, propagating the tightest downstream PONR ceiling backward (running_ceiling = min(running_ceiling, step_gate_pos)), clamping each step's geographical progression weight (zone_order), deduplicating diamond dependencies across shared step_keys, and flagging same-run mutual exclusivity collisions (exclusive_group).

Would love any feedback on the stateless FastAPI + HTMX architecture or the DAG solver in compiler.py!


r/FastAPI • • Jul 21 '26

Tutorial Finished my first FastAPI project. Where do I go from here?

17 Upvotes

Hey everyone,

I recently finished my first FastAPI project and wanted to get some feedback from people with more experience.

It's just a simple Movie Watchlist API that I built to learn FastAPI and backend fundamentals, so I'm not really looking for feedback on the idea itself. I'm more interested in hearing what you think about the code, the structure, and the way I approached building it.

Repo: https://github.com/BensefiaAbdessamed/MoviesWatchlist

My goal is to become a backend engineer who can build production-ready applications, so I'd really appreciate an honest review. If you were reviewing this as a junior's project, what would you point out? What beginner mistakes do you notice? What would you refactor or do differently? Are there any bad practices that I should stop early?

I'm also a bit unsure about what to learn next. Should I keep improving this project by adding more concepts, or is it better to start a new one? What backend topics do you think are important after getting comfortable with FastAPI? Things like testing, caching, message queues, Docker, CI/CD, design patterns, system design, or anything else?

A couple of friends also suggested that I should learn Django next. Do you think it's worth learning at this stage, or should I keep going deeper with FastAPI and backend fundamentals before jumping to another framework?

Lately I've also been getting interested in RAG systems and MCP integration because AI applications seem to be everywhere now. Do you think it's a good idea to start learning those, or would that just distract me from building a strong backend foundation first?

Feel free to be as critical as you want. I'm posting this because I genuinely want to improve and avoid building bad habits early on.

Thanks to anyone who takes the time to review it or share their advice. I really appreciate it.


r/FastAPI • • Feb 26 '26

pip package We built a self-hosted observability dashboard for AI agents — one flag to enable, zero external dependencies using FASTAPI

17 Upvotes

We've been building https://github.com/definableai/definable.ai, an open-source Python framework built on fastapi for building AI agents. One thing that kept burning us during development: you can't debug what you can't see. Most agent frameworks treat observability as an afterthought — "just send your traces to LangSmith/Arize and figure it out.

https://youtu.be/WbmNBprJFzg

We wanted something different: observability that's built into the execution pipeline itself, not bolted on top

Here's what we shipped:

One flag. That's it.

from definable.agent import Agent
agent = Agent(
    model="openai/gpt-4o",
    tools=[get_weather, calculate],
    observability=True,  # <- this line
)
agent.serve(enable_server=True, port=8002)
# Dashboard live at http://localhost:8002/obs/

No API keys. No cloud accounts. No docker-compose for a metrics stack. Just a self-contained dashboard served alongside your agent.

What you get

- Live event stream : SSE-powered, real-time. Every model call, tool execution, knowledge retrieval, memory recall - 60+ event types streaming as they happen.

- Token & cost accounting: Per-run and aggregate. See exactly where your budget is going.

- Latency percentiles: p50, p95, p99 across all your runs. Spot regressions instantly.

- Per-tool analytics: Which tools get called most? Which ones error? What's the avg execution time?

- Run replay: Click into any historical run and step through it turn-by-turn.

- Run comparison Side-by-side diff of two runs. Changed prompts? Different tool calls? See it immediately.

- Timeline charts: Token consumption, costs, and error rates over time (5min/30min/hour/day buckets).

Why not just use LangSmith/Phoenix?

- Self-hosted — Your data never leaves your machine. No vendor lock-in.

- Zero-config — No separate infra. No collector processes. One Python flag.

- Built into the pipeline — Events are emitted from inside the 8-phase execution pipeline, not patched on via monkey-patching or OTEL instrumentation.

- Protocol-based: Write a 3-method class to export to any backend. No SDKs to install.

We're not trying to replace full-blown APM systems. If you need enterprise dashboards with RBAC and retention policies, use those. But if you're a developer building an agent and you just want to *see what's happening* — this is for you.

Repo: https://github.com/definableai/definable.ai

its still in early stages, so might have bugs I am the only one who is maintaining it, looking for maintainers right now.

Happy to answer questions about the architecture or take feedback.


r/FastAPI • • Feb 07 '26

Question How to implement UI filtering without full page reload using FastAPI + Jinja2

17 Upvotes

Hi everyone,

I’m quite new to web development and I’m learning by building a small personal finance web app.

Current stack:

Backend: FastAPI

Database: SQLite

Frontend: Jinja2 templates + Tailwind CSS

I’d like to avoid heavy JavaScript if possible

Right now, I display a table summarizing my financial data (accounts, balances, account types, etc.).

What I want to achieve is a filtering/search feature in the UI in a div above the table (for example:

filter by account provider

filter by account type: savings / investments

possibly a search input)

The key requirement is: 👉 update only part of the page (the table) without reloading the whole page.

I’ve read that:

One approach is to create a separate FastAPI endpoint that accepts query parameters (?provider=…&type=…)

This endpoint would return only a partial HTML template

The frontend would then replace the table dynamically

ChatGPT suggested using HTMX for this, but I’m a bit confused about:

- How HTMX fits with Jinja (since I have already my table populated)

- Whether I really need multiple endpoints

- How the request/response flow should look conceptually

Edit: After a couple of weeks trying to figure things out, I finally realized that the combination of Alpine.js (to manage user state and the UI) and HTMX (to handle server-side communication) is amazing 😍 Of course, I could have gone with an already prebuilt framework, but this is how you learn. So thank you very much, everyone, for your feedback.


r/FastAPI • • Sep 25 '25

Question django to fastapi

17 Upvotes

We've hit the scaling wall with our decade-old Django monolith. We handle 45,000 requests/minute (RPM) across 1,500+ database tables, and the synchronous ORM calls are now our critical bottleneck, even with async views. We need to migrate to an async-native Python framework.

To survive this migration, the alternative must meet these criteria:

  1. Python-Based (for easy code porting).

  2. ORM support similar to Django,

  3. Stability & Community (not a niche/beta framework).

  4. Feature Parity: Must have good equivalents for:

    • Admin Interface (crucial for ops).

    • Template system.

    • Signals/Receivers pattern.

    • CLI Tools for migrations (makemigrations, migrate, custom management commands, shell).

  5. We're looking at FastAPI (great async, but lacks ORM/Admin/Migrations batteries) and Sanic, but open to anything.

also please share if you have done this what are your experiences


r/FastAPI • • Aug 22 '25

Tutorial From Django to FastAPI

17 Upvotes

What are the best resources or road maps to learn fastAPI if i’m a Django developer?


r/FastAPI • • Jul 28 '25

Question FastAPI Authentication Question

17 Upvotes

Hello all! I am not a software developer, but I do have a heavy background in database engineering. Lately, I've been finding a lot of joy in building ReactJS applications using AI as a tutor. Given that I am very comfortable with databases, I prefer to shy away from ORMs (I understand them and how they are useful, but I don't mind the fully manual approach). I recently discovered FastAPI (~3 months ago?) and love how stupid simple it is to spin up an API. I also love that large companies seem to be adopting it making my resume just a bit stronger.

The one thing I have not really delved into just yet is authentication. I've been doing a ton of lurking/researching and it appears that FastAPI Users is the route to go, but I'd be lying if I said it didn't seem just slightly confusing. My concern is that I build something accessible to the public internet (even if its just a stupid todo app) and because I didn't build the auth properly, I will run into security concerns. I believe this is why frameworks like Django exist, but from a learning perspective I kind of prefer to take the minimalist approach rather than jump straight into large frameworks.

So, is handling authentication really that difficult with FastAPI or is it something that can be learned rather easily in a few weeks? I've considered jumping ship for Django-Ninja, but my understanding is that it still requires you to use django (or at least add it as a dependency?).

Also, as a complete side-note, I'm planning on using Xata Lite to host my Postgres DB given their generous free tier. My react app would either be hosted in Cloudflare Workers or Azure if that makes a difference.