用于将复杂数据类型转换为本机python数据类型和从本机python数据类型转换为本机python数据类型的轻量级库。
marshmallow2的Python项目详细描述
marshmallow是一个orm/odm/framework无关的库,用于将复杂的数据类型(如对象)转换为原生python数据类型和从原生python数据类型转换。
fromdatetimeimportdatefrommarshmallowimportSchema,fields,pprintclassArtistSchema(Schema):name=fields.Str()classAlbumSchema(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.data,indent=2)# { 'artist': {'name': 'David Bowie'},# 'release_date': '1971-12-17',# 'title': 'Hunky Dory'}
简而言之,棉花糖模式可用于:
- validate输入数据。
- 反序列化将数据输入到应用程序级对象。
- serialize应用程序级对象到原始python类型。然后,可以将序列化对象呈现为标准格式(如json),以便在http api中使用。
立即获取
$ pip install -U marshmallow
文档
完整的文档可在http://marshmallow.readthedocs.io/获得。
学分
专业支持
专业支持的棉花糖现在可以通过 Tidelift Subscription。
Tidelift为软件开发团队提供了购买和维护软件的单一来源, 有了最了解它的专家的专业级别保证, 同时与现有工具无缝集成。[Get professional support]
安全联系人信息
若要报告安全漏洞,请使用 Tidelift security contact。 Tidelift将协调修复和披露。
项目链接
许可证
麻省理工学院许可。有关详细信息,请参阅捆绑的LICENSE文件。