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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

networkconfparse-0.3.0.tar.gz (98.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

networkconfparse-0.3.0-py3-none-any.whl (17.8 kB view details)

Uploaded Python 3

File details

Details for the file networkconfparse-0.3.0.tar.gz.

File metadata

  • Download URL: networkconfparse-0.3.0.tar.gz
  • Upload date:
  • Size: 98.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for networkconfparse-0.3.0.tar.gz
Algorithm Hash digest
SHA256 c4898bdc0ce608d0ddc3a883598813f49b9d07438f6cc2ac0b087d559da3f459
MD5 f941c9b4e167ad130279185a28a89cad
BLAKE2b-256 8c9e16250351948d0e418a4f786730f7331c57a822f4f4884727561237129d1a

See more details on using hashes here.

Provenance

The following attestation bundles were made for networkconfparse-0.3.0.tar.gz:

Publisher: release.yaml on ChartinoLabs/networkconfparse

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file networkconfparse-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for networkconfparse-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 139daa2127adaee6547a6c0a22cd3faa2919851d254e43698abd21e5a4b796ff
MD5 a77cfaa5d40b8430c02bda5282e31a35
BLAKE2b-256 26d834a6342b3d9429981b4d9dca15067f14e469cbcaaf2ae55f792b0e184bc1

See more details on using hashes here.

Provenance

The following attestation bundles were made for networkconfparse-0.3.0-py3-none-any.whl:

Publisher: release.yaml on ChartinoLabs/networkconfparse

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 files

0.2.0

2 files

0.1.0

2 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