Skip to main content

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


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.2.3.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pydantic_yaml-0.2.3-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file pydantic_yaml-0.2.3.tar.gz.

File metadata

  • Download URL: pydantic_yaml-0.2.3.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.8.6

File hashes

Hashes for pydantic_yaml-0.2.3.tar.gz
Algorithm Hash digest
SHA256 19b880d6ecff0395ca08d7db64200a5284759e40b4452e92b5f0e86ca637d60e
MD5 093149454cecdf1644b798c582f6a646
BLAKE2b-256 5f2d49dc773812226ae4a6c1ea73aadcf8cae98c4e27a3fdb50fee6a15bc2696

See more details on using hashes here.

File details

Details for the file pydantic_yaml-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: pydantic_yaml-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.8.6

File hashes

Hashes for pydantic_yaml-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4896565fa4047659ed0e701753b45861d586bb1784ac222ad9353ad2cefc80a5
MD5 5c3252648e576367a9c7aa9d51cc86df
BLAKE2b-256 883865a0d99f98ba89d5154f8595da8a5a26e5a71669e15284eb5e9a0a031d70

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page