Back to Learn

ntc-templates โ€” parse CLI into structured data

A community library of TextFSM templates for hundreds of 'show' commands across Cisco, Arista, Juniper and more. Stop writing regex โ€” turn raw CLI output into clean, structured data.

Python
TextFSM
Cisco IOS / NX-OS
Arista EOS
Juniper JunOS
Parsing
TextFSM templates turn 'show' output into lists of dicts
An index maps vendor + command to the right template
Raw/parsed fixtures let you test new templates

Setup, key templates & run commands

Step 0 โ€” install
Setup

Install ntc-templates. It ships the bundled TextFSM templates plus an index that maps vendor + command to the right template.

Step 0 โ€” install
bash
python3 -m venv .venv
source .venv/bin/activate
pip install ntc-templates textfsm
parse.py โ€” parse_output
parse_output

The simplest entry point: pass the platform, the command and the raw CLI text, and get back a list of dicts. The index picks the matching template automatically.

parse.py โ€” parse_output
python
from ntc_templates.parse import parse_output

raw = open("show_ip_int_brief.txt").read()

rows = parse_output(
    platform="cisco_ios",
    command="show ip interface brief",
    data=raw,
)

for row in rows:
    print(row["intf"], row["ipaddr"], row["status"])
with_netmiko.py โ€” use_textfsm
Netmiko integration

Netmiko ships ntc-templates as its default TextFSM source. use_textfsm=True returns structured output directly off the wire.

with_netmiko.py โ€” use_textfsm
python
from netmiko import ConnectHandler

device = {
    "device_type": "cisco_ios",
    "host": "10.10.1.1",
    "username": "admin",
    "password": "secret",
}

with ConnectHandler(**device) as conn:
    rows = conn.send_command("show ip interface brief", use_textfsm=True)

print(rows)  # list of dicts, parsed via ntc-templates
custom template โ€” index + .textfsm
Authoring

Add a new parser by dropping a <vendor>_<command>.textfsm file under ntc_templates/templates/ and registering it in the 'index' file (regex command, platform, filename).

custom template โ€” index + .textfsm
bash
# 1. Create the template
#    ntc_templates/templates/cisco_ios_show_foo.textfsm
#
# 2. Register it in ntc_templates/templates/index
#    Template, Hostname, Platform, Command
#    cisco_ios_show_foo.textfsm, .*, cisco_ios, sh[[ow]] foo
#
# Point NET_TEXTFSM at a custom template dir if needed:
export NET_TEXTFSM=/path/to/ntc_templates/templates
test.py โ€” validate a template
Testing

ntc-templates uses raw/parsed fixture pairs under tests/. Run pytest to confirm a template parses sample output correctly before relying on it.

test.py โ€” validate a template
bash
git clone https://github.com/networktocode/ntc-templates.git
cd ntc-templates
poetry install   # or: pip install -r requirements.txt pytest

# run the full template test suite
pytest tests/

ntc-templates is the parsing engine behind Netmiko's use_textfsm and many NetDevOps pipelines. Pair it with Netmiko or Nornir to collect and normalise device state at scale.