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-templatesVerified import paths — ran on the pinned version, not inferred.
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.
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.
Ensure `textfsm` is installed at version `1.1.0` using `pip install textfsm==1.1.0` before installing or using `ntc-templates`.
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.
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.
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`.
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.
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).