Registry / devops / hier-config

hier-config

JSON →
library3.6.0pypypi✓ verified 84d ago

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.

pip install hier-config
INSTALL
IMPORT
SIG · HIER-CONFIG
H
hier-config
devopspythonv3.6.0
Install
3.3s avg
Import
566ms
Disk
27MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.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.910 runs
installs and imports cleanly · install 0.0s · import 0.588s · 28.6MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 3.3s · import 0.544s · 28MB
27MB installed
● package 27MB
Code
Verified usage

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

WorkflowRemediation
from hier_config import WorkflowRemediation
get_hconfig
from hier_config import get_hconfig
Platform
from hier_config import Platform
read_text_from_file
from hier_config.utils import read_text_from_file
Host
from hier_config import Host # For hier-config v2.x
from hier_config import Host
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.

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.

from hier_config import WorkflowRemediation, get_hconfig, Platform from hier_config.utils import read_text_from_file import os # Create dummy config files for demonstration running_config_content = ''' hostname DEVICE-RTR-01 ! interface GigabitEthernet0/1 description Uplink to CORE ip address 10.0.0.1 255.255.255.0 no shutdown ! router bgp 65000 neighbor 192.168.1.1 remote-as 65001 ''' intended_config_content = ''' hostname DEVICE-RTR-01-UPDATED ! interface GigabitEthernet0/1 description Uplink to CORE - Primary ip address 10.0.0.1 255.255.255.0 no shutdown ! router bgp 65000 neighbor 192.168.1.1 remote-as 65001 address-family ipv4 unicast neighbor 192.168.1.1 activate ''' with open('running_config.conf', 'w') as f: f.write(running_config_content) with open('intended_config.conf', 'w') as f: f.write(intended_config_content) # Step 1: Load configurations from files running_config_text = read_text_from_file('running_config.conf') intended_config_text = read_text_from_file('intended_config.conf') # Step 2: Create HConfig objects, specifying the device platform running_hconfig = get_hconfig(Platform.CISCO_IOS, running_config_text) intended_hconfig = get_hconfig(Platform.CISCO_IOS, intended_config_text) # Step 3: Initialize WorkflowRemediation to compare and generate remediation workflow = WorkflowRemediation(running_hconfig, intended_hconfig) # Step 4: Print the remediation configuration print('Remediation Configuration:') for line in workflow.remediation_config: print(line.text) # Clean up dummy files os.remove('running_config.conf') os.remove('intended_config.conf')
Debug
Known issues
breakingVersion 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.
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.
affects: >=3.0.0
gotchaJuniper JunOS support is currently experimental and has not been extensively tested. It should be used with caution in production environments.
fix
Exercise caution and thorough testing when using `Platform.JUNIPER_JUNOS`. Refer to the official documentation for updates on its stability.
affects: All v3.x versions
gotchaPrior to v3.5.1, parsing IOS-XR configurations with indented '!' section separators could lead to a `DuplicateChildError`.
fix
Upgrade to hier-config v3.5.1 or newer to resolve the `DuplicateChildError` when parsing IOS-XR configs with indented '!' section separators.
affects: <3.5.1
gotchaIn versions prior to 3.4.1, BGP neighbor descriptions could be dropped in the future config output.
fix
Upgrade to hier-config v3.4.1 or newer to ensure BGP neighbor descriptions are correctly preserved in future configuration predictions.
affects: <3.4.1
Errors
Common errors & fixes
NameError: name 'Host' is not defined
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.
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)`.
ValueError: 'ios_xr' is not a valid Platform
When creating an `HConfig` object, the platform argument expects a `Platform` enum member (e.g., `Platform.CISCO_IOS`), not a string.
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`.
FileNotFoundError: [Errno 2] No such file or directory: './my_config.conf'
The `read_text_from_file` utility function cannot find the specified configuration file at the given path.
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.
Upgrade
Version history
3.6.0latest on PyPI · released Mar 26, 2026
Audit
Dependencies
pythonrequiredRequires Python 3.10 or newer, but less than 4.0.
Agent activity
8 hits · last 30 days
node
8
Resources
hier-config — pip install hier-config · libregistry