Skip to content

Commit 257c3b4

Browse files
committed
Adding grep docs
1 parent 79d17d9 commit 257c3b4

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

deepdiff/search.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,32 @@ def __search(self, obj, item, parent="root", parents_ids=frozenset({})):
286286

287287
class grep(object):
288288
"""
289-
Grep!
289+
**Grep!**
290+
291+
grep is a new interface for Deep Search. It takes exactly the same arguments.
292+
And it works just like grep in shell!
293+
294+
**Examples**
295+
296+
Importing
297+
>>> from deepdiff import grep
298+
>>> from pprint import pprint
299+
300+
Search in list for string
301+
>>> obj = ["long somewhere", "string", 0, "somewhere great!"]
302+
>>> item = "somewhere"
303+
>>> ds = obj | grep(item)
304+
>>> print(ds)
305+
{'matched_values': {'root[3]', 'root[0]'}
306+
307+
Search in nested data for string
308+
>>> obj = ["something somewhere", {"long": "somewhere", "string": 2, 0: 0, "somewhere": "around"}]
309+
>>> item = "somewhere"
310+
>>> ds = obj | grep(item, verbose_level=2)
311+
>>> pprint(ds, indent=2)
312+
{ 'matched_paths': {"root[1]['somewhere']": 'around'},
313+
'matched_values': { 'root[0]': 'something somewhere',
314+
"root[1]['long']": 'somewhere'}}
290315
"""
291316

292317
def __init__(self,

0 commit comments

Comments
 (0)