Filter dictionaries based on a list of field names.
Project description
dictfilter
installation
pip install dictfilter
usage
from dictfilter import query
bsg = {
'class': 'Battlestar',
'model': 'Jupiter',
'name': 'Galactica',
'crew': {
'commander': 'William Adama',
'xo': 'Saul Tigh',
'cag': 'Kara Thrace',
}
}
result = query(bsg, ['class', 'name', 'crew.commander'])
# {
# 'class': 'Battlestar',
# 'name': 'Galactica',
# 'crew': {
# 'commander': 'William Adama',
# }
# }
The default delimiter used in field names is dot .
however this can be changed
with the delimiter
keyword argument to query
:
result = query(bsg, ['class', 'name', 'crew > commander'], delimiter=' > ')
# {
# '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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
dictfilter-2.1.tar.gz
(12.4 kB
view details)
Built Distribution
File details
Details for the file dictfilter-2.1.tar.gz
.
File metadata
- Download URL: dictfilter-2.1.tar.gz
- Upload date:
- Size: 12.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c2da06083dfae2f2dad1528ff5bc45d025b486088cd3714f748d3dc8fd502a7c |
|
MD5 | 86a7e45b391e3d4f93716307957e257b |
|
BLAKE2b-256 | 3672b19e9df3b2d61a145f8af680e40efff020c50b79816ab69d499dba9a3548 |
Provenance
File details
Details for the file dictfilter-2.1-py3-none-any.whl
.
File metadata
- Download URL: dictfilter-2.1-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a35275dfe82755f489902947e0d202c1411009c44680d21fd4370a5bd87a837 |
|
MD5 | c3b5cd511900bf06bcf00cfd0b5a48a4 |
|
BLAKE2b-256 | 4d3e73f1db4c65432570f36e1c495e2bc1f2e55ab74013b74153ef6f0cb586fd |