Data validation using Python type hints
90
A system for managing user account statuses with automatic validation and JSON serialization.
@generates
from enum import Enum
from typing import Dict, Any
class AccountStatus(Enum):
"""Enumeration of possible account statuses."""
ACTIVE = "active"
SUSPENDED = "suspended"
BANNED = "banned"
class User:
"""
User model with validated account status.
When serialized to JSON/dict, the status should be represented
as its string value (e.g., "active") rather than the enum instance.
"""
username: str
status: AccountStatus
def to_dict(self) -> Dict[str, Any]:
"""
Convert user to dictionary representation.
Status should be serialized as its string value.
"""
passProvides data validation support.
Install with Tessl CLI
npx tessl i tessl/pypi-pydanticdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10