Instantly convert API responses into production-ready Pydantic models
A Claude agent that automatically transforms JSON responses, API URLs, or curl commands into clean, type-safe Pydantic data models - eliminating manual model creation.
Transform this messy API response:
{
"user_id": 123,
"userName": "john_doe",
"emailAddress": "[email protected]",
"createdAt": "2023-01-01T00:00:00Z",
"userProfile": {
"biography": "Software developer",
"followerCount": 42,
"isVerified": true
}
}Into this beautiful Pydantic model:
from pydantic import BaseModel, EmailStr
from datetime import datetime
from typing import Optional
class UserProfile(BaseModel):
"""User profile information"""
biography: Optional[str] = None
follower_count: int = Field(alias="followerCount")
is_verified: bool = Field(alias="isVerified")
class UserResponse(BaseModel):
"""Auto-generated from API response"""
user_id: int
user_name: str = Field(alias="userName")
email_address: EmailStr = Field(alias="emailAddress")
created_at: datetime = Field(alias="createdAt")
user_profile: UserProfile = Field(alias="userProfile")- 🔍 Smart Detection: Automatically identifies input type (JSON, URL, curl, file)
- 🧠 Intelligent Typing: Converts JSON types to proper Python types with validation
- 📧 Pattern Recognition: Detects emails, URLs, timestamps, UUIDs automatically
- 🔄 Field Mapping: Handles camelCase ↔ snake_case conversion seamlessly
- 📚 Auto Documentation: Generates docstrings and field descriptions
- 🎯 Optional Fields: Smart detection of required vs optional fields
- 🏗️ Nested Models: Creates clean class hierarchies for complex data
- Claude Code CLI installed
- Python 3.8+ (for using generated models)
-
Activate the agent in Claude Code:
/api-to-pydantic
-
Provide your input in any format:
📋 Direct JSON:
{"id": 1, "name": "John", "email": "[email protected]"}🌐 API URL:
https://api.github.com/users/octocat💻 curl command:
curl -H "Authorization: Bearer token" https://api.example.com/data📁 JSON file (recommended for large/complex data):
file: response.json file: api_data.json file: /path/to/your_data.json -
Get instant Pydantic models - ready to copy and use!
- 🔌 API Integration: Model third-party API responses quickly
- ✅ Data Validation: Create type-safe models for incoming data
- 📖 Documentation: Generate model docs from API examples
- 🧪 Testing: Create mock data structures for tests
- 🔄 Migration: Convert JSON schemas to Pydantic v2
Automatically detects and converts:
2023-01-01T00:00:00Z→datetime[email protected]→EmailStrhttps://example.com→HttpUrl550e8400-e29b-41d4-a716-446655440000→UUID
- Analyzes data patterns to determine optional vs required fields
- Generates meaningful class names from JSON structure
- Handles complex nested objects and arrays
- Creates proper field aliases for API compatibility
- One-command workflow from JSON file to tested model
- Copy-paste ready output with validation
- Production quality code generation
- Automatic testing with executable test files
- Zero configuration required
api_2_pydantic/
├── README.md # This file
├── CLAUDE.md # Project instructions and overview
├── agents/ # Claude agent definitions
│ ├── api-to-pydantic.md # Main agent - handles routing and model generation
│ ├── schema-extract.md # Schema extraction agent for large/complex data
│ └── models-tester.md # Model testing agent (future feature)
├── api_to_pydantic_utils/ # Python utilities for schema processing
│ ├── __init__.py # Module initialization
│ └── schema_extractor.py # Core schema extraction logic
└── .gitignore # Git ignore rules
The project uses a multi-agent architecture for optimal performance:
- 🎯 Main Agent (
agents/api-to-pydantic): Handles input detection, routing, and Pydantic model generation - ⚡ Schema Extractor (
agents/schema-extract): Compresses large JSON data (80-95% reduction) for efficient processing - 🧪 Model Tester (
agents/models-tester): Validates generated models against original data (coming soon) - 🛠️ Utility Module (
api_to_pydantic_utils): Python utilities for file processing and schema extraction
This architecture enables handling everything from small JSON snippets to massive API responses efficiently.
This is a Claude agent project. To improve or extend functionality:
- Modify the agent instructions in
CLAUDE.md - Test with various API responses
- Submit issues for edge cases or improvements
MIT License - see the LICENSE file for details.
- Built for the Claude Code ecosystem
- Powered by Pydantic for data validation
- Inspired by developers who are tired of writing models manually
Made with ❤️ for developers who value their time
Stop writing Pydantic models by hand. Let AI do the heavy lifting.