Python Display Filter Query Language
A Wireshark-like display filter various data formats, including Python dictionaries, lists, objects, and SQL databases.
Table of Contents
Quick Start
To quickly get started follow the steps below:
Installation
First, install the package using pip:
pip3 install pydfql
Initialization
Next, import the necessary module and initialize the appropriate display filter with some data.
In the example below we are initializing the ObjectDisplayFilter with a list of objects:
from dataclasses import dataclass
from pydfql import ObjectDisplayFilter
@dataclass
class Actor:
name: list
age: dict
gender: str
actors = [
Actor(["Laurence", "Fishburne"], {"born": "1961"}, "male"),
Actor(["Keanu", "Reeves"], {"born": "1964"}, "male"),
Actor(["Joe", "Pantoliano"], {"born": "1951"}, "male"),
Actor(["Carrie-Anne", "Moss"], {"born": "1967"}, "female")
]
df = ObjectDisplayFilter(actors)
Filtering Data
Once the display filter is initialized, you can start filtering the data using the display filter query language. For example, let's filter the actors whose birth year is after 1960:
filter_query = "age.born > 1960"
filtered_data = df.filter(filter_query)
print(list(filtered_data))
[
Actor(name=['Laurence', 'Fishburne'], age={'born': '1961'}, gender='male'),
Actor(name=['Keanu', 'Reeves'], age={'born': '1964'}, gender='male'),
Actor(name=['Carrie-Anne', 'Moss'], age={'born': '1967'}, gender='female')
]
You can also use more complex queries to filter the data. For example, let's filter male actors born between 1960 and 1964 whose names end with "e":
filter_query = "gender == male and (age.born > 1960 and age.born < 1965) and name matches .*e$"
filtered_data = df.filter(filter_query)
print(list(filtered_data))
This will output the filtered data:
[Actor(name=['Laurence', 'Fishburne'], age={'born': '1961'}, gender='male')]
Overall, PyDFQL supports a wide range of features, including:
- Data Types:
Dictionaries,Lists,Objects,SQL - Comparison Operators:
==,!=,<=,<,>=,>,~=,~,& - Combining Operators:
and,or,xor,not - Membership Operators:
in - Types:
Text,Number,Date & Time,Ethernet-,IPv4-,IPv6-Address - Slicing:
Text,Ethernet-,IPv4-,IPv6-Address - Functions:
upper,lower,len
For a detailed description of the individual features check out the User Guide.
Examples
For detailed examples of how the display filter can be utilized, please refer to the following:
Acknowledgements
This project wouldn't be possible without these awesome projects:
- wireshark display filter: Display filter for filtering network packages
- parameterized: Parameterized testing with any Python test framework
- pyparsing: Creating PEG-parsers made easy
- ipranger: Parsing and matching IPv4-addresses
- python-dateutil: Parsing and comparing dates
Metadata
Release files for pydfql 1.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pydfql-1.3.0.tar.gz | 38.7 kB | Without provenance | Details for pydfql-1.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pydfql-1.3.0-py3-none-any.whl | Python 3 | none | any | Details for pydfql-1.3.0-py3-none-any.whl |
Total release size: 92.8 kB
Release files / pydfql-1.3.0.tar.gz
| Download URL | pydfql-1.3.0.tar.gz |
|---|---|
| Size | 38.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8daea61968722230d2a1b8e6c151914174dc0a264e368852db41974d5a68a3cf
|
|
BLAKE2b-256 checksum How to use checksums |
ee6c1097b8c7a37c5a296097c0c28b30dc2f64418f975618c7e5d314b6d7556e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.65.0 urllib3/1.26.5 CPython/3.10.6
|
Release files / pydfql-1.3.0-py3-none-any.whl
| Download URL | pydfql-1.3.0-py3-none-any.whl |
|---|---|
| Size | 54.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
447df990c95bd732e96eedf3c3584f2b9b67458222c07ca82d9ecec56d3417fa
|
|
BLAKE2b-256 checksum How to use checksums |
605ee1e75066be759e5386984b0b39504ef07216d0e5c13514ed9fd3ea2a2898
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.65.0 urllib3/1.26.5 CPython/3.10.6
|
Security for pydfql 1.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.