Registry / serialization / yamlloader

yamlloader

JSON →
library1.6.0pypypi✓ verified 85d ago

yamlloader is a Python library (version 1.6.0) that provides ordered YAML loaders and dumpers for PyYAML, ensuring that the order of items in dictionaries is preserved when loading from or dumping to YAML files. It offers faster C-version implementations and automatically falls back to pure Python versions if C bindings are unavailable. The library is actively maintained, with recent updates for Python 3.14 support.

pip install yamlloader
INSTALL
IMPORT
SIG · YAMLLOADER
Y
yamlloader
serializationpythonv1.6.0
Install
1.7s avg
Import
143ms
Disk
18MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.6.0 · 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.144s · 20MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.7s · import 0.142s · 21MB
18MB installed
● package 18MB
Code
Verified usage

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

yamlloader
import yamlloader
The main package import.
CLoader
from yamlloader.ordereddict import CLoader
from yamlloader import CLoader
CLoader (and CDumper) are within the 'ordereddict' submodule. Using the C-versions is recommended for performance; they gracefully fall back to pure Python if C bindings are not compiled for PyYAML.
CDumper
from yamlloader.ordereddict import CDumper
CDumper for dumping YAML while preserving order, with C-speed if available.
yaml
import yaml
yamlloader builds on PyYAML, so the base PyYAML library is often imported alongside it.

This quickstart demonstrates how to load and dump YAML content using `yamlloader`'s `CLoader` and `CDumper` to ensure dictionary order is preserved. It highlights how `yaml.load` is used with the custom loader and how the order is maintained in the resulting Python object, even for standard dictionaries in Python 3.7+.

import yaml from yamlloader.ordereddict import CLoader, CDumper import os yaml_content = """ key_a: value_1 key_b: value_2 key_c: value_3 list_items: - item1 - item2 - item3 """ # Create a dummy YAML file with open('config.yaml', 'w') as f: f.write(yaml_content) # --- Loading YAML --- print('--- Loading YAML ---') with open('config.yaml', 'r') as f: # Using CLoader to preserve order data = yaml.load(f, Loader=CLoader) print(f"Loaded data type: {type(data)}") print(f"Loaded data: {data}") # Verify order preservation (Python 3.7+ dicts preserve insertion order by default, # but yamlloader explicitly guarantees and was designed around OrderedDict behavior) expected_keys = ['key_a', 'key_b', 'key_c', 'list_items'] actual_keys = list(data.keys()) print(f"Keys in order: {actual_keys == expected_keys}") # --- Dumping YAML --- print('\n--- Dumping YAML ---') modified_data = data modified_data['new_key'] = 'new_value' output_yaml = yaml.dump(modified_data, Dumper=CDumper, default_flow_style=False) print(f"Dumped YAML:\n{output_yaml}") # Clean up dummy file os.remove('config.yaml')
Debug
Known issues
breakingSupport for Python 3.7 was dropped in `yamlloader` version 1.3.2. Users on Python 3.7 must use `yamlloader` version 1.2 or older. Later versions require Python 3.8+.
fix
Upgrade Python to 3.8+ or pin `yamlloader` to `<1.3.0` for Python 3.7 environments.
affects: >=1.3.2
deprecatedPyYAML's `yaml.load()` function without an explicit `Loader` argument (e.g., `yaml.load(file_obj)`) has been deprecated since PyYAML 5.1 due to security concerns, as it could lead to arbitrary code execution when processing untrusted YAML. While `yamlloader`'s examples always specify a Loader, users might accidentally revert to the insecure pattern.
fix
Always explicitly specify a loader when calling `yaml.load()`. For safe loading of untrusted input, use `yaml.safe_load()` or `yaml.load(file, Loader=yaml.SafeLoader)`. When using `yamlloader`, ensure you pass its specific loaders: `yaml.load(file, Loader=yamlloader.ordereddict.CLoader)` or `yaml.load(file, Loader=yamlloader.ordereddict.CSafeLoader)`.
affects: PyYAML >=5.1
gotchaWhile `yamlloader` explicitly uses `OrderedDict` internally (and `dict` for Python 3.7+ as `dict` preserves insertion order), prior to `yamlloader 1.0.0`, it might have behaved differently with Python 3.7+ native `dict` ordering. Since `1.0.0`, it consistently returns `OrderedDict` or order-preserving `dict` for all supported Python versions.
fix
For consistent ordered dictionary behavior, ensure you are using `yamlloader` version `1.0.0` or newer. For Python 3.7+, standard `dict`s preserve insertion order, but explicit `OrderedDict`s or `yamlloader`'s wrappers provide a stronger guarantee and consistent API.
affects: <1.0.0
gotchayamlloader leverages PyYAML's C-bindings for performance (`CLoader`, `CDumper`). If PyYAML was installed without C extensions (e.g., missing `libyaml-dev` or `Cython`), these C-versions will automatically fall back to their pure Python equivalents. This fallback is usually seamless but can hide performance issues. You can disable this fallback by setting `yamlloader.settings.ALLOW_C_VERSION_FALLBACK = False` which will cause an error if C-versions are unavailable.
fix
To ensure C-version performance, install `libyaml-dev` (or equivalent for your OS) and `Cython` before installing PyYAML or `yamlloader`. Check `yaml.cyaml` exists in your environment to verify C-binding availability.
affects: All
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'yaml'
The underlying PyYAML library, which `yamlloader` depends on, is not installed.
fix
Install PyYAML: `pip install pyyaml` (or simply `pip install yamlloader` which should pull in PyYAML as a dependency).
YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://pyyaml.readthedocs.io/en/latest/api.html#yamllib-org-api
You are calling PyYAML's `yaml.load()` function without explicitly specifying a `Loader` class. This warning is from PyYAML itself, which `yamlloader` uses.
fix
Always provide a `Loader` argument. For `yamlloader`'s ordered loading, use `yaml.load(file_obj, Loader=yamlloader.ordereddict.CLoader)`. For general safe loading, use `yaml.safe_load(file_obj)` or `yaml.load(file_obj, Loader=yaml.SafeLoader)`.
MemoryError: cannot allocate vector of size ...
Attempting to load a very large YAML file (e.g., several gigabytes) into memory at once, potentially exceeding available RAM.
fix
For extremely large YAML files, consider processing them in chunks if the structure allows, or using alternative streaming parsers not offered by `yamlloader`/`PyYAML`. Ensure your system has sufficient RAM for the file size.
yaml.scanner.ScannerError: while scanning for the next token found character '\t' that cannot start any token in "<string>", line X, column Y
YAML syntax is very strict about indentation. This error typically means you've used a tab character for indentation where spaces are required, or there's an inconsistent mix of tabs and spaces.
fix
Replace all tab characters with spaces for indentation in your YAML file. Many text editors have 'convert tabs to spaces' functionality. Ensure consistent indentation levels (e.g., always 2 or 4 spaces).
Upgrade
Version history
1.6.0latest on PyPI · released Nov 10, 2025
Audit
Dependencies
PyYAMLrequiredyamlloader extends and relies on PyYAML for core YAML parsing and serialization functionality. It became an explicit runtime requirement in version 1.5.2.
Agent activity
19 hits · last 30 days
node
16
Amazon
1
Bingbot
1
OpenAI (training)
1
Resources
yamlloader — pip install yamlloader · libregistry