Skip to main content

networkconfparse

CI pre-commit PyPI version PyPI downloads Python versions License

networkconfparse is a library that parses the whitespace-indented configuration of network infrastructure (Cisco IOS, IOS XE, IOS XR, and NX-OS) into a queryable tree of native Python objects.

Why networkconfparse?

  • Standalone - No runtime dependencies. Install and use it in any Python project.
  • Network-OS agnostic - Hierarchy is inferred from relative indentation, so IOS (one space), NX-OS (two spaces), and inconsistent indentation are all handled without per-platform rules.
  • Queryable - A small, composable API to find configuration objects by regex, by predicate, or by their parent/child relationships.
  • Handles the awkward parts - Transparently skips ! comment and delimiter lines and captures multiline banner blocks and inline certificate data as opaque bodies, rather than mistaking them for configuration.
  • Typed and well-tested - Fully type-hinted with a comprehensive test suite.

Installation

networkconfparse can be quickly and easily installed with uv as shown below:

uv add networkconfparse

Or, if you prefer good old-fashioned pip, you can do so as shown below:

pip install networkconfparse

Quick Examples

Parsing a Configuration

Call parse() with the configuration text. It returns a Config whose top-level lines each carry their indented children as a tree of ConfigNode objects. Comment/delimiter lines (!) are dropped automatically.

import networkconfparse

config = networkconfparse.parse("""
interface GigabitEthernet0/0
 ip address 10.0.0.1 255.255.255.0
 no shutdown
!
interface GigabitEthernet0/1
 shutdown
!
""")

for interface in config.find(r"^interface "):
    print(interface.text, "->", [child.text for child in interface.children])

Prints:

interface GigabitEthernet0/0 -> ['ip address 10.0.0.1 255.255.255.0', 'no shutdown']
interface GigabitEthernet0/1 -> ['shutdown']

Querying the Tree

find() searches the entire tree and accepts a regular expression, a where predicate, or both. find_child()/has_child() look only at a node's immediate children, and find_one() returns the first match. Every node also exposes path, ancestors, descendants, and root for navigation.

# Interfaces that have an IP address configured anywhere beneath them.
configured = config.find(r"^interface ", where=lambda node: node.has_child(r"^ip address "))

# The first matching line, or None.
mgmt = config.find_one(r"^ip address 10\.0\.0\.1")

# Where does that line live in the hierarchy?
print(mgmt.path)
# ['interface GigabitEthernet0/0', 'ip address 10.0.0.1 255.255.255.0']

Relationship Helpers

For the common cases, dedicated helpers read more clearly than a hand-written predicate. Each accepts a single regex or a list (combined with AND), and they are simply convenience wrappers around find():

# Parents matching "interface" that have BOTH children as direct children.
config.find_with_child(r"^interface ", [r"^ip address ", r"^no shutdown"])

# Parents that have a matching line anywhere below them (not just direct children).
config.find_with_descendant(r"^router bgp ", r"neighbor")

# Lines whose direct parent matches.
config.find_with_parent(r"^neighbor ", r"^address-family ipv4")

# Lines with a matching ancestor anywhere above (or a consecutive chain with adjacent=True).
config.find_with_ancestor(r"^neighbor ", [r"^router bgp ", r"^address-family ipv4"])

Each helper has a find_without_* counterpart for the equally common absence questions ("interfaces without an ip address"). Given a list they apply a "none present" (NOR) rule, returning nodes where none of the patterns are found:

# Interfaces with neither an `ip address` nor a `shutdown` line.
config.find_without_child(r"^interface ", [r"^ip address ", r"^shutdown"])

These compose naturally for SDK-style questions. For example, "find every ACL that does not end with an explicit deny":

acls = config.find(r"^ip access-list ")
missing_deny = [
    acl for acl in acls
    if not acl.children or not acl.children[-1].matches(r"^deny ")
]

Documentation

Full documentation is available at chartinolabs.github.io/networkconfparse.

Acknowledgments

  • Conceptual inspiration - The idea of modeling a network device configuration as a queryable parent/child tree owes a great deal to Mike Pennington's work on CiscoConfParse and CiscoConfParse2. networkconfparse is an independent, clean-room implementation; it is not affiliated with, derived from, or endorsed by those projects.

Status

Early development. The API is still evolving and may change as the library matures.

Metadata

Release files for networkconfparse 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for networkconfparse 0.3.0
File Size Uploaded
networkconfparse-0.3.0.tar.gz 98.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for networkconfparse 0.3.0
File Interpreter ABI Platform
networkconfparse-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 116.4 kB

Release files / networkconfparse-0.3.0.tar.gz

Download URL networkconfparse-0.3.0.tar.gz
Size 98.7 kB
Tags Source
SHA-256 checksum
How to use checksums
c4898bdc0ce608d0ddc3a883598813f49b9d07438f6cc2ac0b087d559da3f459
BLAKE2b-256 checksum
How to use checksums
8c9e16250351948d0e418a4f786730f7331c57a822f4f4884727561237129d1a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 6, 2026.

Transparency log

Release files / networkconfparse-0.3.0-py3-none-any.whl

Download URL networkconfparse-0.3.0-py3-none-any.whl
Size 17.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
139daa2127adaee6547a6c0a22cd3faa2919851d254e43698abd21e5a4b796ff
BLAKE2b-256 checksum
How to use checksums
26d834a6342b3d9429981b4d9dca15067f14e469cbcaaf2ae55f792b0e184bc1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 6, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page