... fastapi.

FastApi is an enjoyable tool for building web applications in python. In these videos we demonstrate the main features.

Episode Notes

You can send json to FastApi. This is like sending a python dictionary. You'd still like the dictionary you send to adhere to a standard though. FastApi using the pydantic library to help you define the perfect json type.

The app.py file at the end of our video looks like this;

from fastapi import FastAPI

app = FastAPI()

def root():
    return {"message": "hello world again"}

def read_user(user_id: str):
    return {"user_id": user_id}

from pydantic import BaseModel, validator

class Item(BaseModel):
    name: str
    price: float

    def price_must_be_positive(cls, value):
        if value <= 0: 
            raise ValueError(f"we expect price >= 0, we received {value}")
        return value

def create_item(item: Item):
    return item

Don't forget that you need to import the validator decorator from pydantic.

Feedback? See an issue? Feel free to mention it here.

If you want to be kept up to date, consider getting the newsletter.