Data validation using Python type hints
90
Build a storage quota configuration system that validates and manages file size limits for different user tiers.
Implement a configuration validator that accepts storage quotas in human-readable formats (like "500 MB", "2.5 GiB") and provides utilities to check if file sizes are within allowed limits and format sizes for display.
Validate storage quota configurations with support for both decimal (KB, MB, GB) and binary (KiB, MiB, GiB) units.
Check if a given file size in bytes is within the quota limit.
Format storage sizes in bytes as human-readable strings.
from pydantic import BaseModel
class StorageQuota(BaseModel):
"""Storage quota configuration for a user tier."""
quota_limit: <appropriate_type>
def is_within_quota(self, file_size_bytes: int) -> bool:
"""Check if a file size in bytes is within the quota limit."""
pass
def format_size(self, size_bytes: int) -> str:
"""Format a size in bytes as a human-readable string."""
pass@generates
Provides data validation with support for human-readable byte size types.
@satisfied-by
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