dotty-dictionary 1.2.0__tar.gz → 1.2.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,10 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: dotty-dictionary
3
- Version: 1.2.0
3
+ Version: 1.2.1
4
4
  Summary: Dictionary wrapper that provides dot notation access to nested dictionaries
5
5
  License: MIT
6
+ License-File: AUTHORS.md
7
+ License-File: LICENSE
6
8
  Author: 01Joseph-Hwang10
7
9
  Author-email: joseph95501@gmail.com
8
10
  Requires-Python: >=3.10,<4.0
@@ -14,8 +16,10 @@ Classifier: Programming Language :: Python :: 3
14
16
  Classifier: Programming Language :: Python :: 3.10
15
17
  Classifier: Programming Language :: Python :: 3.11
16
18
  Classifier: Programming Language :: Python :: 3.12
17
- Classifier: Programming Language :: Python :: 3 :: Only
18
19
  Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
21
+ Classifier: Programming Language :: Python :: 3.15
22
+ Classifier: Programming Language :: Python :: 3 :: Only
19
23
  Classifier: Programming Language :: Python :: Implementation :: CPython
20
24
  Classifier: Programming Language :: Python :: Implementation :: PyPy
21
25
  Classifier: Topic :: Software Development
@@ -35,19 +39,6 @@ Description-Content-Type: text/markdown
35
39
 
36
40
  `dotty-dictionary` is a fork of [pawelzny/dotty_dict](https://github.com/pawelzny/dotty_dict) that provides additional features and improvements.
37
41
 
38
- ## Features
39
-
40
- - Simple wrapper around python dictionary and dict like objects
41
- - Two wrappers with the same dict are considered equal
42
- - Access to deeply nested keys with dot notation: dot['deeply.nested.key']
43
- - Create, read, update and delete nested keys of any length
44
- - Expose all dictionary methods like .get, .pop, .keys and other
45
- - Access dicts in lists by index dot['parents.0.first_name']
46
- - Support for setting value in multidimensional lists
47
- - Support for accessing lists with slices
48
- - Support for flattening nested dictionary keys from a dotty dictionary and vice versa
49
- - Support for iteration over nested dictionary keys (e.g. `for key in dotty_dict_instance`)
50
-
51
42
  ## Installation
52
43
 
53
44
  ```bash
@@ -57,44 +48,82 @@ pip install dotty-dictionary
57
48
  - Package: <https://pypi.org/project/dotty-dictionary>
58
49
  - Source: <https://github.com/01Joseph-Hwang10/dotty-dictionary>
59
50
 
60
- ## Quick Example
51
+ ## Features
52
+
53
+ ### Provides dot notation acccess to dictionary objects
61
54
 
62
- Create new dotty using factory function.
55
+ It provides a simple wrapper around python dictionary and dict like `Mapping` objects.
56
+ You can access deeply nested keys with dot notation.
63
57
 
64
58
  ```py
65
59
  from dotty_dictionary import dotty
66
- dot = dotty({'plain': {'old': {'python': 'dictionary'}}})
67
- dot['plain.old']
68
- {'python': 'dictionary'}
60
+ dot = dotty({"deeply": {"nested": {"key": "value"}}})
61
+ dot['deeply.nested.key']
62
+ 'value'
69
63
  ```
70
64
 
71
- You can start with empty dotty
65
+ ### Exposes all dictionary methods (`.get`, `.pop`, `.keys`, ...)
66
+
67
+ You can use all dictionary methods like `.get`, `.pop`, `.keys` and other.
72
68
 
73
69
  ```py
74
70
  from dotty_dictionary import dotty
75
- dot = dotty() # Alias: `Dotty.empty()`
76
- dot['very.deeply.nested.thing'] = 'spam'
77
- dot
78
- Dotty(dictionary={'very': {'deeply': {'nested': {'thing': 'spam'}}}}, separator='.', esc_char='\\')
71
+ dot = dotty({"deeply": {"nested": {"key": "value"}}})
79
72
 
80
- dot['very.deeply.spam'] = 'indeed'
81
- dot
82
- Dotty(dictionary={'very': {'deeply': {'nested': {'thing': 'spam'}, 'spam': 'indeed'}}}, separator='.', esc_char='\\')
73
+ # View methods
74
+ list(dot.keys()) # ["deeply"]
75
+ list(dot.values()) # [{"nested": {"key": "value"}}]
76
+ list(dot.items()) #[("deeply", {"nested": {"key": "value"}})]
83
77
 
84
- del dot['very.deeply.nested']
78
+ # `.update`
79
+ dot.update({"other": "value"})
85
80
  dot
86
- Dotty(dictionary={'very': {'deeply': {'spam': 'indeed'}}}, separator='.', esc_char='\\')
81
+ Dot(dictionary={'deeply': {'nested': {'key': 'value'}}, 'other': 'value'}, separator='.', esc_char='\\')
87
82
 
88
- dot.get('very.not_existing.key')
89
- None
83
+ # `.pop`: Pops nested keys
84
+ dot.pop("deeply.nested.key")
85
+ "value"
86
+
87
+ # `.copy`
88
+ dot is not dot.copy()
89
+ True
90
90
  ```
91
91
 
92
- More examples can be found in the [examples](https://github.com/01Joseph-Hwang10/dotty-dictionary/tree/master/examples) directory.
92
+ ### Dot notation access support for list objects
93
+
94
+ You can access dicts in lists by index like: `dot['parents.0.first_name']`.
95
+ It also supports multidimensional lists.
96
+
97
+ ```py
98
+ from dotty_dictionary import dotty
99
+ dot = dotty({"parents": [{"first_name": "John"}, {"first_name": "Jane"}]})
100
+ dot['parents.0.first_name']
101
+ 'John'
102
+
103
+ dot = dotty({"matrix": [[1, 2, 3], [4, 5, 6], [7, 8, 9]]})
104
+ dot['matrix.1.1']
105
+ 5
106
+ ```
93
107
 
94
108
  > [!NOTE]\
95
109
  > Using integer in dictionary keys will be treated as embedded list index.
96
110
 
97
- ## Flattening and Unflattening
111
+
112
+ ### Support for accessing lists with slices
113
+
114
+ You can access lists with slices like: `dot['parents.0:2']`.
115
+
116
+ ```py
117
+ from dotty_dictionary import dotty
118
+ dot = dotty({"parents": [{"first_name": "John"}, {"first_name": "Jane"}, {"first_name": "Doe"}]})
119
+ dot['parents.0:2']
120
+ [{"first_name": "John"}, {"first_name": "Jane"}]
121
+
122
+ dot['parents.:']
123
+ [{"first_name": "John"}, {"first_name": "Jane"}, {"first_name": "Doe"}]
124
+ ```
125
+
126
+ ### Flattening and Unflattening
98
127
 
99
128
  You can utilize `to_flat_dict` and `from_flat_dict` to convert dotty to and from flat dictionary.
100
129
 
@@ -108,7 +137,7 @@ dot.to_flat_dict()
108
137
  {'very.deeply.nested.thing': 'spam', 'very.deeply.spam': 'indeed'}
109
138
  ```
110
139
 
111
- ## Custom Types && Encoders
140
+ ### Custom Types && Encoders
112
141
 
113
142
  By default, `dotty-dictionary` only considers `dict` as a mapping type, and `list` as a sequence type and will provide a dot notation access for them. However, you can also provide custom types to be considered as mapping or sequence types.
114
143
 
@@ -123,6 +152,8 @@ class User(MutableMapping):
123
152
  name: str
124
153
  age: int
125
154
 
155
+ # Implementations are skipped for brevity
156
+
126
157
  class CustomJSONEncoder(DottyEncoder):
127
158
  def default(self, obj):
128
159
  if isinstance(obj, User):
@@ -157,6 +188,9 @@ dot["h.age"]
157
188
 
158
189
  Full example can be found on [tests/test_dotty_custom_types.py](https://github.com/01Joseph-Hwang10/dotty-dictionary/tree/master/tests/test_dotty_custom_types.py)
159
190
 
191
+ ## More Examples
192
+
193
+ More examples can be found in the [examples](https://github.com/01Joseph-Hwang10/dotty-dictionary/tree/master/examples) and [tests](https://github.com/01Joseph-Hwang10/dotty-dictionary/tree/master/tests) directory.
160
194
 
161
195
  ## Contributing
162
196
 
@@ -11,19 +11,6 @@
11
11
 
12
12
  `dotty-dictionary` is a fork of [pawelzny/dotty_dict](https://github.com/pawelzny/dotty_dict) that provides additional features and improvements.
13
13
 
14
- ## Features
15
-
16
- - Simple wrapper around python dictionary and dict like objects
17
- - Two wrappers with the same dict are considered equal
18
- - Access to deeply nested keys with dot notation: dot['deeply.nested.key']
19
- - Create, read, update and delete nested keys of any length
20
- - Expose all dictionary methods like .get, .pop, .keys and other
21
- - Access dicts in lists by index dot['parents.0.first_name']
22
- - Support for setting value in multidimensional lists
23
- - Support for accessing lists with slices
24
- - Support for flattening nested dictionary keys from a dotty dictionary and vice versa
25
- - Support for iteration over nested dictionary keys (e.g. `for key in dotty_dict_instance`)
26
-
27
14
  ## Installation
28
15
 
29
16
  ```bash
@@ -33,44 +20,82 @@ pip install dotty-dictionary
33
20
  - Package: <https://pypi.org/project/dotty-dictionary>
34
21
  - Source: <https://github.com/01Joseph-Hwang10/dotty-dictionary>
35
22
 
36
- ## Quick Example
23
+ ## Features
37
24
 
38
- Create new dotty using factory function.
25
+ ### Provides dot notation acccess to dictionary objects
26
+
27
+ It provides a simple wrapper around python dictionary and dict like `Mapping` objects.
28
+ You can access deeply nested keys with dot notation.
39
29
 
40
30
  ```py
41
31
  from dotty_dictionary import dotty
42
- dot = dotty({'plain': {'old': {'python': 'dictionary'}}})
43
- dot['plain.old']
44
- {'python': 'dictionary'}
32
+ dot = dotty({"deeply": {"nested": {"key": "value"}}})
33
+ dot['deeply.nested.key']
34
+ 'value'
45
35
  ```
46
36
 
47
- You can start with empty dotty
37
+ ### Exposes all dictionary methods (`.get`, `.pop`, `.keys`, ...)
38
+
39
+ You can use all dictionary methods like `.get`, `.pop`, `.keys` and other.
48
40
 
49
41
  ```py
50
42
  from dotty_dictionary import dotty
51
- dot = dotty() # Alias: `Dotty.empty()`
52
- dot['very.deeply.nested.thing'] = 'spam'
53
- dot
54
- Dotty(dictionary={'very': {'deeply': {'nested': {'thing': 'spam'}}}}, separator='.', esc_char='\\')
43
+ dot = dotty({"deeply": {"nested": {"key": "value"}}})
55
44
 
56
- dot['very.deeply.spam'] = 'indeed'
57
- dot
58
- Dotty(dictionary={'very': {'deeply': {'nested': {'thing': 'spam'}, 'spam': 'indeed'}}}, separator='.', esc_char='\\')
45
+ # View methods
46
+ list(dot.keys()) # ["deeply"]
47
+ list(dot.values()) # [{"nested": {"key": "value"}}]
48
+ list(dot.items()) #[("deeply", {"nested": {"key": "value"}})]
59
49
 
60
- del dot['very.deeply.nested']
50
+ # `.update`
51
+ dot.update({"other": "value"})
61
52
  dot
62
- Dotty(dictionary={'very': {'deeply': {'spam': 'indeed'}}}, separator='.', esc_char='\\')
53
+ Dot(dictionary={'deeply': {'nested': {'key': 'value'}}, 'other': 'value'}, separator='.', esc_char='\\')
54
+
55
+ # `.pop`: Pops nested keys
56
+ dot.pop("deeply.nested.key")
57
+ "value"
63
58
 
64
- dot.get('very.not_existing.key')
65
- None
59
+ # `.copy`
60
+ dot is not dot.copy()
61
+ True
66
62
  ```
67
63
 
68
- More examples can be found in the [examples](https://github.com/01Joseph-Hwang10/dotty-dictionary/tree/master/examples) directory.
64
+ ### Dot notation access support for list objects
65
+
66
+ You can access dicts in lists by index like: `dot['parents.0.first_name']`.
67
+ It also supports multidimensional lists.
68
+
69
+ ```py
70
+ from dotty_dictionary import dotty
71
+ dot = dotty({"parents": [{"first_name": "John"}, {"first_name": "Jane"}]})
72
+ dot['parents.0.first_name']
73
+ 'John'
74
+
75
+ dot = dotty({"matrix": [[1, 2, 3], [4, 5, 6], [7, 8, 9]]})
76
+ dot['matrix.1.1']
77
+ 5
78
+ ```
69
79
 
70
80
  > [!NOTE]\
71
81
  > Using integer in dictionary keys will be treated as embedded list index.
72
82
 
73
- ## Flattening and Unflattening
83
+
84
+ ### Support for accessing lists with slices
85
+
86
+ You can access lists with slices like: `dot['parents.0:2']`.
87
+
88
+ ```py
89
+ from dotty_dictionary import dotty
90
+ dot = dotty({"parents": [{"first_name": "John"}, {"first_name": "Jane"}, {"first_name": "Doe"}]})
91
+ dot['parents.0:2']
92
+ [{"first_name": "John"}, {"first_name": "Jane"}]
93
+
94
+ dot['parents.:']
95
+ [{"first_name": "John"}, {"first_name": "Jane"}, {"first_name": "Doe"}]
96
+ ```
97
+
98
+ ### Flattening and Unflattening
74
99
 
75
100
  You can utilize `to_flat_dict` and `from_flat_dict` to convert dotty to and from flat dictionary.
76
101
 
@@ -84,7 +109,7 @@ dot.to_flat_dict()
84
109
  {'very.deeply.nested.thing': 'spam', 'very.deeply.spam': 'indeed'}
85
110
  ```
86
111
 
87
- ## Custom Types && Encoders
112
+ ### Custom Types && Encoders
88
113
 
89
114
  By default, `dotty-dictionary` only considers `dict` as a mapping type, and `list` as a sequence type and will provide a dot notation access for them. However, you can also provide custom types to be considered as mapping or sequence types.
90
115
 
@@ -99,6 +124,8 @@ class User(MutableMapping):
99
124
  name: str
100
125
  age: int
101
126
 
127
+ # Implementations are skipped for brevity
128
+
102
129
  class CustomJSONEncoder(DottyEncoder):
103
130
  def default(self, obj):
104
131
  if isinstance(obj, User):
@@ -133,6 +160,9 @@ dot["h.age"]
133
160
 
134
161
  Full example can be found on [tests/test_dotty_custom_types.py](https://github.com/01Joseph-Hwang10/dotty-dictionary/tree/master/tests/test_dotty_custom_types.py)
135
162
 
163
+ ## More Examples
164
+
165
+ More examples can be found in the [examples](https://github.com/01Joseph-Hwang10/dotty-dictionary/tree/master/examples) and [tests](https://github.com/01Joseph-Hwang10/dotty-dictionary/tree/master/tests) directory.
136
166
 
137
167
  ## Contributing
138
168
 
File without changes
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
4
4
 
5
5
  [tool.poetry]
6
6
  name = "dotty-dictionary"
7
- version = "1.2.0"
7
+ version = "1.2.1"
8
8
  description = "Dictionary wrapper that provides dot notation access to nested dictionaries"
9
9
  authors = [
10
10
  "01Joseph-Hwang10 <joseph95501@gmail.com>",