"Adds some YAML functionality to the excellent `pydantic` library."
Project description
pydantic-yaml
This is a small helper library that adds some YAML capabilities to pydantic, namely dumping to yaml via the yaml_model.yaml()
function, and parsing from strings/files using YamlModel.parse_raw()
and YamlModel.parse_file()
. It also adds an Enum
subclass that gets dumped to YAML as a string, and fixes dumping of some typical types.
Usage
Example usage is seen below.
from pydantic_yaml import YamlEnum, YamlModel
class MyEnum(str, YamlEnum):
a = "a"
b = "b"
class MyModel(YamlModel):
x: int = 1
e: MyEnum = MyEnum.a
m1 = MyModel(x=2, e="b")
yml = m1.yaml()
m2 = MyModel.parse_raw(yml, proto="yaml")
assert m1 == m2
m3 = MyModel.parse_raw(yml, content_type="application/yaml")
assert m1 == m3
Installation
pip install pydantic_yaml
Make sure to install ruamel.yaml
(recommended) or pyyaml
as well. These are optional dependencies:
pip install pydantic_yaml[ruamel]
pip install pydantic_yaml[pyyaml]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pydantic_yaml-0.3.0.tar.gz
(6.2 kB
view hashes)
Built Distribution
Close
Hashes for pydantic_yaml-0.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d7d56adc4a7ca1df19f9855ed47b8b8603b49f374ca2d67d61362356afc9364 |
|
MD5 | 86f78c53a1d61c4739c7e417b18aa54f |
|
BLAKE2b-256 | fd3d26b78ce50fd64b1570e22b3be31725d32a7845342021e9e0056313cc1854 |