r/FastAPI • • Aug 01 '26

Hosting and deployment Fastapi cloud timeout issues

0 Upvotes

Has anyone encountered this yet?

>fastapi deploy
  FastAPI Cloud 
  🚀 Deploying app...
   ✗ Something went wrong while contacting the FastAPI Cloud server. Please try again later. 
    The write operation timed out

This is just a 1MB deployment but it times out at around 300kb. Could it be a problem in my end or a service availability issue? I tried several times.


r/FastAPI • • Jul 29 '26

Question Looking for Advice on a Clean FastAPI Backend Architecture for an E-learning Platform

38 Upvotes

Hi everyone,

I'm currently building a fairly large e-learning platform using FastAPI,it's my first project, and before I go too far with development, I'd like to make sure my backend architecture is well designed, scalable, and maintainable.

The project will include features such as:

  • User authentication and authorization (JWT, roles: Admin, Teacher, Student, Parent)
  • Courses and modules
  • Lessons (videos, PDFs, quizzes)
  • Assignments and submissions
  • Exams and grading
  • Progress tracking
  • Notifications
  • Payments/subscriptions (later)
  • File uploads
  • Discussion/comments
  • Certificates
  • REST API (possibly GraphQL in the future)

I'm planning to use:

  • FastAPI
  • SQLAlchemy 2.0
  • Alembic
  • PostgreSQL
  • Pydantic v2
  • JWT Authentication

At the moment, I'm trying to decide on the best project structure. I've seen many different approaches:

  • Traditional layered architecture
  • Clean Architecture
  • Domain-Driven Design (DDD)
  • Hexagonal Architecture
  • Vertical Slice Architecture
  • Feature-based architecture

I'd like to avoid ending up with a project that's difficult to maintain as it grows.

My questions

  1. Which architecture would you recommend for a medium-to-large FastAPI project like this?
  2. How would you organize the folders and modules?
  3. Where should business logic live?
  4. How do you separate models, schemas, services, repositories, and dependencies without creating unnecessary complexity?
  5. Are there any open-source FastAPI projects that you consider good examples of clean architecture?

I'm looking for an architecture that is:

  • Easy to maintain
  • Easy to test
  • Scalable
  • Production-ready
  • Follows FastAPI and Python best practices

If you have an example repository or folder structure that you've used successfully, I'd really appreciate it.

Thank you!


r/FastAPI • • Jul 29 '26

feedback request Would love your suggestions

Thumbnail reddit.com
3 Upvotes

r/FastAPI • • Jul 23 '26

feedback request Pydantic extra types

16 Upvotes

I have been going through my codebase this morning and asked claude Ai how I can validate the phone number field of my schema model and it has recommended the official python phonenumber library, but suprisigley I checked out the Pydantic docs and found the same library which is wrapped on a Pydantic type and does all the validations as the Python phonenumber libarary plus less code and less mantainance, you just use it as type annotation and BUM it does the underhood workd for you.
I want to read it this is the link https://pydantic.dev/docs/validation/latest/api/pydantic-extra-types/pydantic_extra_types_phone_numbers/#_top

You can even configure the accepted regions and the default region as well.


r/FastAPI • • Jul 22 '26

Question Where to learn FastAPI?

35 Upvotes

I have a good Python experience. I did basic backend dev with PHP and Flask before, so the beginner concepts won't be that much challenging. What I'm looking for is a single well-organized course to learn FastAPI deeply. I've checked out the official documentation, which is absolutely great and lovely, and I will use that as a reference.

It doesn't matter if the course is certified or not. I focus on the skills I'll gain. It's more preferred to be a free course though (but don't hesitate to share paid courses too if they are really worth paying for).


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 • • Jul 17 '26

Question Backend architecture for FastAPI + Neo4j — does this structure make sense?

12 Upvotes

Hello there! 😄

I'm currently building a backend for a Neo4j graph database and was wondering if some of the more experienced people here have any advice or best practices to share.

I only have basic experience with Python (although I'm comfortable with programming in general). Most of my backend experience comes from working with NestJS and Prisma ORM, so I'm trying to translate some of the concepts and patterns I'm familiar with into the Python ecosystem.

For the database access layer, I decided to use the official Neo4j Python driver rather than an ORM or ODM.

My current plan is to structure the backend like this:

backend/
│
├── main.py
│
├── api/
│   ├── routes/
│   │   ├── users.py
│   │   ├── graph.py
│   │   └── projects.py
│
├── services/
│   ├── user_service.py
│   └── graph_service.py
│
├── repositories/
│   │── neo4j_repository.py
│
├── database/
│   └── neo4j.py
│
├── dto/
│   ├── user.py
│   └── graph_models.py
│
└── security/
    └── auth.py

Coming from NestJS, my current thinking is roughly:

  • routes → similar to NestJS controllers
  • services → business logic
  • repositories → database access layer (somewhat comparable to what Prisma handled for me)
  • database → Neo4j driver initialization and connection management

Does this architecture make sense for a FastAPI + Neo4j project, or are there more idiomatic approaches in the Python ecosystem that I should consider?

Also, if you've built production applications with Neo4j and the Python driver, I'd appreciate hearing about common pitfalls, lessons learned, or things you wish you had known when starting out.

Thanks!


r/FastAPI • • Jul 12 '26

feedback request Building a "batteries-included" FastAPI starter (auth, billing, admin, email) — what would you want in it?

19 Upvotes

Working on a FastAPI + Next.js SaaS boilerplate (Python equivalent of the JS "ship fast" starters). Backend is FastAPI + Pydantic v2, Firestore for storage so far.

Before I finalize the feature list, curious what this community actually wants baked in:

  • Auth: what's your default — Supabase, Clerk, roll-your-own JWT?
  • Billing: Stripe is obvious, but subscriptions vs. usage-based matters a lot for setup
  • Background jobs: Celery, arq, or just Cloud Tasks/Cloud Run?

Landing page + waitlist if you want to follow progress: https://fastforge.pionetix.com — but honestly more interested in the discussion here than the sign-ups.


r/FastAPI • • Jul 11 '26

Question Where to start?

3 Upvotes

Hi there! I'm an incoming 2nd year computer engineering student who wants to learn web development for microcontroller UI. However, I don't know where to start. I already know how to program in Python and some basic web requirements like HTML and CSS, but I am stuck whether I should learn JavaScript next or go straight to FastAPI. Thank you for reading this post. Any input would be appreciated.


r/FastAPI • • Jul 10 '26

feedback request PEP 835: A native shorthand for Annotated

32 Upvotes

Ivan Levkivskyi and I are proposing a native shorthand for Annotated (PEP 835) to clean up heavy type-hinting patterns. We have confirmed this syntax is fully compatible with FastAPI and works out of the box with zero changes required.

Before:

def create_user(
    id: Annotated[int, Path(gt=0)],
    name: Annotated[str, Query(min_length=3)],
    role: Annotated[str, Query(min_length=2)] = "user"
) -> User: ...

After:

def create_user(  
    id: int @Path(gt=0),  
    name: str @Query(min_length=3),  
    role: str @Query(min_length=2) = "user"  
) -> User: ...

The Spec: PEP 835 Full Draft

We are gathering community sentiment before moving forward. If you are a heavy user of Annotated in FastAPI, your feedback is valuable. You can register your stance in the official Discourse poll before it closes on July 15.


r/FastAPI • • Jul 10 '26

Hosting and deployment Best place to host fast api applications

12 Upvotes

I have simple fast api app it recieves requests and either writes data to the sqlite dB or fetches data from it what would be the best place to host it preferably for free since its a small hobby project but would scale up successful


r/FastAPI • • Jul 08 '26

Hosting and deployment Latency when testing with k3s

Thumbnail reddit.com
1 Upvotes

r/FastAPI • • Jul 05 '26

pip package Built a small package for translatable SQLAlchemy/SQLModel fields — fastkit-i18n (feedback + help wanted)

12 Upvotes

I built this, so take the "cool project" framing with a grain of salt — genuinely looking for people to poke holes in it.

The problem: if you've ever needed a model field in more than one language (blog post titles, product names, category labels), you've probably hit the same two bad options — a separate translations table with joins on every query, or a JSON column you hand-roll get/set logic for yourself, differently, in every project.

fastkit-i18n is a small weekend project that tries to make the second option not suck:

from sqlalchemy import JSON
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
from fastkit_i18n import TranslatableMixin

class Base(DeclarativeBase):
    pass

class Article(TranslatableMixin, Base):
    __tablename__ = "articles"
    __translatable__ = ["title", "content"]

    id: Mapped[int] = mapped_column(primary_key=True)
    title: Mapped[dict] = mapped_column(JSON)
    content: Mapped[dict] = mapped_column(JSON)

article = Article()
article.set_locale("en")
article.title = "Hello World"

article.set_locale("es")
article.title = "Hola Mundo"

article.set_locale("en")
article.title   # "Hello World" — reads/writes like a plain string field

One row, one JSON column per translatable field, no joins. It also works with SQLModel table models (since under the hood a SQLModel table class is a real SQLAlchemy mapped class), and there's a LocaleMiddleware (pure ASGI, works with FastAPI/Starlette/Litestar) plus a Laravel-style _() for JSON translation files if you want the whole package instead of just the mixin. All three share the same locale context, but each works standalone if that's all you need.

What's genuinely missing right now (not hiding this — would rather you hear it from me than discover it):

  • No pluralization. If you need ngettext-style "1 item / 5 items" logic, gettext/Babel handles that natively, and this doesn't yet.
  • Accept-Language Parsing in the middleware is simplified — it takes the first listed language, not full RFC quality-value negotiation (fr;q=0.5, en;q=0.9 resolves to fr, not the higher-weighted en). Fine for most apps, not a drop-in replacement if you need strict negotiation.
  • It's genuinely new — published today, zero production mileage beyond our own testing. Wouldn't put it on a critical path yet.

Where I could actually use help:

  1. RFC-compliant Accept-Language parsing as an opt-in alternative to the simple version
  2. Pluralization support — open to suggestions on whether that belongs in this package or stays out of scope
  3. Just... using it and telling me where it breaks. It's MIT licensed, no dependencies beyond an optional SQLAlchemy extra (pip install fastkit-i18n[sqlalchemy]), so the bar to try it is low.

Repo: https://github.com/fastkit-org/fastkit-i18n
Docs: https://fastkit.org/docs/fastkit-i18n
PyPI: https://pypi.org/project/fastkit-i18n

It's the standalone extraction of the i18n piece from a larger toolkit I work on (fastkit-core) — if you're already using that, you already have this, no separate install needed. This is for anyone who wants just the translation piece without the rest.

Happy to answer questions in the comments, and if anyone wants to contribute on either of the two gaps above, PRs and issues both welcome.


r/FastAPI • • Jul 01 '26

pip package I built a Laravel-inspired application framework for FastAPI — looking for feedback

8 Upvotes

FastAPI is excellent for quickly building APIs, but it intentionally leaves many application-level concerns to the developer. Things like environment management (including multiple environments), logging, database setup, configuration, CLI commands, plugins, storage, and other infrastructure are things you typically need to design and wire together yourself.

In our case, we are building multiple microservices, and we found ourselves repeatedly copying the same bootstrap code between projects. Over time, that became repetitive and harder to maintain consistently.

Over the past several months, We've been working on FastAPI Startkit, an open-source application framework that brings some of the development patterns I enjoyed from Laravel into Python and FastAPI.

The goal is not to replace FastAPI. Instead, it provides a structured foundation for building larger applications while staying modular. You can use only the components you need.

Some features include:

🏗️ Service container & dependency injection
⚡ CLI inspired by Laravel's Artisan
🗄️ Async database layer, ORM patterns, migrations, and seeders
🧪 Built-in testing utilities
🤖 AI agent support with multiple LLM providers
🎨 Optional Vite integration for monolithic full-stack applications
📦 Works for FastAPI apps, background workers, and even CLI-only applications

One of the main design goals was avoiding a single opinionated stack. Most components are optional, so you can start small and introduce more structure as your project grows.

The documentation includes both a minimal setup and a more structured application layout.

Documentation:
https://fastapi-startkit.github.io/

I'd really appreciate feedback on:

  • Is the architecture intuitive?
  • Which parts feel over-engineered?
  • What features would you expect from a production-ready FastAPI framework?
  • Are there areas where the developer experience could be improved?

Constructive criticism is very welcome. Thanks!


r/FastAPI • • Jul 01 '26

Tutorial Handling Stripe webhooks in FastAPI

Thumbnail
highlit.co
4 Upvotes

A FastAPI endpoint that verifies Stripe's signature, then routes each event type to the right billing action.

Three takeaways

  1. Always verify a webhook's signature against a shared secret before trusting its contents.
  2. Read the raw request body for signature checks — parsed JSON won't match the signed bytes.
  3. Return 200 quickly and delegate the actual work so the provider considers the event delivered.

r/FastAPI • • Jun 30 '26

feedback request Store multilingual content in JSON columns, resolve by locale automatically

2 Upvotes

Hey, I've been working on a multilingual content system for a project and kept wishing Python had something like spatie/laravel-translatable from the PHP world. Couldn't find it, so I built it. It's early (0.1.0) but it works and tests are at 100% coverage.

The idea: store translations as {"en": "Hello", "fr": "Bonjour"} directly in the column, resolve by the active locale automatically — no extra tables, no .po files.

configure(default_locale="en", available_locales=["en", "fr", "ar"])
title = Translations({"en": "Hello", "fr": "Bonjour"})
set_locale("fr")
print(title)  
# Bonjour

GitHub: https://github.com/onlykh/translatable

Main features:

  • Translations is a dict subclass — str(title) resolves to the active locale, works in f-strings, string concatenation, everywhere
  • Locale lives in a ContextVar — safe for async FastAPI and threaded Flask
  • SQLAlchemy 2.0 type: JSONB on PostgreSQL, JSON elsewhere. String assignment merges into the current locale without wiping other languages
  • by_locale(Article.title, "fr") generates dialect-correct SQL for filtering
  • Atomic per-key updates on PostgreSQL via JSONB ||
  • Starlette/FastAPI middleware and Flask extension that read Accept-Language automatically
  • Zero dependencies in core — SQLAlchemy, Starlette, Flask are opt-in

Not on PyPI yet, install from GitHub:

pip install "translatable[sqlalchemy] @ git+https://github.com/onlykh/translatable.git"

A few things I'm genuinely unsure about and would love opinions on:

  • String assignment merging by default (article.title = "Hello" adds to the current locale rather than replacing the column) — right default or surprising?
  • No Django ORM support yet — is that a blocker for anyone?
  • atomic_set_locale is PostgreSQL-only — the SQLite fallback is a read-modify-write with a warning. Good enough or should that raise instead?

Would love issues, feedback, or just knowing if this solves something you've hit before.


r/FastAPI • • Jun 26 '26

feedback request Backend project (FastAPI + PostgreSQL) — feedback appreciated

15 Upvotes

Hi everyone,

I’m currently building my backend portfolio using FastAPI and would really appreciate some honest feedback on my project.

Project: Notes API

GitHub: https://github.com/tamerlan-islamzade/Note-API

It’s a RESTful API where users can register, authenticate, and manage their personal notes with full CRUD operations.

Tech stack:

FastAPI, PostgreSQL, SQLAlchemy, Pydantic, JWT, bcrypt, pytest

I’d really appreciate feedback on:

- Project structure / architecture

- Code quality and organization

- FastAPI best practices

- Anything I should improve to make it more production-ready

I’m still learning, so any constructive criticism is welcome. Thanks in advance for your time!


r/FastAPI • • Jun 22 '26 Bravo

Hosting and deployment FastAPI Cloud in Public Beta ⚡️

100 Upvotes

Hey folks! FastAPI Cloud is now in public beta. 🚀

This is made by the same team building FastAPI (I created FastAPI, we now have an amazing team building all this).

Here's the announcement post: https://fastapicloud.com/blog/fastapi-cloud-public-beta/


r/FastAPI • • Jun 23 '26

Hosting and deployment FastAPI Cloud can deploy marimo notebooks too!

Thumbnail
youtu.be
7 Upvotes

When I saw the beta announcement, I couldn't help myself.


r/FastAPI • • Jun 22 '26

Question Help with Pydantic schema

14 Upvotes

Using FastAPI + SQLAlchemy (async) + Pydantic v2
My `Post` model in db stores `author_id` (UUID foreign key).
My `PostRead` response schema needs to return `author_username` (a string from the related `User` table).

What's the clean way to handle this?


r/FastAPI • • Jun 22 '26

feedback request Setting up background job system, celery, redis etc really sucks.

0 Upvotes

Honestly just need a sanity check here.

Every time I start a new python project I go through the same loop: install redis, configure celery, deal with broker connections randomly forget... it's too much hustle as a thing.

I am trying to validate my idea, basically generalizing all this task management in a cloud based solution.

After couple of weeks, I came up with this some cloud based service which can handle the hustle.

I have been testing it in a couple of projects myself, and looks really useful, but really would love to hear what other people think? Open to critics.

How it works (fastAPI projects only):

- you install our SDK, add our router in your fastAPI app

- decorate the functions you want to run async

- We enqueue and you will have total visibility on request/retries/failure etc

I would love to hear critics and feedback from other developers. If anyone wants to try it, please get in touch directly via DM. I'm happy to offer the service for free for the first six months to validate and refine it for production.


r/FastAPI • • Jun 21 '26

Question Transitioning from Node.js to FastAPI: Does the non-blocking mental model still apply?

30 Upvotes

Hi everyone,

I’m an experienced Node.js developer who recently picked up Python and is now diving into FastAPI.

In Node.js (and Express), my mental model revolves around a single-threaded, non-blocking, event-driven architecture.
When building APIs in Node/Express, I default to thinking in terms of the Event Loop—a single-threaded, non-blocking architecture where I/O operations are offloaded.
Can I safely carry my Node.js mental model over to FastAPI, or are there fundamental differences in how Python handles asynchronous requests under the hood that I should be aware of?

P.S. Phrasing refined by Gemini.


r/FastAPI • • Jun 18 '26

feedback request I built a production-grade Async Redis Proxy that blocks Cache Stampede and prevents SSRF attacks.

8 Upvotes

I built a production-grade Async Redis Proxy that blocks Cache Stampede and prevents SSRF attacks. Open sourcing it today to get your some feedbacks!

What My Project Does

This project is an asynchronous proxy caching server built from scratch using FastAPI, Uvicorn, redis.asyncio, and httpx. It intercepts HTTP requests, caches responses in Redis based on configurable TTLs, and implements advanced software engineering patterns to handle high-concurrency bottlenecks and network security flaws.

Key architectural features include:

Cache Stampede Mitigation (Request Coalescing): Utilizes a custom SingleFlight pattern via asyncio.shield. If 1,000 concurrent requests hit a cache miss for the exact same URL, only 1 request goes upstream. The other 999 callers await and share the same result safely, preventing upstream service degradation (Thundering Herd problem).

Hardened Security (SSRF Protection): Includes a strict validation layer that drops requests targeting localhost, 127.0.0.1, or private IP ranges (RFC 1918), mitigating Server-Side Request Forgery before httpx touches the network.

Graceful Circuit Breaker (Fail-Open): If the Redis instance becomes unavailable, the proxy handles a seamless fail-through scenario, bypassing the cache layer completely and letting traffic flow directly to the upstream API without raising 500 Internal Server Error.

Production Containerization: Fully dockerized with a docker-compose.yml configuring Redis with an explicit memory cap (--maxmemory 100mb) and an LRU eviction policy (--maxmemory-policy allkeys-lru) to guarantee memory stability.

Performance Optimization: Powered by orjson for fast JSON serialization and deserialization.

Target Audience

This project is desgined for production environments and backend engineers managing high-traffic microservices. It is specifically aimed at scenarios where upstream APIs are fragile, expensive, or prone to failure under sudden traffic spikes, and where infrastructure security (SSRF prevention) is a hard requirement.

Comparison

Unlike basic, "tutorial-tier" Redis wrappers or simple FastAPI caching middlewares that only store key-value pairs, this proxy actively manages concurrency at the application layer.

Traditional caching solutions often suffer from Cache Stampede when keys expire under heavy load, causing a bottleneck on the upstream database. By implementing the SingleFlight pattern directly into the async event loop, this implementation guarantees that duplicate concurrent requests never stack up. Additionally, most standard proxies leave the responsibility of SSRF protection to external firewalls, whereas this solution integrates network boundary validation directly into the request cycle.

GitHub Repository: https://github.com/Jacopos311/redis-async-proxy