ait-aecid / dictfilter

Filter python dictionaries based on a list of field names.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

dictfilter

installation

pip install dictfilter

usage

bsg = {
    'class': 'Battlestar',
    'model': 'Jupiter',
    'name': 'Galactica',
    'crew': {
        'commander': 'William Adama',
        'xo': 'Saul Tigh',
        'cag': 'Kara Thrace',
    }
}

result = query(some_data, ['class', 'name', 'crew.commander'])

# {
#     'class': 'Battlestar',
#     'name': 'Galactica',
#     'crew': {
#         'commander': 'William Adama',
#     }
# }

django integration

Register the dictfilter middleware in settings.py:

MIDDLEWARE = [
    ...
    'dictfilter.django.middleware.DictFilterMiddleware',
]

By default, every 2xx series response will be filtered based on a comma-separated fields parameter in the query string.

About

Filter python dictionaries based on a list of field names.

License:MIT License


Languages

Language:Python 100.0%