DictDeeper: The easy way to manipulate deeply-nested dicts like JSON-style objects.
What you can do with DictDeeper?
- You can navigate to any depth with a simple dotted-string key notation.
- You can even transparently navigate within lists inside dicts.
- You can do full and partial validate of your dict structure in a declarative way.
- You can do full and partial value comparison in a declarative way.
- You can arrange a variety of strategies to merge dicts into a single one.
How to use it?
To access values nested in an object using a dotted-key notation,
wrap the object using DeepDict, then use the standard dict interface:
from dictdeeper import DeepDict
request_body = DeepDict(request.json())
is_scheduled = request_body.get("data.attributes.date_scheduled") is not None
How to match the structure of a deeply nested dict?
Use DeepDict to compare the values within a dict or list against a partial specification.
Both DeepDict and DeepList objects automatically use deep matching in their __eq__ method.
When a comparison fails, a MatcherError is raised, with the location and context of the mismatch.
Here are the things you can use in the matching spec:
some_keyin adictexists of any value: Include"some_key": ...in the spec.- Other keys may exist in a
dict: Include...: ...in the spec. - Matching items in an unordered
list: Include...as an item in the spec. - Matching a string against a regex: Use
re.compile("your-regex-here")as a value in the spec.
Example:
data = {
"1": "one",
"2": {
"a": "A",
"b": {
"i": "I",
"ii": "II",
},
},
"3": ["index0", "index1", "index2"],
"4": [{"id": 1, "name": "foo"}, {"id": 2, "name": "bar"}, {"id": 3, "name": "baz"}],
}
assert DeepDict(data) == {
"1": ..., # [1]
"3": ["index1", ...], # [3]
"4": [{"name": re.compile("ba."), ...: ...,}, ...], # [4]
...: ..., # [2]
}
Thank you to Routable
Routable sponsored the development of this library. Working at Routable is an awesome experience, with a developer-first culture that fosters innovation and growth. If you're interested in joining a dynamic team, check out our job opportunities here!
Authors
- Henrique Bastos henrique@bastos.net
- Matthew Scott matt@11craft.com
Metadata
Release files for dictdeeper 1.2
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 | |
|---|---|---|---|---|
| dictdeeper-1.2.tar.gz | 26.0 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| dictdeeper-1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 33.6 kB
Release files / dictdeeper-1.2.tar.gz
| Download URL | dictdeeper-1.2.tar.gz |
|---|---|
| Size | 26.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c7a5e3ae926ae2976762ffbfbd85a83d401a34ae4c82755b98f949a8a1f53a37
|
|
BLAKE2b-256 checksum How to use checksums |
e10b35a57efecf93d64dd40fd06d5488e441e97955d5168bb912647b543bad7c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 28, 2025.
Transparency logRelease files / dictdeeper-1.2-py3-none-any.whl
| Download URL | dictdeeper-1.2-py3-none-any.whl |
|---|---|
| Size | 7.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ed2dc55c74d92ff4cfc3b1279e1d4bd163aa5ae2ba46326728f04fed89dae77a
|
|
BLAKE2b-256 checksum How to use checksums |
1a7f52cef29033ece693a3b63b579d9b4c78a9044da12ef8e13501c103cfeedd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 28, 2025.
Transparency logSecurity for dictdeeper 1.2
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.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for dictdeeper-1.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 28, 2025.
Transparency logA 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.