text2py

Library for processing structured text into python object (dict or list) using templates


License
MIT
Install
pip install text2py==0.0.2

Documentation

Library for processing structured text into python object (dict or list) using templates.

Using:

text2py -t template.yml -i input.txt -o output.txt
import text2py
parser = text2py.Parser(template)
output = parser.parse(input_file)

Template format:

Scalar value:

- regexp: 'Volume (?P<volume>\w+) Author (?P<author>\w+)'
  key: "{volume}"
  value: "{author}"
{volume: author}

Dict value

- regexp: 'Volume (?P<volume>\w+) Author (?P<author>\w+) Review (?P<review>)'
  key: "volumes.{volume}"
  values:
    - key: 'author'
      value: "{author}"
    - key: 'review'
      value: "{review}"
{'volumes' {volume: {'author': author, 'review': review}}}