TTP Templates

0.5.1 · active · verified Fri Apr 17

ttp-templates is a Python library that provides a curated collection of Text Template Parser (TTP) templates, primarily focused on parsing network device CLI output. It extends the core TTP parser by offering an easy way to access and apply pre-built templates for various vendors and commands, including "getter" templates for normalized data. The current version is 0.5.1, with releases occurring periodically to add new templates and features or address issues.

Common errors

Warnings

Install

Imports

Quickstart

Initializes the TTPTemplates parser, provides sample network device output, and demonstrates how to use a bundled 'getter' template to parse and normalize the data. The 'platform' argument helps select the correct template logic for vendor-specific output.

from ttp_templates import TTPTemplates

# Initialize TTPTemplates
parser = TTPTemplates()

# Example device output for `get/inventory.txt` on Cisco NX-OS
# This output structure is a simplified representation of `show inventory`
device_output = """
NAME: "Chassis", DESCR: "Nexus9000 C9372PX Chassis"
PID: N9K-C9372PX, VID: V01, SN: FOC12345678

NAME: "Slot 1", DESCR: "Supervisor"
PID: N9K-SUP-A, VID: V01, SN: JAE12345678
"""

# Parse the output using the 'get/inventory.txt' template
# The 'platform' argument is often crucial for getter templates to select the right internal logic
result = parser.parse_output(
    data=device_output,
    template_name="get/inventory.txt",
    platform="cisco_nxos" 
)

# Print the normalized result
# 'result' is typically a list of lists, where inner list contains dictionaries
# In v0.5.1, it returns only the parsing result for the matched template.
if result and result[0]:
    print("Parsed Inventory Data:")
    for item in result[0]:
        print(item)
else:
    print("No data parsed or template did not match.")

view raw JSON →