ruamel-yaml-clib

raw JSON →
0.2.15 verified Tue May 12 auth: no python install: stale quickstart: stale

ruamel-yaml-clib is a C-based reader, parser, and emitter for the ruamel.yaml library, derived from libyaml. It enhances the performance of ruamel.yaml by providing C extensions for core YAML processing operations. This package was split from ruamel.yaml to facilitate the creation of universal wheels and streamline platform-specific compilation. The current version is 0.2.15.

pip install ruamel-yaml-clib
error ERROR: Failed building wheel for ruamel-yaml-clib
cause The C extension for `ruamel-yaml-clib` could not be compiled, typically due to a missing C/C++ compiler or required development libraries on the system.
fix
Install a C/C++ compiler toolchain (e.g., build-essential on Linux, Xcode Command Line Tools on macOS, Build Tools for Visual Studio on Windows) and retry pip install ruamel-yaml-clib or pip install ruamel.yaml.
error ImportError: cannot import name '_ruamel_yaml' from 'ruamel.yaml.ext._ruamel_yaml'
cause The internal C extension module `_ruamel_yaml`, which is part of `ruamel-yaml-clib` and used by `ruamel.yaml`, failed to load at runtime, often due to a corrupted installation or incompatible environment.
fix
Reinstall ruamel-yaml-clib and ruamel.yaml in a clean virtual environment: pip uninstall ruamel-yaml-clib ruamel.yaml && pip install ruamel.yaml. Ensure no old or conflicting versions are present.
error UserWarning: Cannot load C-module 'ruamel_yaml.ext._ruamel_yaml'
cause The `ruamel.yaml` library failed to load its C extension (provided by `ruamel-yaml-clib`), causing it to fall back to a slower pure Python implementation without stopping execution.
fix
Verify that ruamel-yaml-clib is installed and its C extensions were successfully built. If not, reinstall ruamel-yaml-clib (or ruamel.yaml which pulls it in) ensuring all necessary build tools are available on your system.
breaking Starting with `ruamel.yaml` version 0.19.1, the library no longer automatically installs `ruamel-yaml-clib` as a direct dependency. To ensure the C-accelerated backend is installed, users must explicitly install `ruamel.yaml` with the `libyaml` extra, e.g., `pip install ruamel.yaml[libyaml]`.
fix Install `ruamel.yaml` with the `libyaml` extra: `pip install ruamel.yaml[libyaml]`. If `ruamel-yaml-clib` is installed directly, `ruamel.yaml` will still detect and use it.
gotcha Compilation issues may occur with newer `clang` versions (e.g., >= 16) when building `ruamel-yaml-clib` from source. This typically manifests in environments like FreeBSD where `clang` is the default compiler.
fix Workarounds may involve patching the source code or using an older/different compiler toolchain. Refer to `ruamel.yaml.clib` issue trackers or community discussions for specific patches.
gotcha When `ruamel-yaml-clib` is active (using the C-based SafeLoader/SafeDumper within `ruamel.yaml`), the `yaml.indent` setting applies uniformly to both mappings and sequences. The pure Python implementation of `ruamel.yaml` offers more granular control over indentation styles.
fix If different indentation settings for mappings and sequences are required, instantiate `ruamel.yaml.YAML(pure=True)` to force the pure Python implementation.
deprecated The maintainer has indicated that `ruamel.yaml.clib` will not receive fixes for free-threading issues. `ruamel.yaml.clibz` is the designated replacement for future free-threading support. While `ruamel.yaml.clib` remains functional, this signals a future transition.
fix For applications requiring free-threading support with `ruamel.yaml`'s C backend in the future, monitor `ruamel.yaml`'s documentation for guidance on adopting `ruamel.yaml.clibz`.
breaking `ruamel.yaml` is not installed. Attempting to import `ruamel.yaml` without it being present in the environment will result in a `ModuleNotFoundError`.
fix Install the package using pip: `pip install ruamel.yaml`.
breaking The `ruamel.yaml` package was not found, resulting in a `ModuleNotFoundError`. This indicates the library was not successfully installed in the environment.
fix Ensure `ruamel.yaml` is installed in the test environment using `pip install ruamel.yaml`. Verify installation logs for any errors if the command was executed.
python os / libc status wheel install import disk
3.10 alpine (musl) wheel - - 19.5M
3.10 alpine (musl) - - - -
3.10 slim (glibc) wheel 1.5s - 21M
3.10 slim (glibc) - - - -
3.11 alpine (musl) wheel - - 21.4M
3.11 alpine (musl) - - - -
3.11 slim (glibc) wheel 1.6s - 23M
3.11 slim (glibc) - - - -
3.12 alpine (musl) wheel - - 13.3M
3.12 alpine (musl) - - - -
3.12 slim (glibc) wheel 1.4s - 15M
3.12 slim (glibc) - - - -
3.13 alpine (musl) wheel - - 13.1M
3.13 alpine (musl) - - - -
3.13 slim (glibc) wheel 1.5s - 14M
3.13 slim (glibc) - - - -
3.9 alpine (musl) wheel - - 19.0M
3.9 alpine (musl) - - - -
3.9 slim (glibc) wheel 1.8s - 20M
3.9 slim (glibc) - - - -

This quickstart demonstrates basic loading and dumping of YAML using `ruamel.yaml`. If `ruamel-yaml-clib` is installed, `ruamel.yaml` will use its C extensions for improved performance without requiring any changes to user code. To explicitly use the pure Python implementation, instantiate `YAML(pure=True)`.

import sys
from ruamel.yaml import YAML

# ruamel.yaml will automatically use ruamel-yaml-clib if available
# For pure Python implementation, use: yaml = YAML(pure=True)
yaml = YAML()

data = {
    'name': 'Alice',
    'age': 30,
    'details': {
        'city': 'New York',
        'occupation': 'Engineer'
    }
}

# Dump to string
import io
string_stream = io.StringIO()
yaml.dump(data, string_stream)
yaml_string = string_stream.getvalue()
print('--- Dumped YAML ---')
print(yaml_string)

# Load from string
loaded_data = yaml.load(yaml_string)
print('--- Loaded Data ---')
print(loaded_data['name'])
print(loaded_data['details']['city'])

# Demonstrate round-trip preservation (if ruamel.yaml is configured for it)
config_yaml_str = """
# My config
key: value # inline comment
list:
  - item1
  - item2
"""

rt_yaml = YAML()
rt_data = rt_yaml.load(config_yaml_str)
rt_data['list'].append('item3')

output_stream = io.StringIO()
rt_yaml.dump(rt_data, output_stream)
print('--- Round-trip preserved ---')
print(output_stream.getvalue())