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:target: https://img.shields.io/pypi/l/tpfd.svg?maxAge=2592000:target:

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_string('<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.2

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.2
File Size Uploaded Provenance Actions
tpfd-0.2.2.tar.gz 4.0 kB Without provenance Details for tpfd-0.2.2.tar.gz

Release files / tpfd-0.2.2.tar.gz

Download URL tpfd-0.2.2.tar.gz
Size 4.0 kB
Tags Source
SHA-256 checksum
How to use checksums
202291324e2ace9a3cfc04f1fcdfa8adc07090a9532ce1108e90d296b19baa25
BLAKE2b-256 checksum
How to use checksums
809894f843d45a97a946bb436f5b9c70a4f18fdf2a1e0cac1a0b5e1d0cae7704
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for tpfd 0.2.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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