Skip to main content

Template Text Parser

Project description

Downloads PyPI versions Documentation status

Template Text Parser

TTP is a Python library for parsing semi-structured text data using templates.

Why?

Every time questions arise on how many devices has blob X configured or how many interface has QoS policy applied or to find IP overlaps in the network etc., etc., for those who write custom scripts to answer these questions, spending hours putting fancy regexes together and learning how to use specialized libraries to prepare, parse and process text data to transform it in a format that they can make use of - have a look at TTP, it can help with most of it.

How?

Regexes, regexes everywhere... but dynamically formed out of TTP templates with added capabilities to streamline process of getting desired outcome from raw text data.

What?

In essence TTP can help to:

  • Prepare, sort and load text data for parsing
  • Parse text using regexes dynamically derived from templates
  • Process matches on the fly using broad set of built-in or custom convenience functions
  • Combine match results in a structure with arbitrary hierarchy
  • Transform results in desired format to ease consumption by humans or machines
  • Return results to various destinations for storage or further processing

Reference documentation for more information.

Example

from ttp import ttp

data_to_parse = """
interface Loopback0
 description Router-id-loopback
 ip address 192.168.0.113/24
!
interface Vlan778
 description CPE_Acces_Vlan
 ip address 2002::fd37/124
 ip vrf CPE1
!
"""

ttp_template = """
interface {{ interface }}
 ip address {{ ip }}/{{ mask }}
 description {{ description }}
 ip vrf {{ vrf }}
"""

parser = ttp(data=data_to_parse, template=ttp_template)
parser.parse()
print(parser.result(format='json')[0])

[
    [
        {
            "description": "Router-id-loopback",
            "interface": "Loopback0",
            "ip": "192.168.0.113",
            "mask": "24"
        },
        {
            "description": "CPE_Acces_Vlan",
            "interface": "Vlan778",
            "ip": "2002::fd37",
            "mask": "124",
            "vrf": "CPE1"
        }
    ]
]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ttp-0.3.0.tar.gz (46.8 kB view details)

Uploaded Source

File details

Details for the file ttp-0.3.0.tar.gz.

File metadata

  • Download URL: ttp-0.3.0.tar.gz
  • Upload date:
  • Size: 46.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.0

File hashes

Hashes for ttp-0.3.0.tar.gz
Algorithm Hash digest
SHA256 b85d3071984764ec9d9aac283cca7e332e95d842f46e251ce43bb8d80abb6f98
MD5 ea4f4eb91a5615fedae57d0851fd89d6
BLAKE2b-256 e5cc093042a5e912f44d57e7e8a552bf7762e541c8ece9447ffe78924d10a81c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page