项目详情
由
分享


HelloGitHub 评分
0 人评分
开源•MIT
认领
讨论
收藏
分享
7.2k
星数
否
中文
Python
主语言
是
活跃
187
贡献者
138
Issues
是
组织
无
最新版本
637
Forks
MIT
协议
更多
使用类似于 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'}
```
收录于:
第 26 期
评论
评分:
暂无精选评论