{"id":371,"library":"ruamel.yaml","title":"ruamel.yaml","description":"ruamel.yaml is a YAML parser and emitter for Python that supports round-trip preservation of comments, sequence and mapping flow styles, and map key order. The current version is 0.19.1, released on March 28, 2026. It is actively maintained with regular updates.","status":"active","version":"0.19.1","language":"python","source_language":"en","source_url":"https://github.com/ruamel/yaml","tags":["YAML","parser","emitter","Python"],"install":[{"cmd":"pip install ruamel.yaml","lang":"bash","label":"Install ruamel.yaml"}],"dependencies":[],"imports":[{"note":"Ensure 'ruamel.yaml' is imported as 'YAML' to access the 'YAML' class.","symbol":"YAML","correct":"import ruamel.yaml as YAML"}],"quickstart":{"code":"import os\nimport ruamel.yaml as YAML\n\n# Load YAML data\nwith open(os.environ.get('YAML_FILE_PATH', 'data.yaml'), 'r') as file:\n    data = YAML().load(file)\n\n# Modify data\ndata['new_key'] = 'new_value'\n\n# Save YAML data\nwith open(os.environ.get('YAML_FILE_PATH', 'data.yaml'), 'w') as file:\n    YAML().dump(data, file)","lang":"python","description":"A basic example demonstrating how to load, modify, and save YAML data using ruamel.yaml."},"warnings":[{"fix":"Open the file using 'with open()' before passing it to 'load'.","message":"The 'load' method in ruamel.yaml requires a file object, not a string. Ensure you open the file before passing it to 'load'.","severity":"breaking","affected_versions":"0.19.1"},{"fix":"Always import 'ruamel.yaml' as 'YAML' to access the 'YAML' class.","message":"The 'YAML' class is case-sensitive. Using 'yaml' instead of 'YAML' will result in an AttributeError.","severity":"gotcha","affected_versions":"0.19.1"},{"fix":"Ensure the YAML file exists at the correct path relative to the script's execution directory, or verify that the 'YAML_FILE_PATH' environment variable is set to a valid, existing file path.","message":"The script failed with FileNotFoundError because the specified YAML file ('data.yaml' by default or via the 'YAML_FILE_PATH' environment variable) does not exist at the expected location.","severity":"breaking","affected_versions":"0.19.1"},{"fix":"Create the 'data.yaml' file in the expected location or verify the value of the 'YAML_FILE_PATH' environment variable to ensure it points to an existing YAML file.","message":"The specified YAML file could not be found at the given path. Ensure the file exists and the path is correct, or that the 'YAML_FILE_PATH' environment variable points to a valid file.","severity":"breaking","affected_versions":"all"}],"env_vars":null,"search_vec":"'0.19.1':32 '2026':37 '28':36 'activ':40 'comment':18 'current':29 'emitt':8,47 'flow':22 'key':26 'maintain':41 'map':21,25 'march':35 'order':27 'parser':6,46 'preserv':16 'python':10,48 'regular':43 'releas':33 'round':14 'round-trip':13 'ruamel.yaml':1,2 'sequenc':19 'style':23 'support':12 'trip':15 'updat':44 'version':30 'yaml':5,45","created_at":"2026-03-28T10:52:36.555142+00:00","updated_at":"2026-04-16T21:12:37.622254+00:00","problems":[{"fix":"Instantiate a `YAML` object and then use its `load()` method:\n```python\nfrom ruamel.yaml import YAML\nyaml = YAML()\nwith open('your_file.yaml') as f:\n    data = yaml.load(f)\n```","cause":"Attempting to call `load()` as a top-level function directly from the `ruamel.yaml` module, which is the API for older `PyYAML` but not modern `ruamel.yaml`.","error":"AttributeError: module 'ruamel.yaml' has no attribute 'load'"},{"fix":"Open the file first and pass the file object to the `load()` or `dump()` method:\n```python\nfrom ruamel.yaml import YAML\nyaml = YAML()\nwith open('config.yaml', 'r') as f:\n    data = yaml.load(f)\n```","cause":"Passing a string (typically a file path) directly to the `yaml.load()` or `yaml.dump()` method, which expects a file-like object (e.g., from `open()`).","error":"TypeError: 'str' object cannot be interpreted as a file-like object"},{"fix":"Review the YAML file for syntax errors, paying close attention to indentation, key-value pair formatting, and proper use of lists and dictionaries.","cause":"The YAML input file contains invalid syntax, such as incorrect indentation, missing colons, or improperly structured mappings/sequences.","error":"ruamel.yaml.parser.ParserError"},{"fix":"Inspect the YAML file for invalid characters, ensure proper escaping of special characters, and correct any malformed strings or flow collection syntax.","cause":"The YAML input contains lexical errors, such as illegal characters, unescaped special characters (e.g., '%' or '@' at the start of a line), or incorrect quoting.","error":"ruamel.yaml.scanner.ScannerError"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"quickstart_score":0,"quickstart_tag":"stale","pypi_latest":"0.19.1","cli_name":"","cli_version":null,"type":"library","homepage":"https://sourceforge.net/p/ruamel-yaml/","github":null,"docs":"https://yaml.dev/doc/ruamel.yaml","changelog":null,"pypi":"https://pypi.org/project/ruamel.yaml/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["serialization","data"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-27","next_check":"2026-07-28","install_tag":"verified"}}