Skip to content

Instantly share code, notes, and snippets.

@abrookins
Created November 20, 2021 01:27
Show Gist options
  • Save abrookins/f873a66552ae17a4b1f638fed433735c to your computer and use it in GitHub Desktop.
Save abrookins/f873a66552ae17a4b1f638fed433735c to your computer and use it in GitHub Desktop.
Data validation with Redis OM for Python
import datetime
from typing import Optional
from pydantic import EmailStr, ValidationError
from redis_om import HashModel
class Customer(HashModel):
first_name: str
last_name: str
email: EmailStr
join_date: datetime.date
age: int
bio: Optional[str]
try:
Customer(
first_name="Andrew",
last_name="Brookins",
email="Not an email address!",
join_date=datetime.date.today(),
age=38,
bio="Python developer, works at Redis, Inc."
)
except ValidationError as e:
print(e)
"""
pydantic.error_wrappers.ValidationError: 1 validation error for Customer
email
value is not a valid email address (type=value_error.email)
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment