In this lesson, we will cover:
- How to install Scrapli TTP.
- TTP using just Python.
- How to create a custom TTP template.
You can find the scripts and code for this lesson within the Scrapli repo under the directory: 002_scrapli_core/006_ttp_parsing/ttp/.
What is TTP?
TTP (Template Text Parser) is a Python module that allows you to parse text data into structured data using TTP parsing templates (see the example below). One of TTP’s key strengths is that it has a low barrier of entry. One of the main reasons for this is that it abstracts away much of the regex required thanks to the simplistic way in which the templates are created.
interface {{ interface }}
ip address {{ ip }}/{{ mask }}
description {{ description }}
ip vrf {{ vrf }}
Installation
To perform Scrapli TTP parsing, you must first install the optional extra TTP package:
pip3 install "scrapli[ttp]"
Note: If you have previously installed the hands-on lab environment this dependency will have already been installed.
Python Example
- Define our unstructured data –
vlan_data
. - Define our TTP template –
ttp_template
. - Parse our data using the TTP template.
- Print the results.