FastAPI and Pydantic CamelCase

import uvicorn
from fastapi import FastAPI
from pydantic import BaseModel

class User(BaseModel):
first_name: str
last_name: str
age: int


app = FastAPI()


@app.get("/user/get", response_model=User)
async def get_user():
return User(first_name="John", last_name="Doe", age=30)

if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)
class User(BaseModel):
first_name: str
last_name: str
age: int
@app.post("/user/create", response_model=User)
async def create_user(user: User):
return user

Installation

pip install fastapi_camelcase

class User(CamelModel):
first_name: str
last_name: str
age: int
import uvicorn
from fastapi import FastAPI
from fastapi_camelcase import CamelModel


class User(CamelModel):
first_name: str
last_name: str
age: int


app = FastAPI()


@app.post("/user/create", response_model=User)
async def create_user(user: User):
return user


if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)

--

--

Software Developer

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

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