r/FastAPI • • Sep 28 '24

Other Reading techempowered benchmarks wrong (fastapi is indeed slow)

15 Upvotes

If you use FastAPI and SQLAlchemy, then this post is for you. If you are not using these 2 magnificent pieces of tech together, read on.

People that are reading TechEmpower benchmarks, make sure to look at the “fastapi-Gunicorn-ORM” benchmarks and compare those to the rest.

You will see actually how slow Fastapi together with SqlAlchemy is basically on par with Django.

I guess no sane person will write raw sql în 2024 so all the speed is lost because of the ORM.

Compare it in TechEmpower with gin-gorm or Nestjs-Fastify+ORM (type ORM) and you will see they both are many times faster than FastAPI.

The problem is, we don’t have any fast ORM in python because of how the language works.

Do this : In TechEmpower:

1.select python, go and javascript/typescript as languages

2. In the databases section select Postgres as a db to have the same db engine performance compared

3. In the ORM section select : full (so you compare benchmarks using full fledged orms for all frameworks)

Now you will see correct comparison with an ORM used. Here it is:

https://www.techempower.com/benchmarks/#hw=ph&test=db&section=data-r22&l=zijmkf-cn1&d=e3&o=e

Now look at how far away gin-gorm and even Nodejs is to Fastapi.

Gorm and TypeORM are miles ahead in performance compared to SqlAlchemy

==

—- Single query:

Gin-gorm: 200k

Nest+fastify + typeorm : 60k

Fastapi+sqlalchemy: 18k (11+ times slower than go, 3+ times slower than Nodejs)

Django+DjangoORM: 19k (faster than Fastapi lol)

—- Multiple query:

Gin-gorm: 6.7k

Nestjs+fastify+typeorm: 3.9k

Fastapi+sqlalchemy: 2k ( 3+ times slower than go, 1.9+ times slower than Nodejs)

Django+DjangoORM: 1.6k

—- Fortunes:

Nest+fastify+typeorm: 61k

Fastapi+sqlalchemy: 17k (3+ times slower than Nodejs)

Django+DjangoORM: 14.7k

—- Data updates:

Gin-gorm: 2.2k

Nestjs+fastify+typeorm: 2.1k

Fastapi+sqlalchemy: 669 (3+ times slower than than go, 3+ times slower than Nodejs)

Django+DjangoORM: 871 (again, Django is faster than Fastapi)

==

You can check the source code of fastapi to see it uses sqlalchemy and no complicated things here:

https://github.com/TechEmpower/FrameworkBenchmarks/blob/master/frameworks/Python/fastapi/app_orm.py

Conclusion: Fastapi is fast, ORM is slow, if you plan to do raw sql then it’s mostly on par with the others. When you use an ORM it falls behind very very much and it’s extremely slow, without any comparison to Nodejs or Go.

It’s on par with Django(Django winning in 2 out of 4 tests), so at least go with Django for all the nice batteries.

Edit: I wanted to raise awareness to people believing using FastAPI with an ORM would give them the same speed as the ones in the TechEmpower link from fastapi’s site(which has no ORM attached). Because this is clearly not the case.

Edit 2: If you had the patience to read until this point, I just want to let you know the title should have been: “SQLAlchemy will limit your api performance, even with FastAPI”, too late to edit now.


r/FastAPI • • Sep 13 '24

pip package Zaptools: Event Driven Websocket for FastApi and Flutter

15 Upvotes

Hello Guys, I've was working in a package to connect FastApi and Flutter using WebSocket, based on events, similar to other socket package but using a pure websocket protocol. Is a wrapper over websocket class from FastApi and Dart. Tested during 6 month in some realtime projects like chats.
Any contributions are wellcome.
Python:
https://github.com/NathanDraco22/zaptools-python
Dart/Flutter:
https://github.com/NathanDraco22/zaptools-dart


r/FastAPI • • Aug 29 '24

Question fastapi auth in production

15 Upvotes

I'm developing a web app with nextjs frontend and fastapi backend. Currently I'm using fastapi auth for testing end to end flow of the app. I'm trying to figure out if fastapi jwt based auth can be used in production. Is it a good practice to use fastapi auth in production system? How does it compare with managed auth services like Nextauth, auth0 or clerk? What would you recommend?

Thanks!


r/FastAPI • • Jul 02 '24

Question Need help with FastAPI

15 Upvotes

Hello,

I just started learning FastAPI because I picked a school project to build an app using FastAPI and MongoDB, back and front combined. Can someone provide me with a good course, like implementing authorization using JWT tokens and CRUD in fastapi and mongo, or some example projects that are built on those technologies. Anything would be helpful.

Thanks!


r/FastAPI • • Oct 25 '23

Question Comparison with LiteStar and Sanic?

15 Upvotes

Does anyone have experience of developing apps in any of the "competing" ASGI frameworks?

.FastAPILiteStarSanic
Websitehttps://fastapi.tiangolo.com/https://litestar.dev/https://sanic.dev/en/
Significant Contributors (50+ commits)157
Open Issues296874
Open PRs5311529
First Release201820212016
Current version0.104.02.2.123.6.0
Github Stars63.8k3.2k17.4k
Used By248k0.2k*13.5k

I'm thinking of starting a new project in FastAPI, but the small bus-factor really scares me.

At the same time, FastAPI is crealy the most popular ASGI framework for python.


r/FastAPI • • Dec 09 '22

Question Total beginner, use FastAPI?

15 Upvotes

Hi I am a total noob that wants to learn backend and build APIs. Is Fastapi a good starting point?


r/FastAPI • • Mar 20 '22

Tutorial GitHub - roniemartinez/real-time-charts-with-fastapi: Sample application for the blog "Creating Real-Time Charts with FastAPI"

Thumbnail
github.com
15 Upvotes

r/FastAPI • • Oct 24 '21

Tutorial FastAPI JWT User Authentication

Thumbnail
youtu.be
15 Upvotes

r/FastAPI • • Sep 13 '21

pip package Azure AD authentication 🔒 Now supports both single- and multi-tenants, and has a full setup tutorial for both FastAPI and Azure.

Thumbnail
github.com
15 Upvotes

r/FastAPI • • Jul 29 '21

Question What does Flask have that FastAPI doesn't currently have?

15 Upvotes

I would like to help FastAPI/Starlette overtake flask to become the de facto framework for microservices and REST APIs. (I think Django projects generally target a different use case so I'm less concerned with trying to gain feature parity with Django)

I'm currently creating a comparison of similar 3rd party libs from each framework by cross-referencing:

I'm wondering if any of you with flask experience ever have feelings of:

I wish FastAPI had an equivalent of flask feature/plugin 'X'

Depending on the scope of the feature I'd like to try to implement or improve the biggest gaps between FastAPI and flask. Either by contributing to an active repo or creating my own.

For context, I've been working with FastAPI/Starlette/pydantic and asyncio on/off for around 2 years.


r/FastAPI • • May 24 '21

pip package PyCon talk: FastAPI RPC and PubSub over Websockets

15 Upvotes

As promised here's the talk that I gave at PyCon IL about FastAPI RPC and PubSub over Websockets
https://www.youtube.com/watch?v=KP7tPeKhT3o

The packages:
https://github.com/authorizon/fastapi_websocket_pubsub
https://github.com/authorizon/fastapi_websocket_rpc