NEW: Fenrir v1.2.2 is now available — Logo & Favicon Patch! Read the changelog
data-validation.md
docs data-validation.md

Data Validation

Pydantic Models

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
from pydantic import BaseModel, Field

class User(BaseModel):
    username: str = Field(..., min_length=3, max_length=50)
    email: str = Field(..., pattern=r"^[\w\.-]+@[\w\.-]+\.\w+$")
    age: int = Field(..., ge=0, le=150)
    is_active: bool = True

# Use in routes
@app.post("/users")
async def create_user(user: User):
    # Automatic validation and parsing
    return {"created": True, "user": user}

Query Parameter Validation

1
2
3
4
5
6
7
8
9
from fenrir import Query

@app.get("/items")
async def list_items(
    skip: int = Query(0, ge=0, description="Number of items to skip"),
    limit: int = Query(10, le=100, description="Maximum items"),
    search: str = Query(None, min_length=1)
):
    return {"skip": skip, "limit": limit, "search": search}

Request Body with Multiple Parameters

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
from pydantic import BaseModel

class Item(BaseModel):
    name: str
    description: str = None
    price: float
    tax: float = None

@app.post("/items")
async def create_item(
    item: Item,
    q: str = Query(None),
    user_id: int = Query(...)
):
    return {"item": item, "query": q, "user_id": user_id}
Edit on GitHub Last Updated: Jun 04, 2026
© 2026 Fenrir Project.
main*
v1.2.2
Ln 1, Col 1
UTF-8
Prettier
Light Mode
Markdown