Skip to main content

TPFD - Text Parsing Function Dispatcher

https://travis-ci.org/erinxocon/tpfd.svg?branch=master https://img.shields.io/pypi/v/tpfd.svg?maxAge=2592000 https://img.shields.io/pypi/l/tpfd.svg?maxAge=2592000

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_parse('{Animal} are cool')
    def main(animal):
        print('I like {0}.'.format(animal))

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

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

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

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

>>> @p.on_find('>{}<')
    def find_example(words):
    print (words)

>>> p.find('<p>the <b>bold</b> text</p>')
'the bold text'

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 or ints

  • Support for parsing unicode strings

  • Supports parsing strings, ints and interator/generator’s automagically with new parse method.

TODO

  • Expose custom types functionality that Parse already offers

Metadata

Release files for tpfd 0.2.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tpfd 0.2.4
File Size Uploaded
tpfd-0.2.4.tar.gz 4.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tpfd 0.2.4
File Interpreter ABI Platform
tpfd-0.2.4-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 10.9 kB

Release files / tpfd-0.2.4.tar.gz

Download URL tpfd-0.2.4.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
f90af668192bab96de1e45bbcdcbfbfe2f906fbff6b45751d0eaa9a083499444
BLAKE2b-256 checksum
How to use checksums
36a683d590ee2982f4b4fd7d50e96eaef57e0028877fe23992ca497d54ad8c1f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / tpfd-0.2.4-py2.py3-none-any.whl

Download URL tpfd-0.2.4-py2.py3-none-any.whl
Size 6.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
8c07ab95d36544c721b2d7a9b75e3c186085f731d577f9d31f86be8e4b69dbe5
BLAKE2b-256 checksum
How to use checksums
0c5c84c2c169652abfb0ad3a4aaee05627d26c5bddbd2764a877cf2b3538d013
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.2.4 This release

2 release files

0.2.2

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.1

1 release file

0.1.0

1 release file

0.0.4

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page