Template Text Parser
Low maintenance activity. Last release 8 months ago, commits in 0 of the last 26 weeks. Weaker on commit activity and issue handling.
pip install ttpTemplate Text Parser
TTP is a Python library for semi-structured text parsing using templates.
Why?
To save ones time on transforming raw text into structured data and beyond.
How?
Regexes, regexes everywhere... but, dynamically formed out of TTP templates with added capabilities to simplify the process of getting desired outcome.
What?
In essence TTP can help to:
- Prepare, sort and load text data for parsing
- Parse text using regexes dynamically derived out of templates
- Process matches on the fly using broad set of built-in or custom 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.
TTP Networktocode Slack channel
Collection of TTP Templates
Example - as simple as it can be
Simple interfaces configuration parsing example
Code
from ttp import ttp
import pprint
data = """
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
!
"""
template = """
interface {{ interface }}
ip address {{ ip }}/{{ mask }}
description {{ description }}
ip vrf {{ vrf }}
"""
parser = ttp(data, template)
parser.parse()
pprint.pprint(parser.result(), width=100)
# prints:
# [[[{'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'}]]]