Created
November 20, 2021 01:27
-
-
Save abrookins/f873a66552ae17a4b1f638fed433735c to your computer and use it in GitHub Desktop.
Data validation with Redis OM for Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
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