Files
pydantic/docs/examples/export_pickle.py
T
Samuel Colvin 82ef45c890 alter the behaviour of dict(model) so that sub-models are nolonger converted to dictionaries (#733)
* fix iteration to not convert to dict by default

* add change

* remove extra newline
2019-08-12 11:31:35 +01:00

19 lines
297 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