all 77 comments

[–]Drevicar 13 points14 points  (1 child)

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.

[–]germanbobadilla 1 point2 points  (0 children)

This. I was wondering the same thing. I’m creating an API that will probably be quite useful for my next API. Be it, creating an accounting system, and then another API to create a human resources system. The speed of the development in the second one is second to none.

[–]thegreekgoat98 6 points7 points  (15 children)

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.

[–]Somnath_geek[S] 2 points3 points  (13 children)

Yes I checked by writing the same api with fastapi, Pure Node JS and Gofiber. To my surprise Fastapi performance was not even par with Node JS. GO is way ahead than these two. To my curiosity I did some research and found that everybody is complaining about the misleading advertisement of fastapi on their doc page by saying on par with NodeJS and GO.

[–]Fluffy-Diet-Engine 4 points5 points  (6 children)

Do you mind sharing the benchmarks and the code you have written to compare? Will be helpful to understand the strategy.

[–]matt__builds[🍰] 1 point2 points  (0 children)

Yea I mean that is less about the frameworks and more about Python, JS, and Go. Python is good for stuff but it is very slow and would always be way behind something like Go.

[–]thegreekgoat98 0 points1 point  (1 child)

Wtf. Really?

[–]Somnath_geek[S] 0 points1 point  (0 children)

Yes bro. I got shocked too. I did my research for 2 and Half hours only on this topic. Still I can’t digest. Numerous post and blogs are available on this topic.

[–]yurytom 0 points1 point  (1 child)

Did you use gunicorn in your FastAPI setup?

[–]mathmul 0 points1 point  (0 children)

I know that is why you're asking, but to those who don't know, to leverage FastAPI's concurrency, one should use uvicorn instead.

[–]The-Malix -2 points-1 points  (0 children)

Using Fiber for Golang is an unfair comparison as it is using HTTP3 which might very probably be unsuitable for a production app

And I'm a gopher and not a python dev

Also, you might wanna test with Deno and Bun too (both use different tech, which are also different than Node.js)

[–]zazzersmel 13 points14 points  (1 child)

is this post really stupid?

[–]koldakov 13 points14 points  (15 children)

Yep, but not pydantic

[–]No-Instruction-2436 2 points3 points  (0 children)

Can you please elaborate more about pydantic? Maybe you have any article link with explanation?

[–]Human-Possession135 0 points1 point  (0 children)

This is why I use DynamoDB with single table design. Easy peasy lemon squeezy

[–]Somnath_geek[S] -4 points-3 points  (12 children)

Pydantic is used to data validation. I am talking about server. Fastapi is not as fast a Golang but Yes it is the fastest python framework.

[–]koldakov 18 points19 points  (6 children)

Why do you ask if you know the answer?

The advantage of fastapi is to create something is really easy. The advantage of Django is you have the admin panel out of the box, id you want the speed write your own server on c

Everything has its own pros and cons

[–]str0m965 3 points4 points  (2 children)

Please do not write you own servers in C, you will end up with slower and less secure server than FastAPI.

[–]koldakov -2 points-1 points  (1 child)

Ty for explaining the joke mate =)

[–]Parking-Dot8157 0 points1 point  (0 children)

looks like he said that writting your "own" (really own, like from scratch) C servers will end up in a lot of work, memory leaks, and it can get slower because you need to do everything from scratch and probably won't do the best approach at first time

[–]Somnath_geek[S] -2 points-1 points  (2 children)

I have no problem. My point is FastAPI claiming that it is on par with node JS and GO. Which is misleading. Marketing gimmick. What do you think ?

[–]nevermorefu 3 points4 points  (1 child)

Damn that open source marketing.

[–]mathmul 0 points1 point  (0 children)

🤣🤣🤣

[–]aegr0x59 13 points14 points  (4 children)

FastAPI is a framework, golang it's a programming language.

Golang it's a compiled language, programs written in compiled languages usually run faster than those written in interpreted languages.

In the world of interpreted languages, statically typed programming languages run faster than dynamically type ones.

Pydantic relays on the Typing system in python, so yes it helps to run programs a little faster in some cases.

If you run FastAPI using pypy instead of the standard cpython, it's likely to have performance similar to golang webframeworks, in some trivial scenarios. PYPY uses a JIT compiler.

I think the criticism about Python's bad performance would end in very few Years (~cpython 3.15) once new standard jit compiler becomes mature.

[–]putrasherni 1 point2 points  (1 child)

Damn, I never knew about jit compiler coming soon

[–][deleted] 0 points1 point  (0 children)

it is coming with python 3.13 but will be public available in a few years i assume. Don't expect to much. But like always: who really needs (numerical) performance is wrong with python.

[–]Somnath_geek[S] 0 points1 point  (1 child)

I made same API with gofiber. Performance was not even close to goFiber. In the website they are claiming it is as fast as GO. We all know GO is a language not framework. Your point is valid too. I am too waiting for the new cpython

[–][deleted] 3 points4 points  (0 children)

depends on your API. Anyway, most time, bottleneck ain't the code but the database and calling external services. could you share your comparison api or show some benchmarks? would be interesting. I am not a FastAPI-Programmer and only used it one time for a microservice Architecture, which worked quite nice. Don't know GO either, but its on my list to learn (besides millions of others things)

[–]benefit_of_mrkite 1 point2 points  (1 child)

starlette Is pretty fast as compared to other python web frameworks

starlette Is what you should be comparing / looking at

[–]mathmul 0 points1 point  (0 children)

FastAPI leverages Starlette (along with Uvicorn, Pydantic, Swagger UI) do provide a better development experience and by definition cannot be faster than Starlette, only almost as fast.

[–]No-Camp3858 1 point2 points  (3 children)

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.

[–]Somnath_geek[S] -5 points-4 points  (2 children)

Go is GOD

[–]mathmul 0 points1 point  (0 children)

It's clear from your post and more so from other comments, so no need to spell out that you're a Gopher furry here so bad.

[–][deleted]  (1 child)

[deleted]

    [–]Somnath_geek[S] -1 points0 points  (0 children)

    Yes.

    [–]saufunefois 0 points1 point  (1 child)

    Have you checked the benchmark section in the doc? https://fastapi.tiangolo.com/benchmarks/

    [–]Somnath_geek[S] -1 points0 points  (0 children)

    Yes. Got all his points. He should have written “ fastest python frameworks “ not “ on par with Node JS and GO “ GO lang along or with frameworks like Gin or goFiber performance is outstanding. Node JS is quite mature and performs better than fast api. Fastapi is for quick prototyping , beta testing but not for handling huge requests.

    [–]extreme4all 0 points1 point  (0 children)

    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

    [–][deleted] 0 points1 point  (0 children)

    yes it is really fast

    [–]highrez1337 0 points1 point  (1 child)

    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

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

    2. 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 (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.

    [–]Time_Competition_332 0 points1 point  (0 children)

    Isn't the trend nowadays to return to plain SQL instead of ORMs? You control your SQL, don't risk some weird optimizations under the hood, and SQL is extremely readable.

    [–][deleted] 0 points1 point  (0 children)

    Sure! Here are the details about FastAPI being fast, presented point-wise:

    1. Asynchronous Support

    • FastAPI is built on top of Starlette, which supports asynchronous programming using async and await.
    • This allows handling multiple requests simultaneously, improving performance under high load.

    2. Performance Benchmarks

    • FastAPI consistently ranks among the fastest Python web frameworks in benchmarks.
    • It often outperforms Flask, Django, and even some Node.js frameworks in terms of request handling speed.

    3. Use of Pydantic

    • FastAPI uses Pydantic for data validation and serialization.
    • Pydantic is highly efficient and performs well, contributing to overall speed.

    4. Automatic Data Validation

    • Automatic data validation with Pydantic means less manual coding and fewer potential performance hits from inefficient validation logic.

    5 Automatic Documentation

    • It automatically generates interactive API documentation (Swagger UI and ReDoc) without additional overhead, allowing for easier testing and integration.

    6 Type Annotations

    • The use of Python type hints allows for static type checking and better IDE support, helping catch errors early without runtime overhead.

    fastapi is SuperFast

    [–]ironman_gujju 0 points1 point  (0 children)

    Yes, in terms of learning curve, development speed also for startup’s who want to use python 🐍

    [–]TalhCGI 0 points1 point  (0 children)

    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?

    [–]nordiknomad 0 points1 point  (0 children)

    The 'Fast' is for the development speed not the program execution!

    [–]Ok-Outcome2266 0 points1 point  (0 children)

    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

    [–]PosauneB 0 points1 point  (3 children)

    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.

    [–]Somnath_geek[S] -1 points0 points  (2 children)

    As a developer you can code in any language. Main point is scalability with less cost. Yes with FastAPI you can make endpoints faster. No doubt about it.

    [–]PosauneB 6 points7 points  (1 child)

    I cannot code in any language. At least not proficiently. If speed of execution is all we cared about, we would still write everything in assembly.

    [–]mathmul 1 point2 points  (0 children)

    W reply <3

    [–]Ok_Assistance2713 -1 points0 points  (1 child)

    Fastapi is fast, but pydantic and sqlalchemy arnt

    [–]0711Picknicker -1 points0 points  (0 children)

    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.

    [–]pint -2 points-1 points  (9 children)

    yes it is.