---
title: "Working with Pydantic in Pixeltable"
description: "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."
url: "https://www.pixeltable.com/notebooks/working-with-pydantic"
updated: "2026-08-14"
---

# 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.

- **Type:** Notebook
- **Group:** Providers

## 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:** `pip install pixeltable pydantic`
- **Pixeltable calls:** `pxt.create_table()`, `insert()`, `add_computed_column()`

## A look at the code

```python
# 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+')
)
```

## Open it

- **Open in Colab:** https://colab.research.google.com/github/pixeltable/pixeltable/blob/release/docs/release/howto/providers/working-with-pydantic.ipynb
- **Docs page:** https://docs.pixeltable.com/howto/providers/working-with-pydantic
- **Source on GitHub:** https://github.com/pixeltable/pixeltable/blob/release/docs/release/howto/providers/working-with-pydantic.ipynb
