Registry / devops / ciscoconfparse

ciscoconfparse

JSON →
library1.9.52pypypi✓ verified 86d ago

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 ciscoconfparse
INSTALL
IMPORT
SIG · CISCOCONFPARSE
C
ciscoconfparse
devopspythonv1.9.52
Install
3.0s avg
Import
814ms
Disk
30MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.9.52 · 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.920 runs
installs and imports cleanly · install 0.0s · import 0.852s · 30MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 3.0s · import 0.775s · 31MB
30MB installed
● package 30MB
Code
Verified usage

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

CiscoConfParse
from ciscoconfparse import CiscoConfParse

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.

from ciscoconfparse import CiscoConfParse # Example Cisco configuration lines config_text = [ 'hostname Router1', '!', 'interface GigabitEthernet0/1', ' description Uplink to Core', ' ip address 192.168.1.1 255.255.255.0', ' no shutdown', '!', 'interface GigabitEthernet0/2', ' description Access Port', ' switchport mode access', ' switchport access vlan 10', ' shutdown', '!', 'router bgp 65000', ' neighbor 10.0.0.1 remote-as 65001' ] # Create a CiscoConfParse object from a list of configuration lines parse = CiscoConfParse(config_text) # Find all interfaces that are administratively shutdown shutdown_interfaces = parse.find_parent_objects('^interface', 'shutdown') if shutdown_interfaces: print('Shutdown Interfaces:') for intf in shutdown_interfaces: # intf.text gives the parent line (e.g., 'interface GigabitEthernet0/2') print(f'- {intf.text}') else: print('No shutdown interfaces found.') # Find all interfaces with an IP address interfaces_with_ip = parse.find_objects_w_child(parentspec='^interface', childspec='ip address') if interfaces_with_ip: print('\nInterfaces with IP addresses:') for intf in interfaces_with_ip: ip_line = intf.re_search_children(r'ip address (\S+ \S+)', result_type=str, group=1) if ip_line: print(f'- {intf.text}: {ip_line}')
Debug
Known issues
breaking`ciscoconfparse` is End of Life (EOL) as of December 2023. No further updates or bug fixes will be released for this package. Users are strongly recommended to migrate to `ciscoconfparse2`, its successor, which is a different PyPI project with a streamlined API and breaking changes.
fix
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.
affects: All versions
gotchaWhen modifying a configuration within a `CiscoConfParse` object (e.g., `delete_lines`, `insert_before`), subsequent search methods like `find_objects()` will not reflect these changes until `commit()` or `atomic()` is explicitly called.
fix
Always call `parse.commit()` or `parse.atomic()` after any modification operations before performing further searches on the updated configuration object.
affects: All versions
gotchaThe `ignore_blank_lines` parameter in `CiscoConfParse` defaults to `True`. This means blank lines in your configuration input will be ignored. If your configurations intentionally use blank lines (e.g., for visual separation) and these are critical for your parsing logic, this default might cause unexpected behavior.
fix
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)`.
affects: All versions
deprecatedThe method `find_lines()` which returns a list of text strings is deprecated in favor of `find_objects()` which returns a list of `IOSCfgLine` objects. Working with `IOSCfgLine` objects is more powerful and efficient for traversing parent/child relationships.
fix
Use `parse.find_objects()` instead of `parse.find_lines()`. Access text via `obj.text` on the returned `IOSCfgLine` objects.
affects: Versions >= 0.9
gotchaWhen using methods like `find_children()` or `find_objects()` with a simple string or regex, results might be broader than intended (e.g., `interface GigabitEthernet3/2` matching `interface GigabitEthernet3/21`).
fix
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).
affects: All versions
Errors
Common errors & fixes
TypeError: config must be a list of strings or a filepath
The `CiscoConfParse` constructor expects either a list of configuration lines (strings) or a string representing a file path to the configuration, but received a different type or an improperly formatted string.
fix
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')`.
Unexpected or incomplete search results after modifying the configuration object (e.g., after delete_lines).
Modifications made to the configuration object (e.g., using `delete_lines`, `insert_before`) are not immediately reflected in the internal parsing structure. Subsequent search queries will operate on the old structure until the changes are committed.
fix
Call `parse.commit()` or `parse.atomic()` immediately after any modification method to update the internal configuration representation before performing new searches.
Modified configuration copied back to a device results in duplicated commands or incorrect state.
Directly editing a configuration string or object and then applying it back to a live device without explicit logic for managing the delta can lead to issues. Commands might be added redundantly, or conflicting commands (e.g., `switchport mode access` vs `switchport mode trunk`) may not be correctly removed/added to achieve the desired state.
fix
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.
Upgrade
Version history
1.9.52latest on PyPI · released Nov 22, 2024
Audit
Dependencies
pythonrequiredRequired runtime environment.
hier_configrequiredAdded as a dependency in versions >= 1.9.41 for enhanced configuration handling.
Agent activity
10 hits · last 30 days
node
8
OpenAI (training)
1
Resources
ciscoconfparse — pip install ciscoconfparse · libregistry