Introduction
On November 25, 2026, we published hier_config 4.0.0. This is the first major release since version 3, which I wrote about in December 2024.
Hierarchical Configuration (hier_config) is an open source Python library. It parses network device configurations into a tree. You can then compare two trees, build a remediation, predict a future configuration, and roll back a change.
Version 4 keeps the same concepts. You still build trees, use drivers, and run a WorkflowRemediation. The biggest change is under the API. A Rust core now parses the text, holds the tree, and calculates the remediation.
What is new
A Rust core
Version 3 was pure Python. In version 4, the parser, the tree, and the remediation engine are Rust code. The Python package calls that code through PyO3.
Version 4 is faster on large configurations. I did a small test on an Apple M3 laptop with Python 3.12. The test used one Cisco IOS configuration of 10,001 lines with 2,000 interfaces. I used timeit, and each value is the best of 3 repeats of 5 runs. In a second run of the test, the repeats varied by less than 0.5 ms, except one version 4 parse at 3.2 ms.
| Operation | 3.7.1 | 4.0.0 |
|---|---|---|
| Parse the configuration | 49.0 ms | 1.9 ms |
| Build a remediation | 28.6 ms | 2.2 ms |
In this test, version 4 parsed the configuration 26 times faster and built the remediation 13 times faster. I did not measure many small configurations. For a small configuration, the cost of each call from Python to Rust can be a larger part of the total.
The project benchmark page gives more measurements. On a 10,000-line configuration, it reports a parse that is 31 times faster and a remediation that is 12 times faster. It also reports that copy.deepcopy() is 259 times faster. Your results will change with your configurations and your hardware.
The benchmark page also states that the Rust core releases the Python GIL while it parses and diffs a configuration. Thus, a thread pool can process many devices on many CPU cores. In version 3, you needed multiprocessing for this. I did not measure a workload with threads, so this claim comes from the project only.
Class method constructors
Version 4 adds constructors on the HConfig class:
from hier_config import HConfig, Platform
running = HConfig.from_text(Platform.CISCO_IOS, running_text)
lines = HConfig.from_lines(Platform.CISCO_IOS, list_of_lines)
restored = HConfig.from_dump(Platform.CISCO_IOS, dump)
JSON and XML configurations
Version 4 can read structured configurations. HConfig.from_json() reads JSON, for example OpenConfig data. HConfig.from_xml() reads XML, for example a NETCONF payload. to_json() and to_xml() write the tree back in the same format.
You can diff these trees and predict a future configuration, the same as with CLI text. WorkflowRemediation can also render the remediation in two new formats:
remediation_netconf_xml()gives a NETCONFedit-configpayload.remediation_json()gives a structure in the shape of a gNMISetRequest.
A report on future configurations
HConfig.future() predicts the configuration after you apply a change. The new future_with_report() also returns a FutureReport. The report lists each negation that matched nothing in the running configuration.
future, report = running.future_with_report(change)
if report.unresolved_negations:
print("Some negations did not apply:", report.unresolved_negations)
In version 3, you had to search the output for no lines to find this problem.
future() also has a new prune_empty_branches=True option. It removes a section that the change made empty.
A driver registry
In version 3, a custom driver needed its own constructor function. Version 4 has a driver registry. You register a driver by name, and then you use that name anywhere that accepts a Platform.
from hier_config import HConfig, register_driver
from hier_config.platforms.cisco_ios.driver import HConfigDriverCiscoIOS
class MyIOSDriver(HConfigDriverCiscoIOS):
pass
register_driver("my_ios", MyIOSDriver)
config = HConfig.from_text("my_ios", "hostname router1")
You can also replace a built-in driver with your own, and restore it later with unregister_driver(). get_registered_platforms() lists the registered platforms.
New platforms
Version 4 adds two platform drivers:
Platform.ARUBA_AOSCXfor Aruba AOS-CX, with a config view.Platform.RUCKUS_FASTIRONfor Ruckus and Brocade FastIron (ICX).
The config views for Arista EOS, Cisco NX-OS, and Cisco IOS XR are now complete. In version 3, many of their properties raised NotImplementedError.
Remediation plugins
WorkflowRemediation has a new plugins parameter. A plugin is a function that takes the remediation HConfig and changes it. You can keep your own remediation transforms in your own package and apply them to each workflow.
A driver can also declare remediation_transform_callbacks. These callbacks change the remediation after the diff and before the workflow returns it.
What changed
Many names changed, and the old names still work
Version 4 renames many functions and methods. The version 3 names stay as permanent aliases. They do not give a DeprecationWarning, and the project has no plan to remove them.
| Version 3 | Version 4 |
|---|---|
get_hconfig(platform, text) | HConfig.from_text(platform, text) |
get_hconfig_fast_load(platform, lines) | HConfig.from_lines(platform, lines) |
get_hconfig_from_dump(platform, dump) | HConfig.from_dump(platform, dump) |
config.config_to_get_to(target) | config.remediation(target) |
config.dump_simple() | config.to_lines() |
child.cisco_style_text() | child.indented_text() |
child.tags_add() and child.tags_remove() | child.add_tags() and child.remove_tags() |
load_hconfig_v2_options() | load_driver_rules() |
load_hconfig_v2_tags() | load_tag_rules() |
Use the new names in new code. You do not have to change the old calls.
One model for negation rules
Version 3 had three negation rule models. Version 4 has one NegationRule model with a NegationStrategy:
| Version 3 | Version 4 strategy |
|---|---|
NegationDefaultWithRule | NegationStrategy.REPLACE |
NegationDefaultWhenRule | NegationStrategy.DEFAULT |
NegationSubRule | NegationStrategy.REGEX_SUB |
All the rules go in one ordered negation list on HConfigDriverRules. Here is a version 4 rule:
from hier_config import HConfigDriverRules, MatchRule
from hier_config.models import NegationRule, NegationStrategy
rules = HConfigDriverRules(
negation=[
NegationRule(
strategy=NegationStrategy.REPLACE,
match_rules=(MatchRule(startswith="logging console "),),
use="logging console debugging",
)
],
)
The three version 3 models and their lists also stay. A version 3 call such as driver.rules.negate_with.append(...) still works.
Typed exceptions
Version 4 adds its own exceptions. All of them are subclasses of HierConfigError:
| Condition | Exception |
|---|---|
| The platform is not known | DriverNotFoundError |
| The configuration input is not valid | InvalidConfigError |
| The running and generated configurations use different drivers | IncompatibleDriverError |
| A duplicate child is not permitted | DuplicateChildError |
Python and the package
- Version 4 needs Python 3.11 or later. Version 3.7.1 supported Python 3.10.
- hier_config is now a compiled wheel. PyPI has wheels for Linux (glibc and musl), macOS, and Windows, on x86_64 and ARM64.
- There is no pure Python fallback. On other platforms, pip builds from source, and you need a Rust toolchain.
- PyYAML is now optional. If you load rules from YAML files, install
hier-config[yaml].
Smaller behavior changes
The Rust core also changes some object behavior. These items can affect code that worked on version 3:
WorkflowRemediation.running_configandgenerated_configare read-only. To use different inputs, make a new workflow. The configuration trees stay mutable.HConfigChild.commentsis now a live view. A change to it changes the configuration. To get a copy, useset(child.comments).- Some view properties return
Nonewhere version 3 raised an exception. For example, IOS speedautonow returnsNone. InterfaceDuplex.valueis now"auto","full", or"half". In version 3, it was"1","2", or"3".- Two traversals of the same tree can give different Python objects for one node.
==andhash()work as before. Do not useisorid()to compare nodes. - Pickles from version 3 do not load in version 4.
The Rust core behavior changes page has the full list.
How to upgrade from version 3
A script that uses only the public version 3 API and the built-in drivers usually runs on version 4 with no change. A custom driver needs changes. Step 7 tells you what to change. I ran this version 3 script on 3.7.1 and on 4.0.0. Both gave the same remediation:
from hier_config import Platform, WorkflowRemediation, get_hconfig
running = get_hconfig(Platform.CISCO_IOS, running_text)
intended = get_hconfig(Platform.CISCO_IOS, intended_text)
workflow = WorkflowRemediation(running, intended)
print(workflow.remediation_config_filtered_text(include_tags=(), exclude_tags=()))
The project tests this. A recording of version 3.7.0 output is in the repository. On each push, CI compares version 4 against it in test_v3_baseline.py. I did not review how much of the API that test covers.
Some changes need action before you upgrade.
Step 1: Pin the version
Keep production on version 3 until you finish the upgrade:
hier-config>=3.7,<4
Step 2: Check Python and the platform
Make sure that your systems use Python 3.11 or later. Make sure that PyPI has a wheel for your platform. If it does not, install a Rust toolchain on the build host.
Step 3: Install version 4 in a test environment
pip install 'hier-config>=4,<5'
If you load rules from YAML files, install the extra:
pip install 'hier-config[yaml]>=4,<5'
Step 4: Change depth() to depth
depth is now a property. This is the only rename that has no alias. If you call depth(), version 4 raises this error:
TypeError: 'int' object is not callable
Remove the parentheses:
# version 3
level = child.depth()
# version 4
level = child.depth
Step 5: Update the exception handlers
Find each except ValueError and each except TypeError near a hier_config call. Catch the new exception, or catch HierConfigError for all of them:
from hier_config import HConfig, HierConfigError
try:
config = HConfig.from_text(platform, config_text)
except HierConfigError as error:
print(f"hier_config error: {error}")
Step 6: Make sure that the input is CLI text
HConfig.from_text() and get_hconfig() now reject JSON and XML input with InvalidConfigError. Version 3 accepted this input and made one node from each line of text. I gave a short JSON document to get_hconfig() on 3.7.1, and dump_simple() returned this tree:
('{', ' "hostname": "r1",', ' "interfaces": ["Gi0/1"]', '}')
For structured input, use HConfig.from_json() or HConfig.from_xml().
from_xml() accepts only str. If you read XML in binary mode, decode the bytes first.
Step 7: Examine each custom driver
WARNING: A custom driver that overrides a removed hook stops your import with a TypeError. Examine every HConfigDriverBase subclass before you upgrade.
Version 4 removes five override hooks from drivers:
idempotent_for()negate_with()sectional_exit()swap_negation()config_preprocessor()
If a subclass defines one of these methods, Python raises the error when it creates the class:
TypeError: Bad defines swap_negation(), which the v4 engine never calls: only rule data crosses into the Rust core. Express this as a rule on HConfigDriverRules instead.
Move each override to rule data:
| Removed hook | Replacement |
|---|---|
idempotent_for() | IdempotentCommandsRule |
sectional_exit() | SectionalExitingRule |
negate_with() | A negation rule |
swap_negation() | The negation_prefix and declaration_prefix properties |
config_preprocessor() | A function that you call on the text before HConfig.from_text() |
The preprocessor change also changes the order. Your function now runs before the constructor applies its full-text substitutions.
Also examine the regular expressions in your rules. Some rules use the text that a pattern captures. Examples are a substitution, a negation template, and an idempotency key. In these rules, the pattern must use the syntax of the Rust regex crate. That syntax does not support lookarounds, backreferences in the pattern, or \Z. Version 4 raises ValueError for these patterns. A rule that only tests for a match can use a larger set of patterns. The regex compatibility section of the project docs gives the details.
Step 8: Set the platform of a custom driver
The platform class attribute tells the Rust core which vendor operations to use. A subclass of a built-in driver inherits it. A driver without it uses the Generic operations:
from typing import ClassVar
from hier_config import HConfigDriverBase, HConfigDriverRules, Platform
from hier_config.platforms.driver_base import load_platform_rules
class CustomIOS(HConfigDriverBase):
platform: ClassVar[Platform] = Platform.CISCO_IOS
@staticmethod
def _instantiate_rules() -> HConfigDriverRules:
return load_platform_rules(Platform.CISCO_IOS)
Then register the driver with register_driver() and remove your old constructor function.
Step 9: Update the code that uses config views
Version 3 code often caught NotImplementedError from a view property. In version 4, use isinstance() to find out if a view has a capability:
# version 3
try:
vlans = interface_view.tagged_vlans
except NotImplementedError:
vlans = ()
# version 4
from hier_config import InterfaceVlanViewMixin
vlans = ()
if isinstance(interface_view, InterfaceVlanViewMixin):
vlans = interface_view.tagged_vlans
The EOS, NX-OS, and IOS XR views now return data where version 3 raised NotImplementedError. Thus, a version 3 handler for that exception no longer runs. Some other properties now return None where version 3 raised an exception. Change those handlers to test for None.
If you store duplex values, change "1", "2", and "3" to "auto", "full", and "half".
Step 10: Fix the other behavior changes
Search your code for these patterns:
- An assignment to
workflow.running_configorworkflow.generated_config. Make a newWorkflowRemediationin its place. - A change to
child.commentsthat you expected to stay local. Useset(child.comments)to get a copy. - An
isorid()comparison between nodes. Use==. - A stored pickle of an
HConfig. Build the tree again from a live configuration.
Step 11: Compare the output on real configurations
Take a set of running and intended configurations from your network. Generate the remediation and the rollback with version 3 and with version 4. Compare the two outputs line by line. When the outputs agree, or when you can explain each difference, move production to version 4. If you cannot explain a difference, keep production on version 3 and report the difference as an issue on the project.