Genie Libs Parser

26.3 · active · verified Thu Apr 16

Genie Libs Parser, currently at version 26.3, is a sub-component of the pyATS and Genie framework designed to parse raw device output (CLI, XML, YANG) into structured Python data structures. It provides a vast collection of parsers for various network operating systems and commands. The project follows a regular release cadence, often aligned with pyATS and Genie releases, with frequent additions of new parsers and APIs. [2, 8]

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `genie-libs-parser` to parse device CLI output into a structured dictionary. It shows both the recommended `device.parse()` method (simulating output for offline use) and direct instantiation of a parser class. A dummy `Device` object is created to provide the necessary context for the parsers. In a live environment, the `device` object would be loaded from a pyATS testbed and connected to a physical or virtual device. [8 in previous search, 1]

import os
from pyats.topology import Device
from genie.libs.parser.iosxe.show_version import ShowVersion

# Simulate a device object for demonstration (in a real scenario, use pyats.topology.loader)
device = Device(name='my_router', os='iosxe')
# This is a hack to allow parsing without an active connection, typically used for offline parsing
device.custom.setdefault('abstraction', {})['order'] = ['os', 'platform']

# Simulate CLI output
cli_output = '''
Cisco IOS XE Software, Version 17.03.04a
Cisco IOS Software [Dublin], ISR Software (X86_64_LINUX_IOSD_UNIVERSALK9-VIRT_STD_ML), Version 17.3.4a, RELEASE SOFTWARE (fc2)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2021 by Cisco Systems, Inc.
Compiled Wed 21-Apr-21 02:40 by mcpre

ROM: System Bootstrap, Version 17.3.1R

my_router uptime is 1 week, 2 days, 3 hours, 4 minutes
System returned to ROM by reload
System image file is "bootflash:isr4400-universalk9.17.03.04a.SPA.bin"
Last reload reason: PowerSupplyFailure
'''

# --- Option 1: Using device.parse() (recommended) ---
# In a real scenario, device.parse() would execute the command on the device.
# For offline parsing, you can pass the 'output' argument.
parsed_data_via_device = device.parse('show version', output=cli_output)
print("Parsed data via device.parse():\n", parsed_data_via_device)

# --- Option 2: Directly instantiating a parser class (less common for general use) ---
parser = ShowVersion(device=device) # The device object provides context (OS, etc.)
parsed_data_via_class = parser.parse(output=cli_output)
print("\nParsed data via direct class instantiation:\n", parsed_data_via_class)

view raw JSON →