I'm not aware on any python ports of grok, but this functionality seems pretty straightforward to implement:
import re
types = {
'WORD': r'\w+',
'NUMBER': r'\d+',
# todo: extend me
}
def compile(pat):
return re.sub(r'%{(\w+):(\w+)}',
lambda m: "(?P<" + m.group(2) + ">" + types[m.group(1)] + ")", pat)
rr = compile("%{WORD:method} %{NUMBER:bytes} %{NUMBER:duration}")
print re.search(rr, "hello 123 456").groupdict()
# {'duration': '456', 'bytes': '123', 'method': 'hello'}