Skip to main content

Text parser.

Project description

buildstatus coverage

About

A text parser written in the Python language.

The project has one goal, speed! See the benchmark below more details.

Project homepage: https://github.com/eerimoq/textparser

Documentation: http://textparser.readthedocs.org/en/latest

Credits

  • Thanks PyParsing for a user friendly interface. Many of textparser’s class names are taken from this project.

Installation

pip install textparser

Example usage

The Hello World example parses the string Hello, World! and outputs its parse tree ['Hello', ',', 'World', '!'].

The script:

import textparser
from textparser import Sequence


class Parser(textparser.Parser):

    def token_specs(self):
        return [
            ('SKIP',          r'[ \r\n\t]+'),
            ('WORD',          r'\w+'),
            ('EMARK',    '!', r'!'),
            ('COMMA',    ',', r','),
            ('MISMATCH',      r'.')
        ]

    def grammar(self):
        return Sequence('WORD', ',', 'WORD', '!')


tree = Parser().parse('Hello, World!')

print('Tree:', tree)

Script execution:

$ env PYTHONPATH=. python3 examples/hello_world.py
Tree: ['Hello', ',', 'World', '!']

Benchmark

A benchmark comparing the speed of 10 JSON parsers, parsing a 276 kb file.

$ env PYTHONPATH=. python3 examples/benchmarks/json/speed.py

Parsed 'examples/benchmarks/json/data.json' 1 time(s) in:

PACKAGE         SECONDS   RATIO  VERSION
textparser         0.11    100%  0.17.0
lark (LALR)        0.28    263%  0.6.4
funcparserlib      0.38    353%  unknown
parsimonious       0.42    397%  unknown
textx              0.57    536%  1.7.1
pyparsing          0.74    696%  2.2.0
pyleri             0.89    835%  1.2.2
parsy              1.03    968%  1.2.0
lark (Earley)      2.03   1903%  0.6.4
parsita            2.54   2380%  unknown

NOTE 1: The parsers are not necessarily optimized for speed. Optimizing them will likely affect the measurements.

NOTE 2: The structure of the resulting parse trees varies and additional processing may be required to make them fit the user application.

NOTE 3: Only JSON parsers are compared. Parsing other languages may give vastly different results.

Contributing

  1. Fork the repository.

  2. Install prerequisites.

    pip install -r requirements.txt
  3. Implement the new feature or bug fix.

  4. Implement test case(s) to ensure that future changes do not break legacy.

  5. Run the tests.

    make test
  6. Create a pull request.

Project details


Download files

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

Source Distribution

textparser-0.17.0.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

textparser-0.17.0-py2.py3-none-any.whl (9.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file textparser-0.17.0.tar.gz.

File metadata

  • Download URL: textparser-0.17.0.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.8.1 pkginfo/1.3.2 requests/2.18.3 setuptools/38.5.0 requests-toolbelt/0.7.0 clint/0.5.1 CPython/2.7.14 Linux/4.13.0-46-generic

File hashes

Hashes for textparser-0.17.0.tar.gz
Algorithm Hash digest
SHA256 c1820b690939caa2926c961a031a4a3b60de6fa29330be6fd68d56cd4220d2ec
MD5 e168f8bd423a5aadfaab0833bae17ef5
BLAKE2b-256 316833dd4f015f84e2cf0d08e18af2850bf4f4014df66ce8f3f17580398422ce

See more details on using hashes here.

File details

Details for the file textparser-0.17.0-py2.py3-none-any.whl.

File metadata

  • Download URL: textparser-0.17.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.8.1 pkginfo/1.3.2 requests/2.18.3 setuptools/38.5.0 requests-toolbelt/0.7.0 clint/0.5.1 CPython/2.7.14 Linux/4.13.0-46-generic

File hashes

Hashes for textparser-0.17.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d225802980278c6f1bd3a3c90cc844e1e95515f98ab4465f14cc495a8cdcd2cd
MD5 4a863b964cd9abafa51854f23d624052
BLAKE2b-256 81e5975c327d5a43553288f51db3373ba822e880160f60ec5e0db2d485e50338

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page