Registry / serialization / yamlcore

yamlcore

JSON →
library0.0.4pypypi✓ verified 85d ago

This module provides YAML 1.2 Core Schema support on top of PyYAML. It acts as an extension, depending on and inheriting from PyYAML, rather than being a fork. It enables all YAML 1.2 Core Schema tags for PyYAML's BaseLoader. Developed as an alternative while native YAML 1.2 support was pending in PyYAML, it is actively maintained. The current version is 0.0.4, released in October 2024, with a focused release cadence for improvements and fixes.

pip install yamlcore
INSTALL
IMPORT
SIG · YAMLCORE
Y
yamlcore
serializationpythonv0.0.4
Install
1.7s avg
Import
135ms
Disk
18MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.0.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.138s · 20MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.7s · import 0.131s · 21MB
18MB installed
● package 18MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

CoreLoader
from yamlcore import CoreLoader
Use CoreLoader for loading YAML 1.2 documents.
CoreDumper
from yamlcore import CoreDumper
Use CoreDumper for dumping YAML 1.2 documents.
CCoreLoader
from yamlcore import CCoreLoader
Use CCoreLoader for C-backed libyaml based parser, for potentially faster performance.
CCoreDumper
from yamlcore import CCoreDumper
Use CCoreDumper for C-backed libyaml based emitter, for potentially faster performance.

This quickstart demonstrates loading and dumping YAML 1.2 compliant data using `yamlcore.CoreLoader` and `yamlcore.CoreDumper` with the standard `PyYAML` `yaml.load` and `yaml.dump` functions. It highlights the differences in how YAML 1.1 and 1.2 interpret certain literals.

import yaml from yamlcore import CoreLoader, CoreDumper yaml_string = """ --- 1.1: - yes - no - 1__0 - 10:20 - +0b100 - 0x4_2 core: - true - 0o10 - 0x42 - ~ - .inf """ # Load using CoreLoader for YAML 1.2 compliance data = yaml.load(yaml_string, Loader=CoreLoader) print("Loaded data (Python object):") print(data) # Dump using CoreDumper for YAML 1.2 compliance output_yaml = yaml.dump(data, Dumper=CoreDumper) print("\nDumped data (YAML string):") print(output_yaml) # Example with a simple dictionary simple_data = {'name': 'Alice', 'age': 30, 'is_active': True} simple_yaml = yaml.dump(simple_data, Dumper=CoreDumper, default_flow_style=False) print("\nSimple data dumped to YAML:") print(simple_yaml)
Debug
Known issues
breakingFrom `yamlcore` v0.0.3 onwards, duplicate keys in YAML mappings are explicitly forbidden and will raise an error during loading. This is a significant change from standard PyYAML's historical behavior, which silently overwrites earlier duplicate keys, and aligns with the YAML specification.
fix
Ensure all keys within YAML mappings are unique. Use tools like `yamllint` or YAML-aware editors to detect duplicate keys before processing. If duplicate keys are intentionally present for specific logic, consider restructuring your YAML or processing it as a list of key-value pairs at a lower level.
affects: >=0.0.3
gotchaUsing `yaml.load()` (from PyYAML, which `yamlcore` builds upon) without explicitly specifying a Loader (e.g., `Loader=CoreLoader` or `Loader=yaml.SafeLoader`) can be a severe security risk if processing untrusted input. The default `UnsafeLoader` allows arbitrary code execution.
fix
Always explicitly specify a `Loader` when calling `yaml.load()`. For `yamlcore`, use `CoreLoader` (or `CCoreLoader`). For general safe loading with PyYAML, use `yaml.SafeLoader`.
affects: All versions
gotcha`yamlcore` currently only supports enabling YAML 1.2 Core Schema tags and does not yet support other advanced YAML features like the `<<` merge key. If your YAML relies on such features, `yamlcore` might not parse it as expected.
fix
Avoid using merge keys (`<<`) and other unsupported YAML 1.2 tags when processing documents with `yamlcore`. Check the `yamlcore` documentation for a complete list of supported tags and features.
affects: All versions
gotchaYAML 1.1 parsers (like older PyYAML versions) treat certain literals like `yes`, `no`, `on`, `off` as booleans and numbers like `10:20` (base-60) as integers, which were changed in YAML 1.2 to be typically parsed as strings or different types. While `yamlcore` aims for YAML 1.2 compliance, be aware of this historical context when migrating or dealing with mixed YAML versions.
fix
When writing YAML for `yamlcore` (YAML 1.2), use explicit `true`/`false` for booleans and quote strings that might otherwise be implicitly typed (e.g., `"yes"`, `"0o10"`).
affects: All versions, especially when migrating from YAML 1.1 sources
Errors
Common errors & fixes
yaml.YAMLError: duplicated key: <key_name>
`yamlcore` (from v0.0.3) strictly enforces the YAML 1.2 specification, which prohibits duplicate keys within a single mapping. Earlier versions of PyYAML might have silently overwritten duplicate keys.
fix
Review your YAML file to identify and remove any duplicate keys within mappings. Each key in a YAML dictionary must be unique. Use YAML validators or linters to pinpoint exact locations.
yaml.YAMLError: mapping values are not allowed in this context
This error often indicates incorrect indentation or the use of tabs instead of spaces in your YAML file. YAML is highly sensitive to whitespace for structural definition, and tabs are universally forbidden by the spec.
fix
Ensure all indentation uses spaces consistently (usually 2 or 4 spaces per level) and that no tabs are present in your YAML file. Many text editors have features to convert tabs to spaces or highlight mixed indentation.
TypeError: load() missing 1 required positional argument: 'Loader'
Starting with PyYAML 5.1 (and therefore affecting `yamlcore` usage indirectly), calling `yaml.load()` without explicitly providing a `Loader` argument is deprecated and will eventually become an error, to enforce safer loading practices.
fix
Always specify a `Loader` when calling `yaml.load()`. For `yamlcore`'s YAML 1.2 capabilities, use `yaml.load(your_data, Loader=CoreLoader)` (or `CCoreLoader`). For general safe PyYAML loading, use `yaml.load(your_data, Loader=yaml.SafeLoader)`.
Upgrade
Version history
0.0.4latest on PyPI · released Oct 9, 2024
Audit
Dependencies
PyYAMLrequiredyamlcore is built on top of and depends on PyYAML to provide YAML 1.2 functionality.
Agent activity
40 hits · last 30 days
node
34
OpenAI (training)
1
Resources