r/FastAPI • • Nov 19 '22

Question Fastapi with azure service bus

1 Upvotes

I'm looking to use a queuing service with FastAPI. I don't want to create two additional apps with celery and flower, but looking to integrate an azure service that could work as a queue, and am looking towards using azure service bus.

In order to use this I need to create a consumer that checks for new messages. Is it architecture wise OK to create a separate thread where this consumer lives? I have something simple working like this in my main file. I could also add this to a startup event

def receiving(Receiving = True):
 while Receiving:
     with ServiceBusClient.from_connection_string(connstr) as client:
         with client.get_queue_receiver(queue_name, max_wait_time=30) as receiver:

             for msg in receiver: 
                 print(f"{datetime.now()}: {msg}")
                 receiver.complete_message(msg)

t1 = Thread(target=receiving) t1.start()

Is this something that is desirable or would this lead to performance issues?


r/FastAPI • • Apr 06 '23

Question How to get Headers from incoming request?

0 Upvotes

I have been looking online and foudn no answer for this, which i assume must be a pretty simple requirement.

How can I get one or all the headers from an incoming request to a POST endpoint?


r/FastAPI • • Sep 09 '24

Hosting and deployment Deploying FastAPI on AWS Lambda

1 Upvotes

I am trying to deploy a fastapi with Google Gemini API. I have done a lot of debugging the past couple of days and seem like Google Gemini libraries are giving me errors inside aws lambda. I just created a dependencies folder and zipped everything with my main.py inside it and deployed on aws lambda. And I keep getting different sort of libraries not being imported errors. Also I am using python 3.10 and used magnum. Anyone has any suggestions what I could do or if this is even compatible with aws lambda, I read people talking about uploading through docker and ECR or using Fargate.


r/FastAPI • • May 30 '21

Question question about fastapi and sqlalchemy

0 Upvotes

i am new to the SQLalchemy and fastapi libraries and i wonder if we can use sqlalchemy directly to connect to a database without the fastapi ? if no why ? i mean why would i add a third party in my connection to the database if i can read and put data using only sqlalchemy ?

reminder : i am new to working with apis and databases with python and i am working on a project with fastapi and sqlalchemy used


r/FastAPI • • Oct 15 '21

Question Pydantics relation with FastAPI?

1 Upvotes

I was just wondering what the deal is with Pydantic. Is it built into FastAPI or is it just like a closely tied partner library?

Mentioned everywhere in the docs and at first I thought these were FastAPI features, but realized they were actually from this other library.

For example could you run FastAPI and all it's features without using any Pydantic? (Not that I want to, just curious). I feel like the dependency injector system might depend on it but not sure.


r/FastAPI • • May 19 '26

feedback request fastapi-url-shortener

Thumbnail
github.com
0 Upvotes

r/FastAPI • • Jun 05 '26

Question Is FastApi strong and secure for production ?

0 Upvotes

I’m building a company monitoring app that reads Firebase data coming from multiple bus DMS devices and returns KPIs for a Svelte dashboard. Is FastAPI a good backend choice for this, especially for a secure, production-ready, scalable, and maintainable API? I also need a good FastAPI template or guide to start from, a secure way to connect it with Firebase, and the best way to package the app for both Windows and Android. What I need to use ?


r/FastAPI • • Mar 17 '26

Question I built a platform to help devs find teams, and I just added a built-in Real-Time Cloud IDE synced with GitHub

1 Upvotes

Hey everyone,

I've been working on CodekHub, a platform to help developers find teammates and build projects together.

The matchmaking part was working well, but I noticed a problem: once a team is formed, collaboration gets messy (Discord, GitHub, Live Share, etc.).

So I built a collaborative workspace directly inside the platform.

Main features:

  • Real-time code collaboration (like Google Docs for code)

  • Auto GitHub repo creation for each project

  • Pull, commit, and push directly from the browser

  • Integrated team chat

  • Project history with restore functionality

Tech stack: I started with Monaco Editor but ran into a lot of issues, so I rebuilt everything using CodeMirror 6 + Yjs. Backend is FastAPI.

The platform is still early, and I’d really love some honest feedback: Would you use something like this? What would you improve?

https://www.codekhub.it


r/FastAPI • • Jan 10 '25

Other Real world scenario FastAPI vs Node.js k8s cluster benchmarks

26 Upvotes

Here is a video comparing FastAPI vs node.js and you can clearly see the performance difference between them.

FastAPI is clearly writing false advertisement on their site !

Same machine resources, using the same Redis/DB instance real time. It’s closest as possible to a modern prod environment. And FastAPI is not at all close to being as fast as NodeJS, as said on the site.

https://m.youtube.com/watch?v=i3TcSeRO8gs

Disclaimer:

On the site it does talk about actual performance of code not about how fast you can develop an app with it.

Quote from the oficial site (https://fastapi.tiangolo.com/) :

“Fast: Very high performance, on par with NodeJS and Go (thanks to Starlette and Pydantic). One of the fastest Python frameworks available.

Fast to code: Increase the speed to develop features by about 200% to 300%. *”

See the difference between “Fast” and “Fast to code”

Edit: there’s also one for Golang:

https://m.youtube.com/watch?v=sxdpKG-6HSY

And as you can see actually the number between Golang and Nodejs are not that far away, they are both far away from the claims from the site.

Simple test: Nodejs: 50k Golang: 65k Fastapi: 11k

DB/Redis: Nodejs: 9k Golang: 18k Fastapi: 2.5k


r/FastAPI • • Sep 28 '25

feedback request FastAPI setup with no ORM

7 Upvotes

I have this simple setup to connect to postgres without any ORM. I'd love some suggestion how to improve this

https://github.com/NepNepFFXIV/fastapi_no_orm


r/FastAPI • • Oct 10 '26

Tutorial I built a self-hosted proxy, and the most interesting part turned out to be the FastAPI permissions

0 Upvotes

Coming from Django, the thing I missed most in FastAPI wasn't the ORM or the admin. It was user.has_perm("app.add_thing"): users, groups, per-action permissions, superuser. FastAPI gives you Depends and leaves the rest to you. The libraries I found were either JWT-only or full policy engines like Casbin.

So for my project's admin API I rebuilt Django's model in plain FastAPI + SQLAlchemy, and changed a few things on the way.

What I kept from Django

  • Permissions named resource.action: traffic.view, certificates.add

  • Groups of permissions, plus permissions given to a user directly

  • An is_superuser flag that has everything

The tables are basically Django's auth_group_permissions, auth_user_groups and auth_user_user_permissions.

What I changed

1. Permissions are an enum in code, not rows in a table

Django generates permission rows through migrations. Here the code is what checks them, so the list lives in code and the DB only stores who has what:

class Permission(StrEnum):
    TRAFFIC_VIEW = "traffic.view"
    CERTIFICATES_ADD = "certificates.add"
    ...

2. Each use case declares what it needs, like permission_required

class CreateTrustedNetworkService(BaseUserAuthenticatedService[CreateTrustedNetworkResponse]):
    required_permissions: ClassVar[frozenset[Permission]] = frozenset({Permission.TRUSTED_NETWORKS_ADD})

The base class decodes the JWT, loads the user and their permissions in one UNION query, and returns 403 with what's missing. The route only passes the token and the body.

3. Why not Depends(require(...))

On purpose. Permissions belong to the use case, not to the URL:

  • The escalation check below needs the user's permissions inside the logic anyway. A dependency would just be a second place for the same thing.

  • A service is tested without HTTP, and the check can't be lost by forgetting a dependency on a new route.

  • OpenAPI still knows: every route documents its 403 with the exact permission, e.g. "The user lacks trusted_networks.add."

4. No privilege escalation

This is the part Django warns about in its own docs: if a user can edit users, they can give themselves superuser. Here you can only give what you have:

missing = self.data.permissions - self.permissions
if missing:
    raise HTTPException(403, f"You can't give permissions you don't have: {', '.join(sorted(missing))}.")

This applies to groups, users, adding someone to a group, and even changing another user's password, since otherwise you could just log in as them. (create_group, update_group, create_user)

5. Revoking access takes effect on the next request

Permissions aren't stored in the JWT. They're read on every request, so if you remove someone from a group, their next call fails.

Where it lives

This is the admin API of Proxium, a self-hosted HTTP/SOCKS5 proxy with accounts, quotas and speed limits. Support gets "revoke accounts", accounting gets "view traffic", and neither can touch certificates. One Docker image runs everything, so you can try to break the permissions yourself:

docker run -d --name proxium -p 80:80 -p 8080:8080 -v proxium:/var/lib/proxium \
  -e SUPERUSER_CREATE=true -e [email protected] -e SUPERUSER_PASSWORD=change-me \
  ikoldakov/proxium

If you'd still put it in Depends, change my mind in the comments.

Next on the API side: SSO for the admin over OIDC and an API for merchants. If either sounds fun, the roadmap has the rest, and the code is MIT: https://github.com/koldakov/proxium


r/FastAPI • • Jul 04 '25

Question API ideas that can generate income

15 Upvotes

I’m a CS student and I have recently made some side projects APIs with fastapi, Postgres, docker and stripe for payments. I’m wondering what are some API ideas that companies and devs will be willing to pay for and if there is a market for this. I’m not trying to make millions just a side income and get experience and launch in platforms such as rapidapi. What are some features that would make paying for the API an no brainer


r/FastAPI • • Dec 19 '25

feedback request FastAPI operator

0 Upvotes

Would you see useful having a FastAPI Kubernetes Operator to deploy production ready FastAPI instances with some constraints?

Those instances must be stateless, single container with some other potential restrictions in the contract, and the potential CRD could look like this:

apiVersion: platform.fastapi.dev/v1alpha1 kind: FastAPIApp metadata: name: users-api namespace: apps spec: image: ghcr.io/acme/users-api:1.2.3

http: port: 8000 path: /

resources: cpu: 500m memory: 512Mi

scaling: minReplicas: 1 maxReplicas: 5 targetCPUUtilization: 70

env: - name: ENV value: production

secrets: - name: DATABASE_URL secretRef: name: users-db key: url

(Edit: can’t properly format the yaml, sorry)


r/FastAPI • • Dec 25 '25

Tutorial Visualizing FastAPI Background Tasks & Task Queues

Post image
59 Upvotes

r/FastAPI • • Dec 29 '25

Question FastAPI and HTMX Are We Seeing the Next Big Shift in Full-Stack Python?

51 Upvotes

Hey r/FastAPI,

I’ve been noticing something lately HTMX is blowing up.
It feels like the frontend world is pushing back against heavy JavaScript frameworks, and a lot of devs are leaning into simple, server-driven frontends again. That got me thinking: Is FastAPI + HTMX becoming the modern, Pythonic answer to full-stack development?

Think about it:

  • FastAPI handles the backend with insane speed (thanks to async and ASGI).

  • HTMX handles the frontend by swapping HTML over the wire no massive JS bundles.

  • You write mostly Python, sprinkle minimal JS when needed, and still get reactive, dynamic interfaces.

  • Deployment stays simple. It’s just… HTTP.

It feels like the perfect stack for building fast, maintainable, and simple web apps without drowning in tooling. I recently rebuilt a small project with FastAPI + HTMX after doing it in React + FastAPI before. The difference in complexity was staggering. Fewer moving parts, faster iterations, and the performance was

So I’m curious:

  • Is anyone else using FastAPI with HTMX (or similar libraries like Alpine.js)?

  • Are we at the start of a quiet revolution in full-stack Python?

  • Or is this just a niche trend that’ll fade?

If you’ve tried it, share your experience


r/FastAPI • • May 03 '25

Question How well did FastAPI do in AI?

2 Upvotes

Hello, I’m a PHP-Laravel developer and wanted to learn about AI. I want to start on integrating AI APIs available out there and I’m convinced Laravel is not the best framework to do it. I’ve heard FastAPI is a good framework for this. I just learned the basics of Python and I wanna know if any of you already did this kinds of projects. How did it go for you?


r/FastAPI • • Feb 15 '22

feedback request A FastAPI's dependency injection clone

Thumbnail self.python
2 Upvotes

r/FastAPI • • Oct 26 '25

Question Should I avoid query parameter in FastAPI?

Thumbnail reddit.com
2 Upvotes

r/FastAPI • • Feb 13 '26

Question Does anyone have real-world experience with fast-saas

2 Upvotes

I was searching for a SaaS template for FastAPI and there have been a few posted here, and I am looking at each of them, but my search outside of Reddit led me to https://www.fast-saas.com/.

- has anyone here used it? If so, any good or bad feedback would be appreciated. I emailed them earlier today but I have not gotten a response. Could be that it's Friday and maybe they are already on their weekend.

- does anyone have a production site built with fast-saas that they would be willing to post a link to so I can evaluate it in the wild?

Thanks in advance


r/FastAPI • • Feb 24 '26

Other Piattaforma per programmatori

0 Upvotes

Sto sviluppando una piattaforma che permette a sviluppatori e studenti di ingegneria di collaborare facilmente a nuovi progetti. Visto che sono circa a metà volevo sapere a quanti di voi potrebbe interessare. È una specie di social per programmatori con matchmaking per nuovi progetti di studio o reali. E ranking basato su recensioni. Fatemi sapere se la usereste💪


r/FastAPI • • Feb 05 '26

Question For a developer in India with 1-2 years experience, what would you focus on in 2026 to stay relevant?

Thumbnail reddit.com
0 Upvotes

r/FastAPI • • Mar 13 '26

pip package Why fastapi-guard

25 Upvotes

Some of you already run fastapi-guard. For those who don't... you probably saw the TikTok. Guy runs OpenClaw on his home server, checks his logs. 11,000 attacks in 24 hours. I was the one who commented "Use FastAPI Guard" and the thread kind of took off from there. Here's what it actually does.

from guard import SecurityMiddleware, SecurityConfig

config = SecurityConfig(
    blocked_countries=["CN", "RU"],
    blocked_user_agents=["Baiduspider", "SemrushBot"],
    block_cloud_providers={"AWS", "GCP", "Azure"},
    rate_limit=100,
    rate_limit_window=60,
    auto_ban_threshold=10,
    auto_ban_duration=3600,
)

app.add_middleware(SecurityMiddleware, config=config)

One middleware call. 17 checks on every inbound request before it hits your path operations. XSS, SQL injection, command injection, path traversal, SSRF, XXE, LDAP injection, code injection. The detection engine includes obfuscation analysis and high-entropy payload detection for novel attacks. On top of that: rate limiting with auto-ban, geo-blocking, cloud provider IP filtering, user agent blocking, OWASP security headers.

Every attack from that TikTok maps to a config field. Those 5,697 Chinese IPs? blocked_countries. Done. Baidu crawlers? blocked_user_agents. The DigitalOcean bot farm? Cloud provider ranges are fetched and cached automatically, blocked on sight. Brute force sequences? Rate limited, then auto-banned after threshold. .env probing and path traversal? Detection engine catches those with zero config.

The OpenClaw audit makes it worse. 512 vulnerabilities across the codebase, 8 critical, 40,000+ exposed instances. 60% immediately takeable. ClawJacked (CVE-2026-25253) lets any website hijack a local instance through WebSocket. If you're exposing FastAPI endpoints to the internet, you need request-level security.

Decorator system works per-route, async-native:

from guard.decorators import SecurityDecorator

guard_decorator = SecurityDecorator(config)

@app.get("/api/admin")
@guard_decorator.require_ip(whitelist=["10.0.0.0/8"])
@guard_decorator.block_countries(["CN", "RU", "KP"])
async def admin():
    return {"status": "ok"}

What people actually use it for: startups building in stealth mode with remote teams, public API but whitelisted so nobody outside the company can even see it exists. Casinos and gaming platforms using decorators on reward endpoints so players can only win under specific conditions. Honeypot traps for LLMs and bad bots that crawl and probe everything. And the one that keeps coming up more and more... AI agent gateways. If you're running OpenClaw or any agent framework on FastAPI, those endpoints are publicly reachable by design. The audit found 512 vulnerabilities, 8 critical, 40,000+ exposed instances. fastapi-guard would have blocked every attack vector in those logs. This is going to be the standard layer for anyone deploying AI agents in production.

I also just shipped a Flask equivalent if anyone's running either or both. flaskapi-guard v1.0.0. Same detection engine, same pipeline, same config field names.

fastapi-guard: https://github.com/rennf93/fastapi-guard flaskapi-guard: https://github.com/rennf93/flaskapi-guard flaskapi-guard on PyPI: https://pypi.org/project/flaskapi-guard/

If you find issues with either, open one.


r/FastAPI • • May 01 '26

Hosting and deployment [FOR HIRE] Python Developer | FastAPI REST APIs | Authentication | CRUD | Docker | Remote

0 Upvotes

I build clean, production-ready REST APIs with FastAPI. JWT auth, CRUD, PostgreSQL, Dockerized and ready to deploy.

Portfolio: https://github.com/IlkinCavadov

Open to small and medium projects. Feel free to DM me!


r/FastAPI • • May 22 '26

pip package I built a single Python file that turns a PRD into a working FastAPI app (auth, CRUD, Alembic, /docs) — zero ▎ dependencies, MIT

0 Upvotes

Been building Archiet (a full PRD-to-code platform) and wanted to distill the core algorithm into something any developer can read and use.

Result: microcodegen.py — one file, ~1,400 lines, pure stdlib. Inspired by Karpathy's micrograd philosophy.

What it does:

Write a plain-English PRD with entities and user stories. Run the script. Get a ZIP containing a bootable FastAPI

project:

- SQLAlchemy 2.0 models (one per entity)

- Pydantic v2 schemas (Base/Create/Update/Response)

- JWT auth via httpOnly cookies — never localStorage

- Full CRUD APIRouters, all behind Depends(get_current_user)

- Per-tenant data isolation (user_id FK on every table, every query filters it)

- Alembic migrations pre-configured

- pytest conftest that auto-skips if Postgres isn't running

- docker-compose.yml with Postgres 16 healthcheck

- openapi.yaml + ARCHITECTURE.md with ArchiMate element typing

Zero LLM calls. Zero API keys. Runs offline.

Quickstart:

git clone https://github.com/Anioko/microcodegen

python microcodegen.py examples/task_manager.md --out ./my-app

cd my-app && pip install -r requirements.txt

alembic upgrade head && uvicorn main:app --reload

# → http://localhost:8000/docs

Or:

pip install archiet-microcodegen

archiet-microcodegen prd.md --out ./my-app

GitHub: github.com/Anioko/microcodegen

MIT licensed. Happy to answer questions about the implementation — the four-stage pipeline (parse → genome IR → render→ pack) is all readable in one file.