{"id":8190,"library":"genie-libs-parser","title":"Genie Libs Parser","description":"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]","status":"active","version":"26.3","language":"en","source_language":"en","source_url":"https://github.com/CiscoTestAutomation/genieparser","tags":["network automation","Cisco","pyATS","parsing","CLI","structured data"],"install":[{"cmd":"pip install pyats[full]","lang":"bash","label":"Recommended for full Genie/pyATS functionality"},{"cmd":"pip install genie","lang":"bash","label":"Installs Genie and its components, including parsers"}],"dependencies":[{"reason":"genie-libs-parser is a core component of the pyATS framework.","package":"pyats","optional":false},{"reason":"Provides the overall library system and device abstraction for parser interaction.","package":"genie","optional":false},{"reason":"The underlying engine for creating and managing parsers.","package":"genie.metaparser","optional":false}],"imports":[{"note":"This is the primary and recommended way to use the parsers, leveraging the pyATS device object.","symbol":"device.parse","correct":"from pyats.topology import loader\n# ... load testbed and device\noutput = device.parse('show version')"},{"note":"Parser classes are located within OS-specific submodules (e.g., `iosxe`, `nxos`). Direct instantiation is less common than `device.parse()` for general usage.","wrong":"from genie.libs.parser.show_version import ShowVersion","symbol":"ShowVersion","correct":"from genie.libs.parser.iosxe.show_version import ShowVersion\n# ... create device object\nparser = ShowVersion(device=device_object)\nparsed_output = parser.parse()"}],"quickstart":{"code":"import os\nfrom pyats.topology import Device\nfrom genie.libs.parser.iosxe.show_version import ShowVersion\n\n# Simulate a device object for demonstration (in a real scenario, use pyats.topology.loader)\ndevice = Device(name='my_router', os='iosxe')\n# This is a hack to allow parsing without an active connection, typically used for offline parsing\ndevice.custom.setdefault('abstraction', {})['order'] = ['os', 'platform']\n\n# Simulate CLI output\ncli_output = '''\nCisco IOS XE Software, Version 17.03.04a\nCisco IOS Software [Dublin], ISR Software (X86_64_LINUX_IOSD_UNIVERSALK9-VIRT_STD_ML), Version 17.3.4a, RELEASE SOFTWARE (fc2)\nTechnical Support: http://www.cisco.com/techsupport\nCopyright (c) 1986-2021 by Cisco Systems, Inc.\nCompiled Wed 21-Apr-21 02:40 by mcpre\n\nROM: System Bootstrap, Version 17.3.1R\n\nmy_router uptime is 1 week, 2 days, 3 hours, 4 minutes\nSystem returned to ROM by reload\nSystem image file is \"bootflash:isr4400-universalk9.17.03.04a.SPA.bin\"\nLast reload reason: PowerSupplyFailure\n'''\n\n# --- Option 1: Using device.parse() (recommended) ---\n# In a real scenario, device.parse() would execute the command on the device.\n# For offline parsing, you can pass the 'output' argument.\nparsed_data_via_device = device.parse('show version', output=cli_output)\nprint(\"Parsed data via device.parse():\\n\", parsed_data_via_device)\n\n# --- Option 2: Directly instantiating a parser class (less common for general use) ---\nparser = ShowVersion(device=device) # The device object provides context (OS, etc.)\nparsed_data_via_class = parser.parse(output=cli_output)\nprint(\"\\nParsed data via direct class instantiation:\\n\", parsed_data_via_class)\n","lang":"python","description":"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]"},"warnings":[{"fix":"Always validate parsed output against expected schema, especially after device OS upgrades. Consider using Genie's 'learn' feature for baseline validation and 'diff' for change detection. If an existing parser fails, it may require a fix or a custom parser to be developed. [9 in previous search]","message":"Parser schemas and regex patterns are highly dependent on the exact CLI output of a device. Minor changes in device OS versions or command output formatting can cause parsers to fail silently or return incomplete data.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Update connection configurations to use the `credentials` dictionary within your testbed YAML or device object, e.g., `device.credentials.default.username = 'admin'`. [5 in previous search]","message":"Direct arguments like 'username', 'enable_password' for Unicon (a core pyATS connection library) have been deprecated and replaced by a 'credentials' dictionary.","severity":"breaking","affected_versions":"Older pyATS/Genie versions leading up to and including some 24.x versions. (Specifically noted in a GitHub issue dated April 2020 related to Unicon plugins)."},{"fix":"If encountering parsing issues with Nornir multi-worker setups, consider collecting output with Nornir and then processing it with Genie in a single-threaded manner, or limit Nornir's worker count to 1 for parser-intensive tasks. [18 in previous search]","message":"When running pyATS/Genie with Nornir using multiple workers, issues have been reported where Genie processing can fail.","severity":"gotcha","affected_versions":"Reported with Nornir 2.20 and older pyATS/Genie versions."},{"fix":"Check the traceback for the specific parser file and line number. If it's a built-in parser, ensure your `genie-libs-parser` package is up to date. If it's a custom parser, review the Python syntax. [15 in previous search]","message":"Some parser modules might contain syntax errors, particularly in older or custom parsers, leading to `SyntaxError` exceptions during execution.","severity":"gotcha","affected_versions":"Specific versions where a parser file might have been introduced with a bug."}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Verify that a parser exists for the exact command and OS (e.g., 'show ip interface brief' for 'iosxe'). You can browse the `genieparser` GitHub repository (src/genie/libs/parser) to find available parsers. If a parser does not exist, you may need to develop a custom parser. Ensure `pyats[full]` or `genie` is installed. [5 in previous search, 1]","cause":"The Genie framework could not locate a parser module for the specified command and operating system, or the parser is named differently than expected.","error":"ModuleNotFoundError: Could not find module_name for command <command_string> for nos <os_name> from genie"},{"fix":"Inspect the raw CLI output and compare it against the expected schema of the parser (often found in the parser's source code or documentation). If the output deviates, the parser might need an update, or a custom parser might be required. Consider printing the raw output and the partial parsed data for debugging. [9 in previous search]","cause":"The device's command output did not match the parser's expected structure, causing the parser to fail to extract a specific key, or the output was partially parsed.","error":"KeyError: 'interface' (or similar key not found in parsed output)"},{"fix":"Ensure that your `Schema` class for the parser has a `schema` dictionary defined with the expected data structure. For example: `schema = { 'interface': { Any(): { 'ip_address': str }}}`. Refer to the `genie.metaparser` documentation for schema definition. [4 in previous search, 6 in previous search]","cause":"This error typically occurs when writing or modifying a custom parser, and the `schema` attribute within the parser's Schema class is not correctly defined or is empty.","error":"genie.metaparser.exceptions.SchemaEmptyError: Schema has to be defined with values"}]}