Skip to main content

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:

  1. wrap() - takes an object and wraps it for easy access
  2. unwrap() - reverse function - give it a wrapped object and it gives you the original back
  3. inspect() - 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

wrappity-0.1.1.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wrappity-0.1.1-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

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

Hashes for wrappity-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8ec843b45602cd1c6e9928030aa24fbf0d314c4a3dda8153a89b7d0fd5660b9e
MD5 192cba530e2720564d31ee17aafb7e01
BLAKE2b-256 07e362471064ca93fbceb30d13211d99b67f6ef0fd3cf2deedb92554522886c7

See more details on using hashes here.

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

Hashes for wrappity-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 97b3655be7c70bfd6981614cee43f26e6a48779e52581418c10d2ab89e7c1124
MD5 d4d67a5c8322acc14f0d58a0b8d05827
BLAKE2b-256 ba78f4d4b27ea0ef178bb5f6d8133075a4b73d806fdbfa3b8657155ae36bf06c

See more details on using hashes here.

Supported by

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