← ClaudeAtlas

pydanticlisted

Data validation and settings management using Python type annotations with Pydantic v2
aiskillstore/marketplace · ★ 329 · Data & Documents · score 82
Install: claude install-skill aiskillstore/marketplace
# Pydantic v2 Framework Skill Pydantic is a data validation library that uses Python type annotations to define data schemas, offering fast and extensible validation with automatic type coercion. ## Quick Start ### Basic Model Definition ```python from pydantic import BaseModel from datetime import datetime from typing import Optional class User(BaseModel): id: int name: str email: str signup_ts: Optional[datetime] = None is_active: bool = True # Automatic type coercion user = User( id='123', # String → int name='John Doe', email='john@example.com', signup_ts='2017-06-01 12:22' # String → datetime ) ``` ### Validation from Data Sources ```python # From dict user = User.model_validate({'id': 1, 'name': 'Alice', 'email': 'alice@test.com'}) # From JSON user = User.model_validate_json('{"id": 1, "name": "Alice", "email": "alice@test.com"}') # Serialization print(user.model_dump()) # Python dict print(user.model_dump_json()) # JSON string ``` ## Common Patterns ### Field Configuration ```python from pydantic import BaseModel, Field, EmailStr, HttpUrl from typing import Annotated class Product(BaseModel): product_id: int = Field(alias='id', ge=1, description='Unique product identifier') name: str = Field(min_length=1, max_length=200) price: float = Field(gt=0, le=1000000) email: EmailStr website: HttpUrl tags: list[str] = Field(default_factory=list, max_length=10) internal_code: str = Field(exclude=Tr