A Python client for Datagrepper
The API is designed around being chainable. To start, create a new Grepper:
>>> from datanozzle import Grepper >>> g = Grepper() >>>
Then, you can build up queries by chaining methods (each new method returns a new query object, so you can reuse partially built queries):
>>> q1 = g.by_user('sross').ascending >>> q2 = q1.by_topic('org.fedoraproject.prod.fedbadges.person.rank.advance') >>>
Queries are not executed until they are evaluated by iterating over them (the library will automatically continue to fetch new pages of information). Each record is returned as an Entry, which has several persistent fields (which are accessible as properties), and additional data available in a dict-like manner:
>>> entry = next(iter(q2.take(pages=1))) >>> entry.topic 'org.fedoraproject.prod.fedbadges.person.rank.advance' >>> entry.timestamp datetime.datetime(2015, 1, 16, 15, 2, 5) >>> entry['person']['nickname'] 'sross' >>>
Most queries can support multiple values. You can either pass multiple values, like g.by_user(‘sross’, ‘someuser’) or chain, like g.by_user(‘sross’).by_user(‘someuser’). To get a query with a parameter reset, call reset(parameter_name), like g.reset(‘user’).