Skip to main content
Open in Kaggle  Open in Colab  Download Notebook
This documentation page is also available as an interactive notebook. You can launch the notebook in Kaggle or Colab, or download it for use with an IDE or local Jupyter installation, by clicking one of the above links.
Pixeltable’s Pydantic integration enables type-safe data insertion using Pydantic models. Instead of inserting raw dictionaries, you can define structured models with validation and insert them directly into Pixeltable tables.

Benefits

  • Type Safety: Pydantic validates data before insertion
  • IDE Support: Autocomplete and type hints for your data
  • Self-Documenting: Models serve as schema documentation
  • Validation: Built-in data validation via Pydantic

Important notes

  • Pydantic model fields map to Pixeltable columns by name
  • Computed columns are automatically skipped during insertion
  • Nested Pydantic models map to JSON columns
Connected to Pixeltable database at: postgresql+psycopg://postgres:@/pixeltable?host=/Users/asiegel/.pixeltable/pgdata
Created directory ‘pydantic_demo’.
<pixeltable.catalog.dir.Dir at 0x12e01b2b0>

Basic usage: scalar types

Define a Pydantic model with fields that match your table columns. Pixeltable automatically maps Python types to Pixeltable types:
Created table ‘products’.
Inserted 3 rows with 0 errors in 0.02 s (146.18 rows/s)

Nested models and JSON columns

Nested Pydantic models automatically map to Pixeltable JSON columns. This is useful for storing structured metadata.
Created table ‘customers’.
Inserted 2 rows with 0 errors in 0.01 s (227.55 rows/s)

Media files with Pydantic

For media columns (Image, Video, Audio, Document), use str or Path fields in your Pydantic model to specify file paths or URLs.
Created table ‘images’.
Inserted 1 row with 0 errors in 0.27 s (3.74 rows/s)

Working with Computed Columns

Pydantic models work seamlessly with computed columns. Simply omit computed column fields from your model - Pixeltable will skip them during insertion.
Created table ‘articles’.
Added 0 column values with 0 errors in 0.01 s
No rows affected.
Inserted 2 rows with 0 errors in 0.01 s (186.43 rows/s)

Optional Fields and Defaults

Pydantic’s optional fields with defaults work naturally with Pixeltable’s nullable columns.
Created table ‘tasks’.
Inserted 3 rows with 0 errors in 0.01 s (408.88 rows/s)

Type Mapping Reference

Here’s the complete mapping between Pydantic/Python types and Pixeltable types:

Learn More

For more information about working with Pydantic in Pixeltable: If you have any questions, don’t hesitate to reach out on Discord.
Last modified on July 14, 2026