CiscoConfParse Installation and Python Basics

A note about Python

If you are coming from Perl or another language (many people do), you may not be familiar with Python’s interpreter interface. To access the interpreter, just issue python at the Windows or unix command-line; this drops you into an interactive interpreter, where you can issue python commands. Use quit() to leave the interpreter.

When you see >>> preceding python statements, that means the example is run from within the python interpreter.

>>>
>>> print("Hello world")

If you don’t see >>> preceding python statements, that means the example is run from a file saved to disk.

Using Python in Unix

This is a “Hello World” example from within a unix Python interpreter.

[mpenning@mpenning-mudslide ~]$ which python
/usr/local/bin/python
[mpenning@mpenning-mudslide ~]$ python
Python 3.10.13 (main, Nov  2 2023, 08:33:35) [GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> print("Hello world")
Hello world
>>> quit()
[mpenning@mpenning-mudslide ~]$

The same commands could be used in an executable script (mode 755) saved to disk… and run from the unix shell.

#!/usr/bin/env python
print("Hello world")

Using Python in Windows

Please see the official Python on Windows documentation.

Using ciscoconfparse

Once you know how to find and use python on your system, it’s time to ensure you have a copy of ciscoconfparse. Many of the examples assume you have imported CiscoConfParse at the interpreter before you start…

>>> from ciscoconfparse import CiscoConfParse

Try importing CiscoConfParse in the python interpreter now. If it doesn’t work, then you’ll need to install ciscoconfparse.

Installing ciscoconfparse

As of version 1.3.22, ciscoconfparse requires Python versions 2.7 or 3.4+ (note: version 3.7.0 has a bug - ref Github issue #117, but version 3.7.1 works); the OS should not matter. If you want to run it under a Python virtualenv, it’s been heavily tested in that environment as well.

Note

You might need to be root to install outside of a virtualenvironment

You can check your python version with the -V switch…

[mpenning@Mudslide ~]# python -V
Python 3.10.13
[mpenning@Mudslide ~]#

The best way to get ciscoconfparse is with pip or setuptools.

Install with pip

If you already have pip, you can install as usual:

Alternatively you can install with pip:

pip install --upgrade ciscoconfparse

If you have a specific version of ciscoconfparse in mind, you can specify that at the command-line

pip install ciscoconfparse==1.9.41

Install with setuptools

If you don’t have pip, you can use setuptools

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

If you have a specific version of ciscoconfparse in mind, you can specify that at the command-line

easy_install -U ciscoconfparse==1.9.41

Install from the source

If you don’t have either pip or setuptools, you can download the ciscoconfparse compressed tarball, extract it and run the setup.py script in the tarball:

python setup.py install

Github

If want to install from the most recent source, you can always clone and install from the github repo:

  • From github:

    git clone git://github.com/mpenning/ciscoconfparse
    cd ciscoconfparse
    pip install .