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 }}


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

Let’s look at an example, which we will run directly using Python. Our example will result in parsing and returning the output of an EOS-based `show vlans` in a structured format. As you can see below we:
  1. Define our unstructured data – vlan_data.
  2. Define our TTP template – ttp_template.
  3. Parse our data using the TTP template.
  4. Print the results.
Members Only Content
Want to Learn Network Automation?
Join our membership to access:
  • Full deep-dive course library (inc. Batfish, pyATS, Netmiko)
  • Code repositories inc. full course code, scripts and examples
  • 24x7 multi-vendor labs (Arista, Cisco, Juniper)
  • Private online community
  • Tech demos and sessions

Join Now ➜
Close You've successfully subscribed to Packet Coders.
Close Success! Your account is fully activated, you now have access to all content.
Close Welcome back! You've successfully signed in.
Close Nearly there! To activate your account, please click the link in the email we just sent you.