Registry / devops / ntc-templates

ntc-templates

JSON →
library9.2.0pypypi✓ verified 21d ago

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.

pip install ntc-templates
INSTALL
IMPORT
SIG · NTC-TEMPLATES
N
ntc-templates
devopspythonv9.2.0
Install
1.8s avg
Import
136ms
Disk
20MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v9.2.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.140s · 22.4MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.8s · import 0.132s · 23MB
20MB installed
● package 20MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parse_output
from ntc_templates.parse import parse_output
from ntc_templates import parse_output
The `parse_output` function resides within the `ntc_templates.parse` module, not directly under the top-level package.

This quickstart demonstrates how to parse raw CLI output using `ntc-templates`. It defines a sample `show version` output from a Cisco IOS device and uses `parse_output` with the corresponding platform and command to transform it into structured Python data (a list of dictionaries). Error handling is included as a best practice.

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')}")
Debug
Known issues
breakingVersion 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.
fix
Review the official release notes (e.g., `https://ntc-templates.readthedocs.io/en/latest/admin/release_notes/version_9.0/`) to understand specific breaking changes and update your code/templates accordingly. This may involve changes to expected dictionary keys due to a move towards a common data model.
affects: >=9.0.0
gotchaA 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.
fix
Ensure `textfsm` is installed at version `1.1.0` using `pip install textfsm==1.1.0` before installing or using `ntc-templates`.
affects: All versions where `textfsm` is not `1.1.0`
gotchaNTC 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.
fix
Always implement error handling around `parse_output` calls. Validate the parsed output before using it in automation. If a template fails or misses data, consider contributing a fix or creating a custom template.
affects: All versions
deprecatedOlder 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.
fix
If maintaining custom TextFSM templates, rename your template files from `.template` to `.textfsm` and your parsed test files from `.parsed` to `.yml` for consistency and to leverage modern tooling like YAML linting.
affects: <1.7.0 (transition began around this version)
Errors
Common errors & fixes
ImportError: cannot import name 'clitable' from 'textfsm'
This error occurs due to a version incompatibility between `ntc-templates` and `textfsm`, specifically when an older `textfsm` source distribution (prior to 1.1.0) is installed, as `ntc-templates` relies on an interface introduced in `textfsm` version 1.1.0 and newer.
fix
Upgrade `textfsm` to version 1.1.0 or later, ensuring it's installed from a wheel distribution if possible: `pip install textfsm==1.1.0` or `pip install textfsm --upgrade`.
textfsm.parser.TextFSMError: State Error raised. Rule Line: X. Input Line: Y
This error indicates that a line (Input Line: Y) in the provided CLI output did not match any of the defined regular expression rules in the TextFSM template (at Rule Line: X), often because the template contains a `^. -> Error` rule to explicitly catch unmatched lines.
fix
Review the CLI output for unexpected variations and either update the TextFSM template to account for the unmatched line or, if the unmatched data is not critical, wrap the `parse_output` call in a `try-except TextFSMError` block to handle the exception gracefully.
Valid ntc-templates not found, please install https://github.com/networktocode/ntc-templates and then set the NET_TEXTFSM environment variable to point to the ./ntc-templates/templates directory.
The `ntc-templates` library, or a tool relying on it (like Netmiko), cannot locate the directory containing the TextFSM templates, usually because the `NET_TEXTFSM` environment variable is not set or points to an incorrect path.
fix
Set the `NET_TEXTFSM` environment variable to the absolute path of the `templates` directory within your `ntc-templates` installation. For example: `export NET_TEXTFSM=/path/to/ntc-templates/templates/` (Linux/macOS) or add it as a system environment variable pointing to the correct path (Windows).
Upgrade
Version history
9.2.0latest on PyPI · released Jul 8, 2026
Audit
Dependencies
textfsmrequiredCore dependency for parsing network CLI output using TextFSM templates. Specific version '1.1.0' is often required to avoid import errors.
Agent activity
3 hits · last 30 days
node
2
Resources
ntc-templates — pip install ntc-templates · libregistry