Skip to main content

A Python library to parse strings and extract information from structured/unstructured data

Project description

Build Status Coverage Status Dependency Status PyPi version

Forked from as it seems to be dead. If pygrok becomes active again this fork may be closed.

Python implementaion of Jordan Sissel’s Grok.


pip install yalp_grok

Basic Usage

>>> import yalp_grok as 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'}

Reusing Patterns

Since compiling a pattern can be time consuming, patterns can be compiled once and then reused for searching.

>>> import yalp_grok as pygrok
>>> pattern = "%{COMMONAPACHELOG}"
>>> compiled_pattern = pygrok.compile_pattern(pattern)
>>> with open('/var/log/apache/access.log', 'r') as log_file
...     matches = [pygrok.grok_search(line, compiled_pattern) for line in log_file]

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 yalp_grok, version 0.3
Filename, size File type Python version Upload date Hashes
Filename, size yalp_grok-0.3-py2-none-any.whl (15.9 kB) File type Wheel Python version py2 Upload date Hashes View hashes
Filename, size yalp_grok-0.3.tar.gz (15.3 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page