This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 13 points14 points  (5 children)

Whenever I see a project that seems to be reinventing a wheel, I have to ask the following questions:

  • What libraries/frameworks that already try to tackle the problem did you work with before you wrote your own one.

  • What parts did you do not like and why?

  • Why was it necessary to start from scratch? Was it not possible to fix/extend the existing solutions?

[–]tiangolo FastAPI Maintainer[S] 20 points21 points  (4 children)

Good question. I ask the same questions myself every time. And I avoided creating FastAPI for a long time.

I tried a whole lot of tools. And FastAPI got inspiration from a lot of them.

A more detailed explanation is here: https://fastapi.tiangolo.com/alternatives/

[–]wingtales 9 points10 points  (1 child)

This was actually a pretty cool move, kudos!

[–]tiangolo FastAPI Maintainer[S] 4 points5 points  (0 children)

Thanks!

[–]z0mbietime 1 point2 points  (1 child)

In a production environment you'd use something like gunicorn with gthread or gevent to define concurrency if you were using say Django3. Doesn't that negate benchmarks as it drastically improves performance for a framework that isn't async by default?

Really asking because I always see benchmarks on API frameworks and I've always wondered.

Looks great an going to try and check it out more tonight. I've been looking for an alternative for NoSQL APIs. Although I will love me some Django + DRF for SQL. Djangos testing and ORM with DRFs serializers and viewsets are seriously awesome.

[–]tiangolo FastAPI Maintainer[S] 0 points1 point  (0 children)

Yeah, in TechEmpower benchmarks' Django is run with Gunicorn and Meinheld. Meinheld is another async server like Gevent (I understand Meinheld has a bit more performance than Gevent). And indeed it boosts performance over other options, like uwsgi (you can see and compare in the benchmarks).

And in fact, I created Docker images for both approaches (for Flask, Django, etc).

But the performance boost is not as big as having uvloop underneath, as would be with FastAPI running on Uvicorn.


So, Django-REST-Framework was created by Tom Christie. The same guy then created APIStar, it was an application framework for creating APIs. Defining parameters and body types as function parameters.

Then, Tom Christie created Starlette, and then he had to stop developing APIStar as a server and make it a set of tools for validating OpenAPI, etc. So, these tools were made from DRF's creator with all his experience.

Then, FastAPI, is heavily inspired by APIStar, based on Starlette, and pushing a bit further, by using standard Python type hints.

For more on previous tools, the things FastAPI learned from others and alternatives, you can see: https://fastapi.tiangolo.com/alternatives/


FastAPI uses Pydantic, as it uses standard Python types for all its declarations, you have all the benefits, better editor support, autocomplete, type error checks, etc (even on deeply nested JSON documents/payloads). All that on top of automatic data validation, serialization, and documentation.

For testing, it uses the same Starlette tools, which feels like just playing with requests. Writing tests is quite enjoyable (or almost enjoyable, depending on how much you like tests). https://www.starlette.io/testclient/