A package for easier access to deeply nested dictionaries.
Project description
Wrappity
Wrappity is a Python package for easier access to deeply nested dictionaries.
Pure Python, no dependencies, lightweight (200 LOC).
What does it do
Wrappity allows you to access deeply nested dictionaries and combinations of dicts and lists using simple attribute 'dot' notation.
It is especially useful when your input are volatile json structures where you can't enforce uniformity.
Instead of...
value = my_dict['foo'][3]['bar'][5]['baz']['this_is_what_I_want']
...you can write
import wrappity
wrapped_dict = wrappity.wrap(my_dict)
value = wrapped_dict.foo[3].bar[5].baz.this_is_what_I_want._
Why bother?
Because if you want to properly account for errors, you might end up with something like:
if 'foo' in my_dict \
and len(my_dict['foo']) >= 3 \
and 'bar' in my_dict['foo'][3] \
and len(my_dict['foo'][3]['bar']) >= 5 \
and 'baz' in my_dict['foo'][3]['bar'][5]:
value = my_dict['foo'][3]['bar'][5]['baz'].get('this_is_what_I_want','my default value')
With Wrappity you don't need to explicitely care about all the elements in the path to be there or not (or have enough items), if anything is missing on the way, Wrappity just gives you None at the end.
This allows (more elegant) constructs like this:
value = wrapped_dict.foo[3].bar[5].baz.this_is_what_I_want._ or "my default value"
print(value)
'my default value' # in case any of the foo, bar or baz are not there
To learn more about why Wrappity was created and what use cases it's good for see here.
Installation
coming soon
Usage
There are 3 key functions in Wrappity:
wrap()- takes an object and wraps it for easy accessunwrap()- reverse function - give it a wrapped object and it gives you the original backinspect()- for introspection - gives you a list of all paths to all leaves in your object incl. their values
Wrap
Unwrap
Inspect
Where can I learn more?
See Wrappity Guide.
Why is it called Wrappity?
Because you do wrappity wrap and that's it! 😉
License
Licensed under the MIT License.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wrappity-0.1.1.tar.gz.
File metadata
- Download URL: wrappity-0.1.1.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ec843b45602cd1c6e9928030aa24fbf0d314c4a3dda8153a89b7d0fd5660b9e
|
|
| MD5 |
192cba530e2720564d31ee17aafb7e01
|
|
| BLAKE2b-256 |
07e362471064ca93fbceb30d13211d99b67f6ef0fd3cf2deedb92554522886c7
|
File details
Details for the file wrappity-0.1.1-py3-none-any.whl.
File metadata
- Download URL: wrappity-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
97b3655be7c70bfd6981614cee43f26e6a48779e52581418c10d2ab89e7c1124
|
|
| MD5 |
d4d67a5c8322acc14f0d58a0b8d05827
|
|
| BLAKE2b-256 |
ba78f4d4b27ea0ef178bb5f6d8133075a4b73d806fdbfa3b8657155ae36bf06c
|