{"id":9036,"library":"hier-config","title":"Hierarchical Configuration (hier-config)","description":"Hierarchical Configuration, or hier-config, is a Python library designed to query and compare network device configurations. It parses configuration text into a hierarchical tree to perform deterministic, line-level diffs that respect vendor syntax rules. This allows it to generate precise remediation commands to bring a device into compliance with an intended configuration. The library is actively maintained, with its current version being 3.6.0, and new releases occurring regularly.","status":"active","version":"3.6.0","language":"en","source_language":"en","source_url":"https://github.com/netdevops/hier_config","tags":["network automation","configuration management","network device","diff","remediation","compliance"],"install":[{"cmd":"pip install hier-config","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Requires Python 3.10 or newer, but less than 4.0.","package":"python","optional":false}],"imports":[{"symbol":"WorkflowRemediation","correct":"from hier_config import WorkflowRemediation"},{"symbol":"get_hconfig","correct":"from hier_config import get_hconfig"},{"symbol":"Platform","correct":"from hier_config import Platform"},{"symbol":"read_text_from_file","correct":"from hier_config.utils import read_text_from_file"},{"note":"The 'Host' class was used in hier-config v2.x. In v3.x, it has been replaced by 'get_hconfig' and 'Platform' for creating configuration objects.","wrong":"from hier_config import Host","symbol":"Host","correct":"from hier_config import Host # For hier-config v2.x"}],"quickstart":{"code":"from hier_config import WorkflowRemediation, get_hconfig, Platform\nfrom hier_config.utils import read_text_from_file\nimport os\n\n# Create dummy config files for demonstration\nrunning_config_content = '''\nhostname DEVICE-RTR-01\n!\ninterface GigabitEthernet0/1\n description Uplink to CORE\n ip address 10.0.0.1 255.255.255.0\n no shutdown\n!\nrouter bgp 65000\n neighbor 192.168.1.1 remote-as 65001\n'''\n\nintended_config_content = '''\nhostname DEVICE-RTR-01-UPDATED\n!\ninterface GigabitEthernet0/1\n description Uplink to CORE - Primary\n ip address 10.0.0.1 255.255.255.0\n no shutdown\n!\nrouter bgp 65000\n neighbor 192.168.1.1 remote-as 65001\n address-family ipv4 unicast\n  neighbor 192.168.1.1 activate\n'''\n\nwith open('running_config.conf', 'w') as f:\n    f.write(running_config_content)\n\nwith open('intended_config.conf', 'w') as f:\n    f.write(intended_config_content)\n\n# Step 1: Load configurations from files\nrunning_config_text = read_text_from_file('running_config.conf')\nintended_config_text = read_text_from_file('intended_config.conf')\n\n# Step 2: Create HConfig objects, specifying the device platform\nrunning_hconfig = get_hconfig(Platform.CISCO_IOS, running_config_text)\nintended_hconfig = get_hconfig(Platform.CISCO_IOS, intended_config_text)\n\n# Step 3: Initialize WorkflowRemediation to compare and generate remediation\nworkflow = WorkflowRemediation(running_hconfig, intended_hconfig)\n\n# Step 4: Print the remediation configuration\nprint('Remediation Configuration:')\nfor line in workflow.remediation_config:\n    print(line.text)\n\n# Clean up dummy files\nos.remove('running_config.conf')\nos.remove('intended_config.conf')\n","lang":"python","description":"This quickstart demonstrates how to load existing and intended device configurations, create hierarchical configuration objects, and then use `WorkflowRemediation` to generate the commands needed to bring the running configuration into compliance with the intended state. It simulates config files and cleans them up afterwards."},"warnings":[{"fix":"Migrate your code to use `get_hconfig(Platform.<YOUR_PLATFORM>, config_text)` instead of `Host(hostname=..., os=...)`. Review driver documentation for how to handle OS-specific options.","message":"Version 3.x introduced significant breaking changes from version 2.x, primarily replacing the `Host` object with `get_hconfig` and `Platform` enums for creating configuration objects, and migrating from dictionary-based options to Pydantic driver models.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Exercise caution and thorough testing when using `Platform.JUNIPER_JUNOS`. Refer to the official documentation for updates on its stability.","message":"Juniper JunOS support is currently experimental and has not been extensively tested. It should be used with caution in production environments.","severity":"gotcha","affected_versions":"All v3.x versions"},{"fix":"Upgrade to hier-config v3.5.1 or newer to resolve the `DuplicateChildError` when parsing IOS-XR configs with indented '!' section separators.","message":"Prior to v3.5.1, parsing IOS-XR configurations with indented '!' section separators could lead to a `DuplicateChildError`.","severity":"gotcha","affected_versions":"<3.5.1"},{"fix":"Upgrade to hier-config v3.4.1 or newer to ensure BGP neighbor descriptions are correctly preserved in future configuration predictions.","message":"In versions prior to 3.4.1, BGP neighbor descriptions could be dropped in the future config output.","severity":"gotcha","affected_versions":"<3.4.1"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Replace `from hier_config import Host` with `from hier_config import get_hconfig, Platform` and create configuration objects using `get_hconfig(Platform.<YOUR_PLATFORM>, config_text)`.","cause":"Attempting to use the `Host` class from hier-config v2.x in a v3.x environment. The `Host` class was removed in v3.0.0.","error":"NameError: name 'Host' is not defined"},{"fix":"Import `Platform` from `hier_config` and use its members, e.g., `get_hconfig(Platform.CISCO_IOSXR, config_text)`. Available platforms can be listed via `hier-config-cli list-platforms`.","cause":"When creating an `HConfig` object, the platform argument expects a `Platform` enum member (e.g., `Platform.CISCO_IOS`), not a string.","error":"ValueError: 'ios_xr' is not a valid Platform"},{"fix":"Verify that the file path provided to `read_text_from_file` is correct and that the file exists at that location relative to your script, or provide an absolute path.","cause":"The `read_text_from_file` utility function cannot find the specified configuration file at the given path.","error":"FileNotFoundError: [Errno 2] No such file or directory: './my_config.conf'"}]}