mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
92d7689271
* add construct method, fix #48 * adding copy method * adding pickle support, fix #40 * tweak copy and add fields copy test * adding docs for immutability, values and copy * add docs for pickle
21 lines
299 B
Python
21 lines
299 B
Python
import pickle
|
|
from pydantic import BaseModel
|
|
|
|
|
|
class FooBarModel(BaseModel):
|
|
a: str
|
|
b: int
|
|
|
|
|
|
m = FooBarModel(a='hello', b=123)
|
|
print(m)
|
|
# > FooBarModel a='hello' b=123
|
|
|
|
data = pickle.dumps(m)
|
|
print(data)
|
|
# > b'\x80\x03c...'
|
|
|
|
m2 = pickle.loads(data)
|
|
print(m2)
|
|
# > FooBarModel a='hello' b=123
|