Repository Details
Shared by


HelloGitHub Rating
0 ratings
Free•MIT
Claim
Discuss
Collect
Share
7.2k
Stars
No
Chinese
Python
Language
Yes
Active
187
Contributors
137
Issues
Yes
Organization
None
Latest
637
Forks
MIT
License
More
使用类似于 ORM 的语法,序列化、反序列化 Python 对象。可以将序列化的对象呈现为标准格式,适用于例如数据校验、返回 HTTP API 的 JSON。示例代码如下:
```python
from datetime import date
from marshmallow import Schema, fields, pprint
class ArtistSchema(Schema):
name = fields.Str()
class AlbumSchema(Schema):
title = fields.Str()
release_date = fields.Date()
artist = fields.Nested(ArtistSchema())
bowie = dict(name='David Bowie')
album = dict(artist=bowie, title='Hunky Dory', release_date=date(1971, 12, 17))
schema = AlbumSchema()
result = schema.dump(album)
pprint(result, indent=2)
# 输出如下
# { 'artist': {'name': 'David Bowie'},
# 'release_date': '1971-12-17',
# 'title': 'Hunky Dory'}
```
Included in:
Vol.26
Comments
Rating:
No comments yet