mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
33b7d52d31
* moving docs to mkdocs * transfering readme to md and more * fixing build * splitting usage.md * improving schema.md and index.md * fix make_history.rst * models intro * working on data conversation and required fields * more fixes to models.md * list all standard types supported * list of pydantic types * tweaks * update links in code * Apply suggestions from code review incorporate @dmontagu's suggestions. Co-Authored-By: dmontagu <35119617+dmontagu@users.noreply.github.com> * Apply suggestions from code review more missed suggestions. Co-Authored-By: dmontagu <35119617+dmontagu@users.noreply.github.com> * Apply suggestions from code review more corrects. * cleanup * Field order warning * fix and regenerate benchmarks * format examples better, cleanup * improve schema mapping table * correct highlighting file types in schema.md * add redirects in javascript * add logo
28 lines
594 B
Python
28 lines
594 B
Python
from typing import List
|
|
from pydantic import BaseModel
|
|
|
|
class Foo(BaseModel):
|
|
count: int
|
|
size: float = None
|
|
|
|
class Bar(BaseModel):
|
|
apple = 'x'
|
|
banana = 'y'
|
|
|
|
class Spam(BaseModel):
|
|
foo: Foo
|
|
bars: List[Bar]
|
|
|
|
m = Spam(foo={'count': 4}, bars=[{'apple': 'x1'}, {'apple': 'x2'}])
|
|
print(m)
|
|
#> Spam foo=<Foo count=4 size=None>
|
|
#> bars=[<Bar apple='x1' banana='y'>, <Bar apple='x2' banana='y'>]
|
|
print(m.dict())
|
|
#> {
|
|
#> 'foo': {'count': 4, 'size': None},
|
|
#> 'bars': [
|
|
#> {'apple': 'x1', 'banana': 'y'},
|
|
#> {'apple': 'x2', 'banana': 'y'}
|
|
#> ]
|
|
#> }
|