Skip to content

Instantly share code, notes, and snippets.

View Daspy11's full-sized avatar

Stuart Johnson Daspy11

View GitHub Profile
@Daspy11
Daspy11 / types.py
Created September 24, 2025 09:42
Pydantic JSONB field
from __future__ import annotations
from typing import Any, Dict, Generic, List, Optional, Type, TypeVar, Union, get_args, get_origin
from pydantic import BaseModel
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.types import TypeDecorator
T = TypeVar("T", bound=Union[BaseModel, dict, list])