Skip to main content

YAML 1.2 Support for PyYAML

Project description

pyyaml-core - YAML 1.2 Core Schema Support for PyYAML

This module can be used on top of PyYAML to load YAML 1.2 files. It depends on PyYAML and inherits from it, it's not a fork.

Currently it supports enabling all YAML 1.2 Core Schema tags on top of the PyYAML BaseLoader. It does not (yet) support other tags like the << merge key. You can add custom constructors, though.

For more information see the comparison of 1.1 and 1.2 schemas.

Examples

import yaml
from yamlcore import CoreLoader
from yamlcore import CoreDumper

y = """
---
1.1: # strings
- yes
- no # norway problem anymore
- 1__0
- 10:20
- +0b100
- 0x4_2

core:
- true
- 0o10
- 0x42
- ~
- .inf
"""

d = yaml.load(y, Loader=CoreLoader)
out = yaml.dump(d, Dumper=CoreDumper)

You can also use CCoreLoader and CCoreDumper for using the libyaml based parser and emitter.

Why?

At the time of this writing, there is a pending pull request that adds YAML 1.2 Core Schema Support for PyYAML.

It's blocked because there is a plan to redesign the API, and no new things shall be added using the old API at this point.

So as long as PyYAML doesn't merge this, you can use this module as an alternative.

Differences

There are other differences in behaviour to PyYAML.

Duplicate keys are not allowed

The YAML spec forbids duplicate keys. PyYAML allows them, which leads to accidentally added duplicate keys in YAML files, eventually.

I can't see a good use case that people would want to allow duplicate keys in a typical YAML loading process. For the use cases I see you would want your own constructor anyway.

If this is breaking anyone's use case, please let me know.

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

yamlcore-0.0.4.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

yamlcore-0.0.4-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file yamlcore-0.0.4.tar.gz.

File metadata

  • Download URL: yamlcore-0.0.4.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.5

File hashes

Hashes for yamlcore-0.0.4.tar.gz
Algorithm Hash digest
SHA256 c2b1a08dd117cf76a70ee124e936b3c568b0b5c4e5131e69b513f4a877a44881
MD5 6beb706251e5c5974aaa6c9e53e36abe
BLAKE2b-256 ebd4113dfc4c85f945de13b045a20eca50be5f6efa33342d9a9bd6162d26b288

See more details on using hashes here.

File details

Details for the file yamlcore-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: yamlcore-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.5

File hashes

Hashes for yamlcore-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f82a7f7d16baf6531a8c3266b0b63ece251ee2abaf2b9eee040a2f64c8fc618d
MD5 ae59abb5b4bed229b927588890f7f595
BLAKE2b-256 b147632498fd9a3fe4f175e5de71162dd8cd9b2141180a98f0bef6af293aeaa6

See more details on using hashes here.

Supported by

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