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 https://github.com/garyelephant/pygrok as it seems to be dead. If pygrok becomes active again this fork may be closed.

Python implementaion of Jordan Sissel’s Grok.

Install

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.

Source Distribution

yalp_grok-0.3.tar.gz (15.3 kB view hashes)

Uploaded Source

Built Distribution

yalp_grok-0.3-py2-none-any.whl (15.9 kB view hashes)

Uploaded Python 2

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