fastapi-validation
БесплатноБез исполняемых скриптовНе проверенUse when FastAPI validation with Pydantic models. Use when building type-safe APIs with robust request/response validation.
от TheBushidoCollective★ 202 звезды на GitHubОб этом скилле
FastAPI Validation
Master FastAPI validation with Pydantic for building type-safe APIs with comprehensive request and response validation.
Pydantic BaseModel Fundamentals
Core Pydantic patterns with Pydantic v2.
from pydantic import BaseModel, Field, ConfigDict
from typing import Optional
from datetime import datetime
# Basic model
class User(BaseModel):
id: int
name: str
email: str
created_at: datetime
# With defaults and optional fields
class UserCreate(BaseModel):
name: str
email: str
age: Optional[int] = None
is_active: bool = True
# With Field constraints
class Product(BaseModel):
name: str = Field(..., min_length=1, max_length=100)
price: float = Field(..., gt=0, le=1000000)
quantity: int = Field(default=0, ge=0)
description: Optional[str] = Field(None, max_length=500)
model_config = ConfigDict(
str_strip_whitespace=True,
validate_assignment=True,
json_schema_extra={
'example': {
'name': 'Widget',
'price': 29.99,
'quantity': 100,
'description': 'A useful widget'
}
}
)
Request Body Validation
Validating complex request bodies.
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel, EmailStr, Field
from typing import List
app = FastAPI()
# Simple request validation
class CreateUserRequest(BaseModel):
username: str = Field(..., min_length=3, max_length=50)
email: EmailStr
password: str = Field(..., min_length=8)
age: int = Field(..., ge=13, le=120)
@app.post('/users')
async def create_user(user: CreateUserRequest):
# user is automatically validated
return {'username': user.username, 'email': user.email}
# Nested models
class Address(BaseModel):
street: str
city: str
state: str = Field(..., min_length=2, max_length=2)
zip_code: str = Field(..., pattern=r'^\d{5}(-\d{4})?$')
class UserProfile(BaseModel):
name: str
email: EmailStr
address: Address
phone: Optional[str] = Field(None, pattern=r'^\+?1?\d{9,15}$')
@app.post('/profiles')
async def create_profile(profile: UserProfile):
return profile
# List validation
class BulkCreateRequest(BaseModel):
users: List[CreateUserRequest] = Field(..., min_length=1, max_length=100)
@app.post('/users/bulk')
async def bulk_create_users(request: BulkCreateRequest):
return {'count': len(request.users)}
# Complex nested structures
class Tag(BaseModel):
name: str
color: str = Field(..., pattern=r'^#[0-9A-Fa-f]{6}$')
class Post(BaseModel):
title: str = Field(..., min_length=1, max_length=200)
content: str
tags: List[Tag] = []
author: UserProfile
published: bool = False
@app.post('/posts')
async def create_post(post: Post):
return post
Query Parameter Validation
Validating query parameters with Field constraints.
from fastapi import FastAPI, Query
from typing import Optional, List
from enum import Enum
app = FastAPI()
# Simple query params
@app.get('/users')
async def get_users(
skip: int = Query(0, ge=0),
limit: int = Query(10, ge=1, le=100),
search: Optional[str] = Query(None, min_length=3, max_length=50)
):
return {'skip': skip, 'limit': limit, 'search': search}
# Enum validation
class SortOrder(str, Enum):
asc = 'asc'
desc = 'desc'
class SortField(str, Enum):
name = 'name'
created_at = 'created_at'
updated_at = 'updated_at'
@app.get('/items')
async def get_items(
sort_by: SortField = Query(SortField.created_at),
order: SortOrder = Query(SortOrder.desc)
):
return {'sort_by': sort_by, 'order': order}
# Multiple values
@app.get('/filter')
async def filter_items(
tags: List[str] = Query([]),
categories: List[int] = Query([], max_length=10)
):
return {'tags': tags, 'categories': categories}
# Regex pattern
@app.get('/search')
async def search(
q: str = Query(..., min_length=1, max_length=100, pattern=r'^[a-zA-Z0-9\s]+$')
):
return {'query': q}
Path Parameter Validation
Validating URL path parameters.
from fastapi import FastAPI, Path
from typing import Annotated
app = FastAPI()
@app.get('/users/{user_id}')
async def get_user(
user_id: int = Path(..., gt=0, description='The user ID')
):
return {'user_id': user_id}
@app.get('/items/{item_id}/reviews/{review_id}')
async def get_review(
item_id: Annotated[int, Path(gt=0)],
review_id: Annotated[int, Path(gt=0)]
):
return {'item_id': item_id, 'review_id': review_id}
# String path validation
@app.get('/categories/{category_name}')
async def get_category(
category_name: str = Path(..., min_length=1, max_length=50, pattern=r'^[a-z-]+$')
):
return {'category': category_name}
Custom Validators
Field validators and model validators with Pydantic v2.
from pydantic import BaseModel, field_validator, model_validator
from typing import Any
Установить fastapi-validation в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
BashReadFAQ
Что делает скилл fastapi-validation?
Use when FastAPI validation with Pydantic models. Use when building type-safe APIs with robust request/response validation.
Как установить скилл fastapi-validation?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл fastapi-validation запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic