File: README.rst

package info (click to toggle)
dotty-dict 1.3.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 352 kB
  • sloc: python: 1,166; makefile: 192; sh: 5
file content (117 lines) | stat: -rw-r--r-- 2,932 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
**********
Dotty-Dict
**********

:Info: Dictionary wrapper for quick access to deeply nested keys.
:Author: Pawel Zadrozny @pawelzny <pawel.zny@gmail.com>


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
============

.. code:: bash

   pip install dotty-dict


* **Package**: https://pypi.org/project/dotty-dict/
* **Source**: https://github.com/pawelzny/dotty_dict


Documentation
=============

* Full documentation: http://dotty-dict.readthedocs.io
* Public API: http://dotty-dict.readthedocs.io/en/latest/api.html
* Examples and usage ideas: http://dotty-dict.readthedocs.io/en/latest/examples.html


TODO
====

Waiting for your feature requests ;)


Quick Example
=============

Create new dotty using factory function.

.. code-block:: python

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


You can start with empty dotty

.. code-block:: python

   >>> 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

.. code-block:: console

    $ make install

Testing
=======

.. code-block:: console

    $ make test

Or full tests with TOX:

.. code-block:: console

    $ 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]).