Skip to content

In Memory

The MemoryCRUDRouter is the simplest usage of the CRUDRouters. To use it, simply pass a pydantic model to it. As a database is not required, the MemoryCRUDRouter is well suited for rapid bootstrapping and prototyping.


from pydantic import BaseModel
from fastapi import FastAPI
from fastapi_crudrouter import MemoryCRUDRouter

class Potato(BaseModel):
    id: int
    color: str
    mass: float

app = FastAPI()
router = MemoryCRUDRouter(schema=Potato)


When using the MemoryCRUDRouter, the schema (model) passed to it must have the id: int property.


The storage for the MemoryCRUDRouter resides in memory, not a database. Hence, the data is not persistent. Be careful when using it beyond the rapid bootstrapping or prototyping phase.