The framework grew out of an effort to keep what a Python service accepts in step with what it tells its clients.
Before writing FastAPI’s internals, Sebastián Ramírez tried out different ways to declare an API in PyCharm, Visual Studio Code, and editors that used the Jedi completion engine. He was deciding what developers should have to write for each endpoint. If a Python function expected an integer, its editor could already use a type annotation to catch some mistakes. Ramírez wanted the framework to use that same information to check incoming requests and explain the endpoint to the people calling it. PyPI records the release of FastAPI 0.1.0 on December 8, 2018. [1] [2] [3]
The design addressed a problem that grew with every endpoint. When a service describes the same field in its code, its validation rules, and its documentation, each change has several places to go wrong. Ramírez put the declarations those jobs shared in the code developers already had to write. That choice made it easier to keep a service and its documentation in step. It also meant that an ordinary Python edit could become a change to a public interface.
The framework he tried to avoid writing
Ramírez recalls a succession of startup projects that kept bringing him back to the same integration work. One of his preferred combinations used Flask for the web application, Marshmallow for data schemas, and Webargs for parsing inputs. The Flask-apispec extension tied those pieces together and could already generate an OpenAPI description from the schemas. He made project generators around that stack to give his teams a common starting point. A generator could reproduce the setup. Each team still had to work with the conventions of several libraries. [1] [4]
Tom Christie’s API Star came closer to what Ramírez wanted. Its server used Python type hints for API parameters and could generate an OpenAPI description. Ramírez still wanted request-body models that gave his editor the same type information, and he recalls needing security integration before he could replace his Flask setup. When Christie recast API Star as a toolkit for working with API descriptions and turned his attention to Starlette, Ramírez took the new project as a foundation. Starlette supplied routing and the asynchronous web layer. Pydantic supplied data parsing, validation, and schemas built from annotated models. Ramírez’s work was to make those pieces agree on what a route declaration meant. [2] [4] [5]
What a declaration can do
Python itself leaves type annotations unenforced at runtime. FastAPI reads the signature of a function registered as an HTTP endpoint to determine which values to extract from the request. A parameter annotated with a Pydantic model can represent the JSON body. Pydantic parses and validates that data before the endpoint receives it. FastAPI uses the model’s JSON Schema to describe the body in OpenAPI, which in turn feeds the built-in Swagger UI. A developer can try a request in the browser, and another team can use the same OpenAPI document to generate client code in another language. [6] [7] [8] [9]
Take a hypothetical inventory API. A request model can declare its quantity field as quantity: int = Field(gt=0). An editor sees an integer. Pydantic enforces the lower bound, and the generated schema describes a positive integer. A declared response model can filter the outgoing data to expose the reservation ID and status while keeping internal fields out of the JSON. The service still has to decide who may reserve stock and ensure that two valid requests cannot both claim the last unit. That decision depends on the caller and on state shared across requests. [7] [8] [10]
The same attention to what developers write shaped FastAPI’s use of Starlette. A route written with async def can await a database call made with an asynchronous driver, giving the event loop time to run other requests. FastAPI runs a regular def route in a thread pool, so a team can use a synchronous driver while keeping the declaration of the request and response. The distinction still matters inside a route. A blocking call made directly from an asynchronous handler can stall the event loop for other requests handled there. [4] [11]
When a dependency changes the contract
The relationship between the Python model and the public API became especially visible in 2023, when FastAPI 0.100.0 introduced support for Pydantic 2 alongside version 1. Consider an inventory reservation with a field declared as note: Optional[str] and no explicit default. Pydantic 1 allowed a request to omit note. Pydantic 2 requires the field to appear and accepts null as its value. Upgrading Pydantic could therefore cause a service to reject requests from existing clients even if its route and model declarations stayed the same. The generated schema could describe the new requirement accurately. Existing clients would still send the old requests. [12] [13]
That coupling matters most when an API has consumers on separate release schedules. A team that starts with OpenAPI can agree on a language-independent contract before it implements the service. That gives client teams something stable to review early and leaves the server team with the work of verifying conformance. A team that starts with FastAPI’s Python models can keep routine documentation changes tied to implementation. It can still review the generated OpenAPI document as a release artifact and test representative requests from existing clients. A schema comparison would flag the newly required note. An HTTP-level test would show what happens to a client that omits it. [9] [12] [13]
A framework that found room alongside others
In the Python Developers Survey, run by the Python Software Foundation and JetBrains, FastAPI appeared in 21 percent of responses to the web-framework question in 2021 and 38 percent in 2024. The 2024 cross-usage table shows that 42 percent of respondents who selected FastAPI also selected Django. The survey recruited through Python community channels and reflects the people who chose to respond. Their answers leave open why they chose a framework or whether they used both on the same project. They do show that many respondents used FastAPI alongside an established alternative. [14]
Ramírez started by testing how a declaration reads in an editor. Once FastAPI turns that declaration into a public contract, its most consequential readers may be people who never see the Python code. They experience the design through the requests their software can keep making as the service evolves.
Editorial disclosure. OpenAI Codex assisted with source research, analysis, and drafting.
References
- Ricky White. Python Community Interview With Sebastián Ramírez. Real Python, June 7, 2021.
- FastAPI project. History, Design and Future.
- Python Package Index. FastAPI 0.1.0. December 8, 2018.
- FastAPI project. Alternatives, Inspiration and Comparisons.
- Encode. API Star project and the status of the API Star server.
- Guido van Rossum, Jukka Lehtosalo, and Łukasz Langa. PEP 484 – Type Hints. Python Enhancement Proposals, 2014.
- FastAPI project. FastAPI documentation and interactive API docs.
- FastAPI project. Body – Fields.
- OpenAPI Initiative. OpenAPI Specification v3.1.0. February 15, 2021.
- FastAPI project. Response Model – Return Type.
- FastAPI project. Concurrency and async / await.
- FastAPI project. FastAPI 0.100.0 release notes. July 2023.
- Pydantic project. Pydantic 2 migration guide on required, optional, and nullable fields.
- Python Software Foundation and JetBrains. Python Developers Survey 2024 Results, frameworks and libraries tables and methodology.