Skip to content

Instantly share code, notes, and snippets.

View fletcheaston's full-sized avatar
🥑

Fletcher Easton fletcheaston

🥑
View GitHub Profile
@fletcheaston
fletcheaston / models.py
Created July 9, 2021 21:47
Helpful Pydantic classes that I use for FastAPI apps.
import uuid
from datetime import datetime
from typing import Optional
from humps import camelize # This is from the pyhumps library (https://pypi.org/project/pyhumps/)
from pydantic import BaseModel as PydanticBase
class BaseModel(PydanticBase):
# Standard config settings.
@fletcheaston
fletcheaston / main.py
Last active July 5, 2021 19:29
Pydantic models from FastAPI query parameters and forms.
# Schema input manipulation. Very hacky, but it generates nice docs.
# Copied from https://github.com/tiangolo/fastapi/issues/318#issuecomment-691121286
# These don't work for nested Pydantic models.
import inspect
from types import FunctionType
from typing import Dict, Type
from fastapi import ( # noqa
BackgroundTasks,