Skip to main content

Dictionary filter

Project description

interdict

Python dictionary filter

Installation

pip install interdict

Examples

Default (inclusion False)

>>> from interdict import filter_obj
>>> obj = {'name': 'shane', 'job': {'salary': 1000000, 'role': 'master of universe'}}
>>> filter = {'name': True, 'job': {'role': True}}
>>> filter_obj(obj, filter)
{'name': 'shane', 'job': {'role': 'master of universe'}}

Inclusive (a.k.a. TMI)

>>> filter_obj(obj, filter, default=True)
{'name': 'shane', 'job': {'salary': 1000000, 'role': 'master of universe'}}

Inclusive with better filter

>>> filter = {'job': {'salary': False}}
>>> filter_obj(obj, filter, default=True)
{'name': 'shane', 'job': {'role': 'master of universe'}}

Stacked filters

>>> obj = {'name': 'shane', 'job': {'salary': 1000000, 'role': {'title': 'master of universe', 'reality': 'dumpster fire starter'}}}
>>> filter_1 = {'name': False}
>>> filter_2 = {'job': {'salary': False, 'role': {'reality': False}}}
>>> filter_obj(obj, [filter_1, filter_2], default=True)
{'job': {'role': {'title': 'master of universe'}}}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

interdict-2020.11.1.tar.gz (3.0 kB view hashes)

Uploaded Source

Built Distribution

interdict-2020.11.1-py3-none-any.whl (3.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page