CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-ciscoconfparse

Parse, Audit, Query, Build, and Modify Cisco IOS-style and JunOS-style network configuration files

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

CiscoConfParse

A comprehensive Python library for parsing, auditing, querying, building, and modifying Cisco IOS-style and JunOS-style network configurations. CiscoConfParse enables network engineers and automation developers to programmatically analyze router, switch, firewall, and wireless LAN controller configurations by breaking them into parent-child relationships for complex queries.

Package Information

  • Package Name: ciscoconfparse
  • Language: Python
  • Installation: pip install ciscoconfparse

Core Imports

from ciscoconfparse import CiscoConfParse

Individual components:

from ciscoconfparse import (
    CiscoConfParse, IPv4Obj, IPv6Obj, CiscoIOSInterface, CiscoIOSXRInterface,
    CiscoRange, L4Object, DNSResponse, Diff, HDiff, ConfigList, CiscoPassword
)

Basic Usage

from ciscoconfparse import CiscoConfParse

# Parse a configuration file
parse = CiscoConfParse('router_config.txt', syntax='ios')

# Find all interface configurations  
interfaces = parse.find_objects(r'^interface')

# Find interfaces with specific child configuration
trunk_intfs = parse.find_objects_w_child(
    parentspec=r'^interface', 
    childspec=r'switchport mode trunk'
)

# Find configuration lines matching a pattern
bgp_lines = parse.find_lines(r'^router bgp')

# Modify configuration - insert new line
parse.insert_after(r'^interface GigabitEthernet0/1', ' description UPLINK')
parse.commit()

# Save modified configuration
parse.save_as('modified_config.txt')

Architecture

CiscoConfParse uses a hierarchical object model where configurations are parsed into parent-child relationships:

  • CiscoConfParse: Main parser class managing the entire configuration
  • Configuration Line Objects: Individual line objects (IOSCfgLine, NXOSCfgLine, etc.) with parent-child relationships
  • Factory System: Automatic creation of vendor-specific objects based on syntax
  • Network Objects: Specialized classes for IP addresses, interfaces, and protocols
  • Utility Classes: Helper classes for ranges, DNS operations, and text processing

The library supports multiple network vendor configurations including Cisco IOS/NXOS/IOS-XR/ASA, Arista EOS, Juniper Junos, Palo Alto Networks, F5 Networks, and other vendors using similar configuration syntax.

Capabilities

Core Configuration Parsing

Primary interface for parsing, querying, and modifying network configurations. Provides methods to find, insert, delete, and replace configuration lines with support for regex patterns and parent-child relationships.

class CiscoConfParse:
    def __init__(self, config, syntax='ios', comment_delimiter='!', debug=False, factory=False, ignore_blank_lines=True, encoding='utf-8'): ...
    def find_objects(self, linespec, exactmatch=False, ignore_ws=False): ...
    def find_lines(self, linespec, exactmatch=False, ignore_ws=False): ...
    def find_children(self, linespec, exactmatch=False, ignore_ws=False): ...
    def find_all_children(self, linespec, exactmatch=False, ignore_ws=False): ...
    def find_blocks(self, linespec, exactmatch=False, ignore_ws=False): ...
    def find_objects_w_child(self, parentspec, childspec, ignore_ws=False): ...
    def find_parents_w_child(self, parentspec, childspec, ignore_ws=False): ...
    def find_objects_wo_child(self, parentspec, childspec, ignore_ws=False): ...
    def find_objects_w_all_children(self, parentspec, childspec, ignore_ws=False, recurse=False): ...
    def find_objects_w_missing_children(self, parentspec, childspec, ignore_ws=False, recurse=False): ...
    def find_object_branches(self, branchspec=(), regex_flags=0, allow_none=True, regex_groups=False, debug=0): ...
    def find_interface_objects(self, linespec, exactmatch=False, ignore_ws=False): ...
    def re_match_iter_typed(self, regexspec, group=1, result_type=str, default="", untyped_default=False, groupdict={}, recurse=False, debug=0): ...
    def insert_before(self, linespec, insertstr, exactmatch=False, ignore_ws=False): ...
    def insert_after(self, linespec, insertstr, exactmatch=False, ignore_ws=False): ...
    def delete_lines(self, linespec, exactmatch=False, ignore_ws=False): ...
    def replace_lines(self, linespec, replacestr, exactmatch=False, ignore_ws=False): ...
    def sync_diff(self, cfgspec=None, ignore_order=True, remove_lines=True, debug=0): ...
    def commit(self): ...
    def save_as(self, filepath): ...

class Diff:
    def __init__(self, old_config, new_config, syntax='ios'): ...
    def get_diff(self): ...

class HDiff:
    def __init__(self, before_config=None, after_config=None, syntax="ios", debug=0): ...
    def unified_diffs(self, header=True): ...

class ConfigList:
    def __init__(self, data, comment_delimiter='!', debug=False, factory=False, ignore_blank_lines=True, syntax='ios', ccp_ref=None): ...
    def append(self, val): ...
    def insert(self, index, val): ...
    def __getitem__(self, key): ...

class CiscoPassword:
    def __init__(self, ep=None): ...
    def decrypt(self, ep): ...

Core Parsing

Network Objects

Handle IPv4/IPv6 addresses, networks, interface names, and Layer 4 protocol information. Provides comprehensive IP address manipulation, subnet calculations, and interface name parsing with vendor-specific support.

class IPv4Obj:
    def __init__(self, ipv4_str): ...
    @property
    def ip(self): ...
    @property
    def network(self): ...
    @property
    def netmask(self): ...
    @property
    def prefixlen(self): ...
    def is_private(self): ...
    def is_multicast(self): ...

class IPv6Obj:
    def __init__(self, ipv6_str): ...
    @property
    def ip(self): ...
    @property
    def network(self): ...
    @property
    def prefixlen(self): ...
    def is_private(self): ...
    def is_multicast(self): ...

class CiscoIOSInterface:
    def __init__(self, interface): ...
    @property
    def name(self): ...
    @property
    def port(self): ...
    @property
    def port_type(self): ...
    def abbreviate(self): ...

Network Objects

Interface Parsing

Parse and analyze network interface configurations with vendor-specific support. Extract interface properties like IP addresses, VLANs, VRFs, and operational states from configuration lines.

class IOSIntfLine:
    @property
    def name(self): ...
    @property
    def port(self): ...
    @property
    def port_type(self): ...
    @property
    def ip_addr(self): ...
    @property
    def ip_netmask(self): ...
    @property
    def ip_network_object(self): ...
    @property
    def ipv6_addr(self): ...
    @property
    def is_shutdown(self): ...
    @property
    def vrf(self): ...
    @property
    def switchport(self): ...
    @property
    def switchport_access_vlan(self): ...
    @property
    def switchport_trunk_vlans(self): ...
    def abbreviate_interface_name(self): ...

Interface Parsing

Utilities and Helpers

DNS operations, text processing, validation functions, logging control, and Cisco-specific utilities like password decryption and range handling.

def dns_query(query_name, query_type='A', server='8.8.8.8', timeout=0.5): ...
def dns_lookup(input_name, timeout=0.5, server='8.8.8.8'): ...
def ip_factory(addr): ...
def collapse_addresses(addresses): ...
def check_valid_ipaddress(addr): ...

class CiscoRange:
    def __init__(self, text="", result_type=int): ...
    def append(self, val): ...
    def remove(self, val): ...
    @property
    def compressed_str(self): ...
    def as_list(self): ...

class CiscoPassword:
    def __init__(self, ep=None): ...
    def decrypt(self, ep): ...

Utilities

Types

# Configuration line base types
class BaseCfgLine:
    text: str
    linenum: int
    parent: 'BaseCfgLine'
    children: list['BaseCfgLine'] 
    indent: int

# Network object types
class L4Object:
    def __init__(self, protocol="", port_spec="", syntax=""): ...
    protocol: str
    port_list: list[int]
    port_spec: str

class DNSResponse:
    query_name: str
    query_type: str
    response: str
    preference: int
    rdtype: str

# Container types
class ConfigList:
    def append(self, val): ...
    def insert(self, index, val): ...
    def __getitem__(self, key): ...
    def __setitem__(self, key, val): ...
    def __delitem__(self, key): ...

# Diff types
class Diff:
    old_config: str
    new_config: str
    syntax: str

class HDiff:
    before_config: str
    after_config: str
    syntax: str

class DiffObject:
    """Represents configuration differences."""

# Interface types
class CiscoIOSXRInterface:
    name: str
    port: str
    port_type: str

Install with Tessl CLI

npx tessl i tessl/pypi-ciscoconfparse
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/ciscoconfparse@1.9.x
Publish Source
CLI
Badge
tessl/pypi-ciscoconfparse badge