Introducing FastAPI

Intro

Key Features

Installation

$ pip install fastapi
$ pip install uvicorn

Example

Create it

from fastapi import FastAPIapp = FastAPI()
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.get("/items/{item_id}")
def read_item(item_id: int, q: str = None):
return {"item_id": item_id, "q": q}

Check it

{"item_id": 5, "q": "somequery"}

Interactive API docs

Alternative API docs

Example upgrade

from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class Item(BaseModel):
name: str
price: float
is_offer: bool = None
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.get("/items/{item_id}")
def read_item(item_id: int, q: str = None):
return {"item_id": item_id, "q": q}
@app.put("/items/{item_id}")
def create_item(item_id: int, item: Item):
return {"item_name": item.name, "item_id": item_id}

Interactive API docs upgrade

Alternative API docs upgrade

Recap

item_id: int
item: Item
return {"item_name": item.name, "item_id": item_id}
... "item_name": item.name ...
... "item_price": item.price ...

Performance

Learn more

About me

--

--

--

Creator of FastAPI and Typer. Dev at Exposion AI. APIs, Deep Learning/Machine Learning, full-stack distributed systems, SQL/NoSQL, Python, Docker, JS, TS, etc.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Creating LVM in Linux And Integrating With Hadoop Cluster

From CSVs to Tables: Infer Schema Data Types From Raw Spreadsheets

A journey To become a full-stack developer

Google Are You Listening? — Part II

How to Increase VM Backup Speed

5–2 [Modeling] How to model a business process (Business Process Diagram)

Top 5 Computer Science Electives For Spring 2019

Kazan Alfan Ihsan

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Sebastián Ramírez

Sebastián Ramírez

Creator of FastAPI and Typer. Dev at Exposion AI. APIs, Deep Learning/Machine Learning, full-stack distributed systems, SQL/NoSQL, Python, Docker, JS, TS, etc.

More from Medium

Banking App With FastApi and Tkinter

muzz goes open source

Production checklist of Websockets using Flask, Celery and Javascript

FastApi Blueprint