pygrok 
A Python library to parse strings and extract information from structured/unstructured data
What can I use Grok for?
parsing and matching patterns in a string(log, message etc.)
relieving from complex regular expressions.
extracting information from structured/unstructured data
Installation
$ pip install pygrok
or download, uncompress and install pygrok from here:
$ tar zxvf pygrok-xx.tar.gz
$ cd pygrok_dir
$ sudo python setup.py install
Getting Started
>>> import pygrok
>>> text = 'gary is male, 25 years old and weighs 68.5 kilograms'
>>> pattern = '%{WORD:name} is %{WORD:gender}, %{NUMBER:age} years old and weighs %{NUMBER:weight} kilograms'
>>> print pygrok.grok_match(text, pattern)
{'gender': 'male', 'age': '25', 'name': 'gary', 'weight': '68.5'}
Pretty Cool ! Some of the pattern you can use are listed here:
`WORD` means \b\w+\b in regular expression.
`NUMBER` means (?:%{BASE10NUM})
`BASE10NUM` means (?<![0-9.+-])(?>[+-]?(?:(?:[0-9]+(?:\.[0-9]+)?)|(?:\.[0-9]+)))
other patterns such as `IP`, `HOSTNAME`, `URIPATH`, `DATE`, `TIMESTAMP_ISO8601`, `COMMONAPACHELOG`..
See All patterns here
More details
Beause python re module does not support regular expression syntax atomic grouping(?>),so pygrok requires regex to be installed.
pygrok is inspired by Grok developed by Jordan Sissel. This is not a wrapper of Jordan Sissel’s Grok and totally implemented by me.
Grok is a simple software that allows you to easily parse strings, logs and other files. With grok, you can turn unstructured log and event data into structured data.Pygrok does the same thing.
I recommend you to have a look at logstash filter grok, it explains how Grok-like thing work.
pattern files come from logstash filter grok’s pattern files
Contribute
You are encouraged to fork, improve the code, then make a pull request.
Get Help
mail:garygaowork@gmail.com twitter:@garyelephant
Contributors
Thanks to all contributors
Metadata
Release files for pygroker 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pygroker-0.1.1.tar.gz | 20.3 kB | Without provenance | Details |
Release files / pygroker-0.1.1.tar.gz
| Download URL | pygroker-0.1.1.tar.gz |
|---|---|
| Size | 20.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
90fb4995e0a6490bb429ff6b4b576095366977a1f9b6752eb303255203b9be6d
|
|
BLAKE2b-256 checksum How to use checksums |
b95c2acbe37a13b7ed30c02a7b3aea9e16cee2d77fcf4083573d8b430463a152
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for pygroker 0.1.1
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.