首页 > 文章列表 > python中marshmallow库如何使用

python中marshmallow库如何使用

Python marshmallow
143 2022-08-07

概念

1、是专门用来支持 Python 对象和原生数据相互转换的库,如实现 object -> dict,objects -> list, string -> dict, string -> list 等的转换功能。

2、提供了非常丰富的数据类型转换和校验 API,帮助我们快速实现数据的转换。

实例

调用 Schema 的 load 事件:

schema = UserSchema()
users = schema.load(data, many=True)
print(users)

输出结果:

[User(name='Germey', age=23), User(name='Mike', age=20)]

本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。