Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

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.

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

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page