ciscoconfparse is a Python library designed for parsing, auditing, querying, building, and modifying Cisco IOS-style configurations. It also supports other vendor configurations that follow a similar hierarchical structure. The current version is 1.9.52, but it is considered End of Life, with all new development moving to its successor, `ciscoconfparse2`.
pip install ciscoconfparseVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize `CiscoConfParse` with a list of configuration lines and then use `find_parent_objects` to locate shutdown interfaces and `find_objects_w_child` to find interfaces with IP addresses. The library supports searching using regular expressions.
Migrate your code to `ciscoconfparse2` by installing `pip install ciscoconfparse2` and updating import statements and API calls. Review `ciscoconfparse2` documentation for migration guidance, as APIs are not fully compatible.
Always call `parse.commit()` or `parse.atomic()` after any modification operations before performing further searches on the updated configuration object.
Initialize `CiscoConfParse` with `ignore_blank_lines=False` if blank lines are significant to your parsing requirements. Example: `parse = CiscoConfParse(config_data, ignore_blank_lines=False)`.
Use `parse.find_objects()` instead of `parse.find_lines()`. Access text via `obj.text` on the returned `IOSCfgLine` objects.
For exact matches, use the `exactmatch=True` parameter if available, or anchor your regular expressions appropriately (e.g., `^interface GigabitEthernet3/2$` for an exact match to the end of the line).
Ensure the input `config` is either a Python list of strings (e.g., `config_string.splitlines()`) or a valid file path string: `parse = CiscoConfParse(config_lines_list)` or `parse = CiscoConfParse('/path/to/config.txt')`.Call `parse.commit()` or `parse.atomic()` immediately after any modification method to update the internal configuration representation before performing new searches.
When performing configuration modifications, ensure your logic explicitly handles the removal of old, conflicting commands before adding new ones. Consider using `replace_children()` or `replace_all_children()` methods if applicable, or generate a proper diff and apply only the necessary changes.