Working with Pydantic in Pixeltable

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.

Providers · Notebook · Updated

Colab runs it in your browser. If it calls a model provider, it asks for that provider's API key in a cell.

What it covers

  • Basic usage: scalar types
  • Nested models and JSON columns
  • Media files with Pydantic
  • Working with Computed Columns
  • Optional Fields and Defaults
  • Type Mapping Reference
  • Learn More

What it uses

Install
terminal
pip install pixeltable pydantic
Pixeltable calls
pxt.create_table()insert()add_computed_column()

A look at the code

working-with-pydantic.ipynb
# Model only includes input columns
class Article(pydantic.BaseModel):
title: str
content: str
# Create table with computed column
articles = pxt.create_table(
'pydantic_demo/articles', {'title': pxt.String, 'content': pxt.String}
)
# Add a computed column
articles.add_computed_column(
word_count=pxt.functions.string.count(articles.content, r'\S+')
)

One cell of the notebook, copied as it is. Open it in Colab for the rest.

Browse all 103