{"id":8789,"library":"yamlcore","title":"YAML 1.2 Support for PyYAML","description":"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.","status":"active","version":"0.0.4","language":"en","source_language":"en","source_url":"https://github.com/perlpunk/pyyaml-core","tags":["yaml","pyyaml","parser","serialization","yaml1.2"],"install":[{"cmd":"pip install yamlcore","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"yamlcore is built on top of and depends on PyYAML to provide YAML 1.2 functionality.","package":"PyYAML"}],"imports":[{"note":"Use CoreLoader for loading YAML 1.2 documents.","symbol":"CoreLoader","correct":"from yamlcore import CoreLoader"},{"note":"Use CoreDumper for dumping YAML 1.2 documents.","symbol":"CoreDumper","correct":"from yamlcore import CoreDumper"},{"note":"Use CCoreLoader for C-backed libyaml based parser, for potentially faster performance.","symbol":"CCoreLoader","correct":"from yamlcore import CCoreLoader"},{"note":"Use CCoreDumper for C-backed libyaml based emitter, for potentially faster performance.","symbol":"CCoreDumper","correct":"from yamlcore import CCoreDumper"}],"quickstart":{"code":"import yaml\nfrom yamlcore import CoreLoader, CoreDumper\n\nyaml_string = \"\"\"\n--- 1.1:\n- yes\n- no\n- 1__0\n- 10:20\n- +0b100\n- 0x4_2\ncore:\n- true\n- 0o10\n- 0x42\n- ~\n- .inf\n\"\"\"\n\n# Load using CoreLoader for YAML 1.2 compliance\ndata = yaml.load(yaml_string, Loader=CoreLoader)\nprint(\"Loaded data (Python object):\")\nprint(data)\n\n# Dump using CoreDumper for YAML 1.2 compliance\noutput_yaml = yaml.dump(data, Dumper=CoreDumper)\nprint(\"\\nDumped data (YAML string):\")\nprint(output_yaml)\n\n# Example with a simple dictionary\nsimple_data = {'name': 'Alice', 'age': 30, 'is_active': True}\nsimple_yaml = yaml.dump(simple_data, Dumper=CoreDumper, default_flow_style=False)\nprint(\"\\nSimple data dumped to YAML:\")\nprint(simple_yaml)\n","lang":"python","description":"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."},"warnings":[{"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.","message":"From `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.","severity":"breaking","affected_versions":">=0.0.3"},{"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`.","message":"Using `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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"`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.","severity":"gotcha","affected_versions":"All 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\"`).","message":"YAML 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.","severity":"gotcha","affected_versions":"All versions, especially when migrating from YAML 1.1 sources"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"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.","cause":"`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.","error":"yaml.YAMLError: duplicated key: <key_name>"},{"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.","cause":"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.","error":"yaml.YAMLError: mapping values are not allowed in this context"},{"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)`.","cause":"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.","error":"TypeError: load() missing 1 required positional argument: 'Loader'"}]}