Skip to main content
Info:

Dictionary wrapper for quick access to deeply nested keys.

Author:

Pawel Zadrozny @pawelzny <pawel.zny@gmail.com>

This is a package published by QMK (https://qmk.fm) since the current dotty-dict published to pypi has non-ASCII characters that breaks with some non-UTF8 locale settings.

Features

  • Simple wrapper around python dictionary and dict like objects

  • Two wrappers with the same dict are considered equal

  • Access to deeply nested keys with dot notation: dot['deeply.nested.key']

  • Create, read, update and delete nested keys of any length

  • Expose all dictionary methods like .get, .pop, .keys and other

  • Access dicts in lists by index dot['parents.0.first_name']

  • key=value caching to speed up lookups and low down memory consumption

  • support for setting value in multidimensional lists

  • support for accessing lists with slices

Installation

pip install dotty-dict

Documentation

TODO

Waiting for your feature requests ;)

Quick Example

Create new dotty using factory function.

>>> from dotty_dict import dotty
>>> dot = dotty({'plain': {'old': {'python': 'dictionary'}}})
>>> dot['plain.old']
{'python': 'dictionary'}

You can start with empty dotty

>>> from dotty_dict import dotty
>>> dot = dotty()
>>> dot['very.deeply.nested.thing'] = 'spam'
>>> dot
Dotty(dictionary={'very': {'deeply': {'nested': {'thing': 'spam'}}}}, separator='.', esc_char='\\')

>>> dot['very.deeply.spam'] = 'indeed'
>>> dot
Dotty(dictionary={'very': {'deeply': {'nested': {'thing': 'spam'}, 'spam': 'indeed'}}}, separator='.', esc_char='\\')

>>> del dot['very.deeply.nested']
>>> dot
Dotty(dictionary={'very': {'deeply': {'spam': 'indeed'}}}, separator='.', esc_char='\\')

>>> dot.get('very.not_existing.key')
None

NOTE: Using integer in dictionary keys will be treated as embedded list index.

Install for development

Install dev dependencies

$ make install

Testing

$ make test

Or full tests with TOX:

$ make test-all

Limitations

In some very rare cases dotty may not work properly.

  • When nested dictionary has two keys of different type, but with the same value. In that case dotty will return dict or list under random key with passed value.

  • Keys in dictionary may not contain dots. If you need to use dots, please specify dotty with custom separator.

  • Nested keys may not be bool type. Bool type keys are only supported when calling keys with type defined value (e.g. dot[True], dot[False]).

Metadata

Release files for qmk-dotty-dict 1.3.0.post1

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

Source distribution (sdist)

Source distribution for qmk-dotty-dict 1.3.0.post1
File Size Uploaded
qmk_dotty_dict-1.3.0.post1.tar.gz 34.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for qmk-dotty-dict 1.3.0.post1
File Interpreter ABI Platform
qmk_dotty_dict-1.3.0.post1-py3-none-any.whl Python 3 none any Details

Total release size: 42.0 kB

Release files / qmk_dotty_dict-1.3.0.post1.tar.gz

Download URL qmk_dotty_dict-1.3.0.post1.tar.gz
Size 34.5 kB
Tags Source
SHA-256 checksum
How to use checksums
3b611e393660bfaa6835c68e94784bae80fe07b8490978b5ecab03a0d2fc7ea2
BLAKE2b-256 checksum
How to use checksums
8d6619e6e56e6839c495e5fcb258b07bbd4a7879a2865de84c35e12074484ea6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.7.10

Release files / qmk_dotty_dict-1.3.0.post1-py3-none-any.whl

Download URL qmk_dotty_dict-1.3.0.post1-py3-none-any.whl
Size 7.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a9cb7fc3ff9631190fee0ecac14986a0ac7b4b6892347dc9d7486a4c4ea24492
BLAKE2b-256 checksum
How to use checksums
b21a05fe9265206c0645b7ecf3384ba4de7f30b1507e7f5b16c4f0a440aff9dc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.7.10

Release history Release notifications | RSS feed

This release

1.3.0.post1 This release

2 release files

1.3.0

2 release files

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