Skip to main content

Various tools, including:

dictlib.union()

>>> dict3 = dictlib.union(dict1, dict2)
>>> dict3 = dictlib.union_copy(dict1, dict2)

Deep union of dict2 into dict1, where dictionary values are recursively merged. Non-dictionary elements are replaced, with preference given to dict2.

This alters dict1, which is the returned result, but it will have references to both dictionaries. If you do not want this, use union_copy(), which is less efficient but data-safe.

dictlib.dig()

Recursively pull from a dictionary, using dot notation.

>>> dictlib.dig({"a":{"b":{"c":1}}}, "a.b.c")
1
>>> dictlib.dig({"a":{"b":[{"c":1},{"d":2}]}}, "a.b[1].d")
2
>>> dictlib.dig({"a":{"b":{"c":1}}}, "a.b.d")
Traceback:...

There is also dig_get(), which allows for a default, similar to dict.get:

>>> dictlib.dig_get({"a":{"b":{"c":1}}}, "a.b.c", 2)
1
>>> dictlib.dig_get({"a":{"b":{"c":1}}}, "a.b.d", 2)
2

dictlib.dug()

Inverse of dig, puts an item into a nested dictionary, using dot notation. This does not behave functionally, it alters the origin dictionary.

>>> test = {"a":{"b":{"c":1}}}
>>> dug(test, "a.b.c", 200)
>>> test
{'a': {'b': {'c': 200}}}

dictlib.Obj()

Represent a dictionary in object form, while handling tokenizable keys, and can export to original form. Recursive.

Not python zen because it provides an alternate way to use dictionaries. But I'm okay with this, becuase it is handy.

Limitations:

  • raises error if there is a name conflict with reserved words
  • reserves the prefix \f$\f for internal use (raises error)
  • because of namespace conflict problems, this is a deal breaker for universal use--you must be cautious on what keys are input.
  • Two keys exist for each non-tokenized name, such as ugly var!, which is tokenized to ugly_var_. While both exist, if exporting to original object only the value of the tokenized name is used.

Examples:

>>> dictlib.Obj(key1=1, a=2)
{'key1': 1, 'a': 2}
>>> test_dict = {"a":{"b":1,"ugly var!":2}, "c":3}
>>> test_obj = dictlib.Obj(**test_dict)
>>> orig_obj = test_obj.copy() # referenced later
>>> test_obj.keys()
['a', 'c']
>>> 'a' in test_obj
True
>>> test_obj.get('c')
3
>>> test_obj['c']
3
>>> test_obj.c
3
>>> test_obj.c = 4
>>> test_obj.c
4
>>> test_obj.a.b
1
>>> test_obj.a.ugly_var_
2
>>> test_obj.a['ugly var!']
2
>>> test_obj.__original__()
{'a': {'b': 1, 'ugly var!': 2}, 'c': 4}

Release files for dictlib 1.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dictlib 1.1.2
File Size Uploaded
dictlib-1.1.2.tar.gz 5.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dictlib 1.1.2
File Interpreter ABI Platform
dictlib-1.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 24.0 kB

Release files / dictlib-1.1.2.tar.gz

Download URL dictlib-1.1.2.tar.gz
Size 5.7 kB
Tags Source
SHA-256 checksum
How to use checksums
7945a38c37d137cc2a854b3bc803a53f8b3b9c32478caf534c64ffc020416742
BLAKE2b-256 checksum
How to use checksums
a5b1cc6991ea90fea352170213529f2aa245b4b6443f58ad048de593c5430073
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.19.5 CPython/3.6.6

Release files / dictlib-1.1.2-py3-none-any.whl

Download URL dictlib-1.1.2-py3-none-any.whl
Size 18.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6db94be9bbd80602ad32afb1507543275c973c05bebf69f1236c8a73506b0b5e
BLAKE2b-256 checksum
How to use checksums
b6e4c66681aa95fffe77a0e8c211523c3ff25bed371eaac6e23a897d66a05987
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.19.5 CPython/3.6.6

Release history Release notifications | RSS feed

1.1.5

2 release files

1.1.3

1 release file

This release

1.1.2 This release

2 release files

1.0.6

1 release file

1.0.4

1 release file

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page