Learn Tyck through practical examples. Copy, paste, and customize for your projects.
Create a simple user model with validation constraints
Define request and response schemas for a REST API
Work with complex nested data structures
Type-safe application configuration with validation
Use @model decorator for schemas with custom methods
Catch and process validation errors with detailed messages
Use Tyck and Pydantic together in the same project
Use pick, omit, partial, extend, and merge utilities
Create a simple user model with validation constraints
from tyck import interface, string, integer, optional, number, array
# Define a User schema with validation
User = interface({
'id': integer.positive(),
'username': string.min(3).max(30),
'email': string.email(),
'age': optional(integer.range(13, 120)),
'roles': array(string).default(['user']),
})
# Create and validate a user
user = User(
id=1,
username="john_doe",
email="john@example.com",
age=28,
)
# Serialize to dictionary
print(user.model_dump()){
'id': 1,
'username': 'john_doe',
'email': 'john@example.com',
'age': 28,
'roles': ['user']
}