NTC Templates
NTC Templates is a Python library providing a comprehensive collection of TextFSM templates for parsing command-line interface (CLI) output from various network devices. It converts unstructured CLI text into structured, machine-readable data (lists of dictionaries), acting as a crucial tool for network automation workflows. The library is actively maintained with frequent updates and bug fixes, currently at version 9.1.0, and often releases minor and major versions to incorporate new templates or data model changes.
Warnings
- breaking Version 9.0.0 introduced breaking changes. Users upgrading from previous major versions, especially those with custom templates or relying on specific output field names, should consult the official release notes for migration steps.
- gotcha A common 'Cannot import name clitable from textfsm' error occurs due to an incompatibility between `ntc-templates` and certain `textfsm` PyPI distributions. This is often seen when `textfsm` is not explicitly pinned to a compatible version.
- gotcha NTC Templates rely on TextFSM, which uses regular expressions. If the raw CLI output from a network device changes format in a way not anticipated by the template, parsing may fail or produce incomplete/incorrect data. Templates do not guarantee to capture all possible data fields.
- deprecated Older versions of `ntc-templates` used `.template` for TextFSM template files and `.parsed` for expected output files. These extensions have been updated to `.textfsm` and `.yml` respectively.
Install
-
pip install ntc-templates
Imports
- parse_output
from ntc_templates.parse import parse_output
Quickstart
import os
from ntc_templates.parse import parse_output
# Example raw CLI output from a Cisco IOS device
raw_output = """
Cisco IOS Software, C800 Series Software (C800-UNIVERSALK9-M), Version 15.6(3)M5, RELEASE SOFTWARE (fc1)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2017 by Cisco Systems, Inc.
Compiled Wed 27-Sep-17 12:00 by prod_rel_team
ROM: System Bootstrap, Version 15.5(3)M, RELEASE SOFTWARE (fc1)
Cisco C891F (1RU) processor (revision 1.0) with 1007616K/54272K bytes of memory.
Processor board ID FHK2126210F
10 Gigabit Ethernet interfaces
8 FastEthernet interfaces
2 Gigabit Ethernet interfaces
1 Virtual Private Network (VPN) Module
256K bytes of non-volatile configuration memory.
1024000K bytes of ATA System CompactFlash (Read/Write)
License Level: ipservices
License Type: Permanent
Next reload will be a ipservices license
Configuration register is 0x2102
"""
# Define the platform and command corresponding to an NTC template
platform = "cisco_ios"
command = "show version"
try:
parsed_data = parse_output(platform=platform, command=command, data=raw_output)
print(parsed_data)
except Exception as e:
print(f"Error parsing output: {e}")
# Expected output is a list of dictionaries with parsed data
# Example of accessing some data (output structure depends on template):
# if parsed_data:
# print(f"Software Version: {parsed_data[0].get('VERSION')}")
# print(f"Platform: {parsed_data[0].get('HARDWARE')}")