|
10 | 10 | </div>
|
11 | 11 | <br>
|
12 | 12 |
|
13 |
| -Wireshark-like display filter for python dictionaries. |
| 13 | +A Wireshark-like display filter for Python dictionaries. This tool allows you to easily filter, analyze, and |
| 14 | +manipulate data in Python dictionaries. It offers a range of features including comparison operators, |
| 15 | +combining operators, membership operators, and more. |
| 16 | + |
| 17 | +## Table of Contents |
| 18 | +1. [Quick Start](#quick-start) |
| 19 | +2. [Usage](#usage) |
| 20 | +3. [Features](#features) |
| 21 | +4. [Examples](#examples) |
| 22 | +5. [Acknowledgements](#acknowledgements) |
| 23 | + |
| 24 | +## Quick Start |
| 25 | + |
| 26 | +Here's a simple example to get you started. First, install the package: |
14 | 27 |
|
15 |
| -## Setup |
16 | 28 | ```commandline
|
17 | 29 | pip3 install python-dict-display-filter
|
18 | 30 | ```
|
19 | 31 |
|
20 |
| -## Usage |
| 32 | +Then, use it to filter a list of dictionaries: |
| 33 | +``` |
| 34 | +from pydictdisplayfilter import DictDisplayFilter |
| 35 | +actors = [ |
| 36 | + {"name": ["Laurence", "Fishburne"], "age": {"born": "1961"}, "gender": "male"}, |
| 37 | + {"name": ["Keanu", "Reeves"], "age": {"born": "1964"}, "gender": "male", "power": ["flight", "bullet-time"]}, |
| 38 | + {"name": ["Joe", "Pantoliano"], "age": {"born": "1951"}, "gender": "male"}, |
| 39 | + {"name": ["Carrie-Anne", "Moss"], "age": {"born": "1967"}, "gender": "female"} |
| 40 | +] |
| 41 | +ddf = DictDisplayFilter(actors) |
21 | 42 |
|
22 |
| -The basics and the syntax of the display filter are described in the |
23 |
| -<a href="https://github.com/bytebutcher/python-dict-display-filter/blob/main/docs/USER_GUIDE.md">User Guide</a>. |
| 43 | +# This will filter the list to show only male actors born between 1960 and 1965 whose names end with 'e' |
| 44 | +filtered_actors = ddf.filter("gender == male and (age.born > 1960 and age.born < 1965) and name matches .*e$") |
24 | 45 |
|
25 |
| -If you want to see some advanced examples of how ```python-dict-display-filter``` can be put to use checkout the |
26 |
| -<a href="https://github.com/bytebutcher/python-dict-display-filter/blob/main/docs/EXAMPLES.md">Examples</a>. |
| 46 | +print(list(filtered_actors)) |
| 47 | +[{'name': ['Laurence', 'Fishburne'], 'age': {'born': '1961'}, 'gender': 'male'}] |
| 48 | +``` |
27 | 49 |
|
28 |
| -If you want to use ```python-dict-display-filter``` in your own application and customize it to your needs |
29 |
| -check out the |
30 |
| -<a href="https://github.com/bytebutcher/python-dict-display-filter/blob/main/docs/DEVELOPER_GUIDE.md">Developer Guide</a>. |
| 50 | +For more details, please refer to the |
| 51 | +<a href="https://github.com/bytebutcher/python-dict-display-filter/blob/main/docs/USER_GUIDE.md">User Guide</a>. |
31 | 52 |
|
32 | 53 | ## Features
|
33 |
| -The following overview shows all the supported features of the display filter: |
| 54 | + |
| 55 | +Python Dictionary Display Filter supports a wide range of features, including: |
34 | 56 | * **Comparison Operators:** ```==```, ```!=```, ```<=```, ```<```, ```>=```, ```>```, ```~=```, ```~```, ```&```
|
35 | 57 | * **Combining Operators:** ```and```, ```or```, ```xor```, ```not```
|
36 | 58 | * **Membership Operators:** ```in```
|
37 | 59 | * **Types:** ```Text```, ```Number```, ```Date & Time```, ```Ethernet-```, ```IPv4-```, ```IPv6-Address```
|
38 | 60 | * **Slicing:** ```Text```, ```Ethernet-```, ```IPv4-```, ```IPv6-Address```
|
39 | 61 | * **Functions:** ```upper```, ```lower```, ```len```
|
| 62 | +* **Data Sources**: ```CSV```, ```Dictionaries```, ```JSON```, ```SQLite``` |
40 | 63 |
|
41 | 64 | For a detailed description of the individual features check out the
|
42 | 65 | <a href="https://github.com/bytebutcher/python-dict-display-filter/blob/main/docs/USER_GUIDE.md">User Guide</a>.
|
43 | 66 |
|
44 | 67 | ## Examples
|
45 | 68 |
|
46 |
| -Initialize ```DictDisplayFilter``` with a list of dictionaries: |
47 |
| -``` |
48 |
| -> from pydictdisplayfilter import DictDisplayFilter |
49 |
| -> actors = [ |
50 |
| - {"name": ["Laurence", "Fishburne"], "age": {"born": "1961"}, "gender": "male"}, |
51 |
| - {"name": ["Keanu", "Reeves"], "age": {"born": "1964"}, "gender": "male", "power": ["flight", "bullet-time"]}, |
52 |
| - {"name": ["Joe", "Pantoliano"], "age": {"born": "1951"}, "gender": "male"}, |
53 |
| - {"name": ["Carrie-Anne", "Moss"], "age": {"born": "1967"}, "gender": "female"} |
54 |
| -] |
55 |
| -> ddf = DictDisplayFilter(actors) |
56 |
| -``` |
57 |
| - |
58 |
| -Show only actors with some kind of super-power: |
59 |
| -``` |
60 |
| -> ddf.filter("power") |
61 |
| -``` |
62 |
| - |
63 |
| -Show only actors which were born before 1965: |
64 |
| -``` |
65 |
| -> ddf.filter("age.born < 1965") |
66 |
| -``` |
67 |
| - |
68 |
| -Show only female actors: |
69 |
| -``` |
70 |
| -> ddf.filter("gender == female") |
71 |
| -``` |
72 |
| - |
73 |
| -Show all male actors which are born between 1960 and 1965: |
74 |
| -``` |
75 |
| -> ddf.filter("gender == male and (age.born > 1960 and age.born < 1965)") |
76 |
| -``` |
77 |
| - |
78 |
| -Show all actors which name contain the character 'e': |
79 |
| -``` |
80 |
| -> ddf.filter("name contains e") |
81 |
| -``` |
82 |
| - |
83 |
| -Show all actors which name matches a regular expression: |
84 |
| -``` |
85 |
| -> ddf.filter("name matches .*e$") |
86 |
| -``` |
| 69 | +For detailed examples of how the display filter can be utilized, please refer to the following: |
87 | 70 |
|
88 |
| -## Inspired by |
| 71 | +* [CSV Display Filter](https://github.com/bytebutcher/python-dict-display-filter/blob/main/docs/EXAMPLES.md#csv-display-filter) |
| 72 | +* [JSON Display Filter](https://github.com/bytebutcher/python-dict-display-filter/blob/main/docs/EXAMPLES.md#json-display-filter) |
| 73 | +* [SQLite Display Filter](https://github.com/bytebutcher/python-dict-display-filter/blob/main/docs/EXAMPLES.md#sqlite-display-filter) |
| 74 | +* [Nmap Display Filter](https://github.com/bytebutcher/python-dict-display-filter/blob/main/docs/EXAMPLES.md#nmap-display-filter) |
89 | 75 |
|
90 |
| -* <a href="https://wiki.wireshark.org/DisplayFilters">Wireshark Display Filter</a> |
| 76 | +## Acknowledgements |
91 | 77 |
|
92 |
| -## Powered by |
| 78 | +This project wouldn't be possible without these awesome projects: |
93 | 79 |
|
| 80 | +* <a href="https://wiki.wireshark.org/DisplayFilters">wireshark display filter</a>: Display filter for filtering network packages |
94 | 81 | * <a href="https://github.com/wolever/parameterized">parameterized</a>: Parameterized testing with any Python test framework
|
95 | 82 | * <a href="https://github.com/pyparsing/pyparsing/">pyparsing</a>: Creating PEG-parsers made easy
|
96 | 83 | * <a href="https://github.com/bytebutcher/ipranger/">ipranger</a>: Parsing and matching IPv4-addresses
|
|
0 commit comments