Skip to main content

Text Parsing Function Dispatcher

Project description

https://travis-ci.org/erinxocon/tpfd.svg?branch=master

TPFD is an easy way to parse strings and execute functions depending on their contents.

Inspired by flask and using parse under the hood, this allows you to decorate functions with grammar rules and if a pattern that matches one of your grammar rules is found, the function will be run with a set of keyword arguments you’ve specified passed to it! Great for parsing logs and executing macros on what it finds!

Examples

Aniamls.txt
Turtles are cool
Sloths are cool
Mosquitos are dumb

>>> p  = tpfd.Parser()

>>> @p.on_recognize('{Animal} are cool')
    def main(animal):
        print('I like {0}.'.format(animal))

>>> p.parse_file('animals.txt')
'I like turtles.'
'I like sloths.'

>>> p.iter_parse(['Turtles are cool', 'Sloths are cool', 'Mosquitos are dumb'])
'I like turtles.'
'I like sloths.'

>>> p.parse_string('Sloths are cool')
'I like sloths.'

>>> p.parse_string('Mosquitos are dumb')
None

To Install

$ pip install tpfd

Notes

Any format spec supported by parse is supported by this library since it’s all parse under the hood. Example: {[field name]:[format spec]}

Current Features

  • Support for parsing text files
  • Support for accepting generators that output text.

TODO

  • Support streams
  • various built in converters to translate numbers/day names/dates

Project details


Download files

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

Files for tpfd, version 0.0.4
Filename, size File type Python version Upload date Hashes
Filename, size tpfd-0.0.4.tar.gz (3.4 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page