Skip to content

Examples Overview

Explore practical examples demonstrating Pydantic Airtable capabilities.


Available Examples

Example Difficulty Description
Simple Usage Beginner Basic CRUD operations and field type detection
Table Management Intermediate Schema creation and synchronization
Agentic Researcher Advanced AI-powered research assistant with OpenAI

Getting Started

Start with the Simple Usage example to learn:

  • How to define models with the @airtable_model decorator
  • Field type detection
  • Basic CRUD operations
  • Environment-based configuration

Schema Management

The Table Management example covers:

  • Creating tables from Pydantic models
  • Field type customization
  • Schema synchronization
  • Handling model evolution

AI Integration

The Agentic Researcher shows:

  • Complex multi-model applications
  • OpenAI GPT-4 integration
  • Real-time web search
  • Structured research workflows

Running Examples

Prerequisites

All examples require:

  1. Python 3.8+
  2. Airtable credentials:
    • Personal Access Token (PAT)
    • Base ID

Setup

  1. Clone the repository:

    git clone https://github.com/pydantic-airtable/pydantic-airtable.git
    cd pydantic-airtable
    

  2. Install dependencies:

    pip install -e .
    

  3. Create .env file:

    AIRTABLE_ACCESS_TOKEN=pat_your_token
    AIRTABLE_BASE_ID=appYourBaseId
    

Run

cd examples/simple_usage
python simple_usage.py

Example Code Snippets

Basic Model

from pydantic_airtable import airtable_model, configure_from_env
from pydantic import BaseModel

configure_from_env()

@airtable_model(table_name="Tasks")
class Task(BaseModel):
    title: str
    completed: bool = False

# Create
task = Task.create(title="Learn Pydantic Airtable")

# Read
tasks = Task.all()

# Update
task.completed = True
task.save()

# Delete
task.delete()

With Field Type Detection

@airtable_model(table_name="Contacts")
class Contact(BaseModel):
    name: str           # → SINGLE_LINE_TEXT
    email: str          # → EMAIL (detected)
    phone: str          # → PHONE (detected)
    website: str        # → URL (detected)
    bio: str            # → LONG_TEXT (detected)

With Custom Fields

from pydantic_airtable import airtable_field, AirtableFieldType

@airtable_model(table_name="Products")
class Product(BaseModel):
    name: str

    status: str = airtable_field(
        field_type=AirtableFieldType.SELECT,
        choices=["Draft", "Active", "Discontinued"]
    )

    price: float = airtable_field(
        field_name="Price (USD)",
        field_type=AirtableFieldType.CURRENCY
    )

Learning Path

Recommended order:

  1. Simple Usage - Foundation concepts
  2. Table Management - Schema management
  3. Agentic Researcher - Real-world application

Each example builds on concepts from previous ones.


Next Steps

After exploring examples: