{"id":6276,"library":"ttp","title":"Template Text Parser (TTP)","description":"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.","status":"active","version":"0.10.1","language":"en","source_language":"en","source_url":"https://github.com/dmulyalin/ttp","tags":["text-parsing","templates","network-automation","cli-parser","regex","data-extraction"],"install":[{"cmd":"pip install ttp","lang":"bash","label":"Standard Installation"},{"cmd":"pip install ttp[full]","lang":"bash","label":"Installation with all optional dependencies"}],"dependencies":[{"reason":"Runtime environment","package":"Python","version":">=3.9, <4.0"},{"reason":"Core dependency, updated in 0.10.0","package":"PyYAML","version":"latest"},{"reason":"Core dependency, updated in 0.10.0","package":"deepdiff","version":"latest"},{"reason":"Core dependency, updated in 0.10.0","package":"jinja2","version":"latest"},{"reason":"Core dependency, updated in 0.10.0","package":"tabulate","version":"latest"},{"reason":"Required for the `geoip_lookup` function within templates","package":"geoip2","optional":true}],"imports":[{"symbol":"ttp","correct":"from ttp import ttp"}],"quickstart":{"code":"from ttp import ttp\nimport pprint\n\ndata = \"\"\"\ninterface Loopback0\n description Router-id-loopback\n ip address 192.168.0.113/24\n!\ninterface Vlan778\n description CPE_Acces_Vlan\n ip address 2002::fd37/124\n ip vrf CPE1\n!\n\"\"\"\n\ntemplate = \"\"\"\n<group>\ninterface {{ interface }}\n description {{ description }}\n ip address {{ ip }}/{{ mask }}\n{{ _start_ -}} ip vrf {{ vrf }}{{ -_end_ }}\n</group>\n\"\"\"\n\nparser = ttp(data=data, template=template)\nparser.parse()\nresults = parser.result(format='json')[0]\npprint.pprint(results)","lang":"python","description":"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."},"warnings":[{"fix":"Ensure your project is running on Python 3.9 or newer. Consider upgrading your Python environment.","message":"Python 2.7 support has been removed, and the minimum required Python version is now 3.9.","severity":"breaking","affected_versions":">=0.10.0"},{"fix":"Migrate any reliance on the removed 'input sources' by directly integrating with Netmiko/Nornir or manually providing data to TTP using its `data` argument.","message":"The 'input sources' feature, including Nornir and Netmiko sources, was removed in version 0.9.0. This was due to better integration methods with Netmiko and updates to Nornir.","severity":"breaking","affected_versions":">=0.9.0"},{"fix":"Design your templates and input strategy such that groups relying on each other's results for lookups are processing distinct input data sets.","message":"When using `lookup` functions where one group's results are used for a lookup in another group, those groups must process separate inputs. TTP combines results on a per-input basis, which can lead to unexpected behavior if lookups cross shared input boundaries.","severity":"gotcha","affected_versions":"All"},{"fix":"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.","message":"Output results often come as deeply nested lists, which can be unintuitive for new users. For example, `parser.result()` returns `[[[...]]]`, requiring indexing like `parser.result()[0]` or `parser.result(format='json')[0]` to access the main results.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z"}