TTP is a Python library designed for fast and flexible parsing of semi-structured text data using templates. It was initially developed for processing CLI output from network devices but is versatile enough for any text with repetitive patterns. TTP offers features such as groups for results hierarchy, dynamic regex parsing, on-the-fly data processing with built-in or custom functions (macros), various output formats, and an input system. The library is actively maintained, with its latest version being 0.10.1.
pip install ttpVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates parsing network interface configuration. It initializes the `ttp` parser with input data and a template, then parses the data and prints the results in JSON format. The template uses `group` tags to define the output structure and `{{ variable }}` for data extraction, including optional fields using `_start_` and `_end_` tags.
Ensure your project is running on Python 3.9 or newer. Consider upgrading your Python environment.
Migrate any reliance on the removed 'input sources' by directly integrating with Netmiko/Nornir or manually providing data to TTP using its `data` argument.
Design your templates and input strategy such that groups relying on each other's results for lookups are processing distinct input data sets.
Always be mindful of the nested list structure when accessing results. Use `parser.result(format='json')[0]` or `parser.result(format='flat_json')` for a potentially simpler structure, or chain indices as needed to reach the desired data.
pip install ttp
Ensure the template variable contains a valid non-empty string with TTP template syntax.
Verify the path to the template file is correct, and ensure the file exists and is accessible.
Review the template string for typos, incorrect block delimiters (e.g., {{, {%), unclosed tags, or malformed regex patterns.