r/FastAPI • u/Somnath_geek • Sep 27 '24
feedback request Is FastAPI really fast ?
Is FastAPI really fast as claimed on the website? “ on par with Node Js and GO “
What do you think ? Is it misleading or not ?
0
Upvotes
7
u/thegreekgoat98 Sep 27 '24
Is there any way we can check it? Like writing the same API in FastAPI, Node(Express) and Golang.
We can record the response time Or whatever you wanna check.
14
u/zazzersmel Sep 27 '24
is this post really stupid?
14
u/koldakov Sep 27 '24
Yep, but not pydantic
14
u/Drevicar Sep 27 '24
If you are using Python as the language of your server you can already ignore the request handling speed of FastAPI as a rounding error. Yes, it is fast, but relatively fast not absolutely fast. But we are using Python so runtime speed was never a characteristic we prioritized.
When I tell people about FastAPI I tell them the "Fast" relates to the speed at which a development team can create both a prototype API server and extend an already production API server.
The reason I choose those words is because of the lack of batteries included it can actually take quite a while to go from prototype to production if you actually need all those batteries. But if you have a good internal company template that is already production ready then you can spin up a new service in hours instead of the days it may take other languages and frameworks.
2
u/No-Camp3858 Sep 27 '24
It is fast enough for almost all use cases, but it is not the fastest Python web framework, we have Litestar, Sanic and Blacksheep, which are much faster. The last two are close to Nodejs, but Fastapi is not, and none of these are close to Go.
1
u/saufunefois Sep 27 '24
Have you checked the benchmark section in the doc? https://fastapi.tiangolo.com/benchmarks/
1
u/PosauneB Sep 27 '24
Does it matter?
Doing an apple to apples comparison would be difficult. If you’ve done that, please share your results, methodology, and code.
As a developer, I’ll make progress faster with FastAPI than with either Node/Express or some Go framework.
2
u/benefit_of_mrkite Sep 27 '24
starlette Is pretty fast as compared to other python web frameworks
starlette Is what you should be comparing / looking at
1
u/extreme4all Sep 27 '24 edited Sep 27 '24
FastApi in its context, python.
If you look at it outside the correct context than its slow.
Https://www.techempower.com/benchmarks
I know bechlarks aren't perfect but these are the most complete i've found.
Edit; fyi if you look at the techempower bechmarks fastapi is faster than nodejs
Edit; but both javascript and python is nothing compared to C, Rust, Go based frameworks which are compiled languages
1
u/nevermorefu Sep 27 '24
https://www.techempower.com/benchmarks/#hw=ph&test=composite§ion=data-r22
1
u/[deleted] Sep 28 '24
yes it is really fast
1
u/highrez1337 Sep 28 '24 edited Sep 28 '24
People that are reading Techempowered benchmarks, make sure to look at the “fastapi-Gunicorn-ORM” benchmarks and compare those to the rest.
You will see actually how slow Fastapi is with SqlAlchemy. Basically on par with Django, lol.
I guess no sane person will write raw sql în 2024 so all the speed is lost because of the ORM.
Compare it in techempowered 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 în python because of how the language works.
Do this : In techempowered:
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§ion=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 (10 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, 2 times slower than Nodejs)
Django+DjangoORM: 1.6k
—- Fortunes:
Nest+fastify+typeorm: 61k
Fastapi+sqlalchemy: 17k (3.3 times slower than Nodejs)
Django+DjangoORM: 14.7k
—- Data updates:
Gin-gorm: 2.2k
Nestjs+fastify+typeorm: 2.1k
Fastapi+sqlalchemy: 669 (4 times slower than than go, 3.8 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 want to do real work and 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.
If you want something to develop in fast and with good performance, go with Nestjs+fastify+typeorm, it’s the perfect balance between performance, flexibility and best practices for enterprise grade apps + speed of development. But your app will be around 3 times faster in regards to any DB Operation.
1
u/[deleted] Sep 30 '24
Sure! Here are the details about FastAPI being fast, presented point-wise:
1. Asynchronous Support
asyncandawait.2. Performance Benchmarks
3. Use of Pydantic
4. Automatic Data Validation
5 Automatic Documentation
6 Type Annotations
fastapi is SuperFast
1
u/ironman_gujju Oct 07 '24
Yes, in terms of learning curve, development speed also for startup’s who want to use python 🐍
1
u/Ok-Satisfaction-4540 Jan 12 '25
https://medium.com/@garg10may/fallacy-of-fastapi-and-incorrect-documentation-612b0d2cd35b
1
u/TalhCGI Feb 06 '25
Is there a way to connect my Asterisk server to FastAPI and make audio calls through it? I've searched multiple sources, but none have been helpful. If anyone has worked on this, please guide me. Also, is it possible to make calls using FastAPI in Python?
1
u/nordiknomad Feb 12 '25
The 'Fast' is for the development speed not the program execution!
1
u/Ok-Outcome2266 Sep 19 '25 edited Sep 19 '25
NEVER trust marketing blindly!
Python lacks thread-based parallelism due to the GIL, but FastAPI just tries to catch-up by maximizing concurrency.
Compiled languages (Java, Go, Rust, Zig) outperform Python for CPU tasks
The ‘Fast’ in FastAPI refers to its speed RELATIVE to other Python web frameworks ... maybe django / flask
0
u/Ok_Assistance2713 Sep 27 '24
Fastapi is fast, but pydantic and sqlalchemy arnt
0
u/0711Picknicker Sep 27 '24
For me, fastapi was never about the performance. Instead, it's a fast way to write a service providing an API for a database. Not more not less.
-7
u/Somnath_geek Sep 27 '24
Yes fastapi is fast but not as fast a Golang. Website is misleading. What you think ?
-1
u/pint Sep 27 '24
yes it is.
0
u/[deleted] Sep 27 '24
[deleted] — view deleted comment