Files
pydantic/docs/examples/exotic.py
T
Samuel Colvin b10566841e Less verbose errors (#90)
* make errors less verbose, fix #71

* remove track too if null

* update docs

* better dict error, fix #74

* add history
2017-10-23 20:06:48 +01:00

60 lines
1.6 KiB
Python

from pathlib import Path
from uuid import UUID
from pydantic import (DSN, BaseModel, EmailStr, NameEmail, PyObject, conint,
constr, PositiveInt, NegativeInt)
class Model(BaseModel):
cos_function: PyObject = None
path_to_something: Path = None
short_str: constr(min_length=2, max_length=10) = None
regex_str: constr(regex='apple (pie|tart|sandwich)') = None
big_int: conint(gt=1000, lt=1024) = None
pos_int: PositiveInt = None
neg_int: NegativeInt = None
email_address: EmailStr = None
email_and_name: NameEmail = None
db_name = 'foobar'
db_user = 'postgres'
db_password: str = None
db_host = 'localhost'
db_port = '5432'
db_driver = 'postgres'
db_query: dict = None
dsn: DSN = None
uuid: UUID = None
m = Model(
cos_function='math.cos',
path_to_something='/home',
short_str='foo',
regex_str='apple pie',
big_int=1001,
pos_int=1,
neg_int=-1,
email_address='Samuel Colvin <s@muelcolvin.com >',
email_and_name='Samuel Colvin <s@muelcolvin.com >',
uuid='ebcdab58-6eb8-46fb-a190-d07a33e9eac8'
)
print(m.values())
"""
{
'cos_function': <built-in function cos>,
'path_to_something': PosixPath('/home'),
'short_str': 'foo', 'regex_str': 'apple pie',
'big_int': 1001,
'pos_int': 1,
'neg_int': -1,
'email_address': 's@muelcolvin.com',
'email_and_name': <NameEmail("Samuel Colvin <s@muelcolvin.com>")>,
...
'dsn': 'postgres://postgres@localhost:5432/foobar',
'uuid': UUID('ebcdab58-6eb8-46fb-a190-d07a33e9eac8'),
}
"""