skip to navigation
skip to content

ciscoconfparse 0.9.15

Parse, Query, Build, and Modify Cisco IOS-style configurations

Latest Version: 1.2.46

Introduction: what is ciscoconfparse?

ciscoconfparse parses, queries, builds, or modifies Cisco IOS configurations.

For instance, suppose you have a large switched network and need to run audits on your configurations; perhaps you need to build configurations for any access switchports missing storm-control or port-security. You can accomplish this using ciscoconfparse with a modest script…

from ciscoconfparse import CiscoConfParse

parse = CiscoConfParse('edge-6509.conf')

## Walk all interfaces, and add missing configs
for intf in parse.find_objects(r'^interface'):

    ## Identify missing features
    has_portsecurity = bool(parse.find_parents_w_child(r'^%s$' % line,
    has_stormcontrol = bool(parse.find_parents_w_child(r'^%s$' % line,
    is_switchport_access = bool(parse.find_parents_w_child(r'^%s$' % line,
       r'^ switchport mode access'))

    ## Add missing features
    if is_switchport_access and (not has_portsecurity):
       parse.insert_after(r'^%s$' % line,
           ' switchport port-security maximum 2')
       parse.insert_after(r'^%s$' % line,
           ' switchport port-security violation restrict')
       parse.insert_after(r'^%s$' % line,
           ' switchport port-security')

    if is_switchport_access and (not has_stormcontrol):
       parse.insert_after(r'^%s$' % line,
           ' storm-control broadcast level 0.4 0.3')
       parse.insert_after(r'^%s$' % line,
           ' storm-control multicast level 0.5 0.3')

## Write the new configuration
with open('') as newconf:
    for line in parse.ioscfg:


ciscoconfparse needs only Python to run. It works with Python versions 2.6, 2.7 and 3.2+ on Linux and Windows. If you’re inclined to run under a virtualenv, it’s been heavily tested in that environment as well.


The latest copy of the docs are archived on the web


The best way to get ciscoconfparse is with setuptools or pip. If you already have setuptools, you can install as usual:

# Substitute whatever version you like...
easy_install -U ciscoconfparse==0.9.14

Alternatively you can install with pip:

pip install ciscoconfparse

Otherwise download it from PyPi, extract it and run the script:

python install

If you’re interested in the source, you can always pull from the github repo or bitbucket repo:

  • From bitbucket:

    hg init
    hg clone
  • From github:

    git clone git://


  • Q1: Is there a way to use this module with perl?
  • A1: Yes, I do this myself. Install the python package as you normally would and import it into perl with and Inline::Python from CPAN.
  • Q2: When I use find_children("interface GigabitEthernet3/2"), I’m getting all interfaces beginning with 3/2, including 3/21, 3/22, 3/23 and 3/24. How can I limit my results?
  • A2. There are two ways… the simplest is to use the ‘exactmatch’ option… find_children("interface GigabitEthernet3/2", exactmatch=True). Another way is to utilize regex expansion that is native to many methods… find_children("interface GigabitEthernet3/2$")

Travis CI

I use the Travis CI project to continuously test ciscoconfparse on Python versions 2.6 through 3.3.

Click the image below for details; the current build status is:

Author and Thanks

ciscoconfparse was written by David Michael Pennington (mike [~at~] pennington [/dot] net).

Thanks to David Muir Sharnoff for his suggestion about making a special case for IOS banners. Thanks to Alan Cownie for his API suggestions. Thanks to everyone in advance for their bug reports and patience. Sola Dei Gloria.

File Type Py Version Uploaded on Size
ciscoconfparse-0.9.15.tar.gz (md5) Source 2014-02-10 72KB