Repository Details
Shared by
HelloGitHub Rating
0 ratings
使用类似于 ORM 的语法,序列化、反序列化 Python 对象
Past 7 days Received 0 stars ✨
Use arrow keys to explore dates, Home and End for the first and last date, Escape to dismiss.| Date | Star | Daily change |
|---|---|---|
| 周二 | 7,243 | — |
| 周三 | 7,243 | 0 |
| 周四 | 7,242 | -1 |
| 周五 | 7,242 | 0 |
| 周六 | 7,242 | 0 |
| 周日 | 7,243 | +1 |
| 周一 | 7,243 | 0 |
7.2k
Stars
No
Chinese
Python
Language
Yes
Active
230
Contributors
174
Issues
Yes
Organization
None
Latest
792
Forks
MIT
License
使用类似于 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