跳到主要内容

11 篇文档带有标签「pydantic」

查看所有标签

04. JSON

Pydantic 提供了内置的 JSON 解析支持

06. Unions

Unions 的验证方式与其他类型不同,它只需要其中一种类型验证通过即为合法

07. Alias

别名是字段的另一个名称,用于序列化和反序列化数据。

09. Serialization

Beyond accessing model attributes directly via their field names (e.g. model.foobar), models can be converted, dumped, serialized, and exported in a number of ways.

11. Strict Mode

默认情况下,Pydantic 会强制将值转化成期望的数据类型(For example, you can pass the string "123" as the input to an int field, and it will be converted to 123),这种强制性的行为在很多场景下都是很有用的 — think: UUIDs, URL parameters, HTTP headers, environment variables, user input, etc.

pydantic field types

pydantic 尽可能的使用标准库类型(standard library types)来标注字段来提供一个平滑的学习曲线;不过它也实现了许多常用的类型(commonly used types)

pydantic models

通过创建一个继承 BaseModel 的子类(model)来定义一类对象(defining objects)