Metadata-Version: 2.1
Name: nested_dicts
Version: 0.0.0
Summary: Self-nesting list-keyed dicts, multiple-defaults dicts, and TOML-style Array of Tables lists/dicts. 
Project-URL: Homepage, https://github.com/JamesParrott/Nested_dicts
Project-URL: Bug Tracker, https://github.com/JamesParrott/Nested_dicts/issues
Author-email: James Parrott <james.parrott@proton.me>
License: MIT License
        
        Copyright (c) 2023 James Parrott
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.7
Provides-Extra: tests
Requires-Dist: pytest; extra == 'tests'
Description-Content-Type: text/markdown

# Nested Dicts

Python multiple-default dicts, list-keyed dicts, dotted-key dicts and Arrays of Tables classes.

*pip install nested_dicts*


## Examples

### DefaultsDictABC
Implement the choose_factory method on a subclass 
to select a factory.  The returned factory is itself 
called with the key value (unlike collections.defaultdict.__missing__)

*The following 4 examples all define a dictionary subclass `d` for which
`d == {'k': {'sub_dict_key': 'v'}}` is True.*

### NestedDefaultsDict
```
>>> d = NestedDefaultsDict()
>>> d['k']['sub_dict_key'] = 'v'
```

### ListKeyedDict
```
>>> d = ListKeyedDict.from_nested_dict({'k': {'sub_dict_key': 'v'}})
>>> d[['k', 'sub_dict_key']]
'v'
```

### ListKeyedNestedDefaultsDict
```
>>> d = ListKeyedNestedDefaultsDict()
>>> d[['k', 'sub_dict_key']] = 'v'
```

### DottedKeyedNestedDefaultsDict
```
>>> d = DottedKeyedNestedDefaultsDict()
>>> d['k.sub_dict_key'] = 'v'
```

### [TOMLTable](https://toml.io/en/v1.0.0#table)
```
>>> from nested_dicts import TOMLTable
>>> t = TOMLTable()
>>> t['table-1'].update(
... key1 = "some string",
... key2 = 123)

>>> t['table-2'].update(
... key1 = "another string",
... key2 = 456)
>>> t
{'table-1': {'key1': 'some string', 'key2': 123}, 'table-2': {'key1': 'another string', 'key2': 456}}
```

Values in TOMLTable()s indexed with lists behave like [Arrays of Tables](https://toml.io/en/v1.0.0#array-of-tables),
even when only read
```
>>> from nested_dicts import TOMLTable
>>> t = TOMLTable()
>>> t[['products']].update(
name = "Hammer",
sku = 738594937
)

>>> t[['products']]  # empty table within the array
{}
>>> t[['products']].update(
name = "Nail",
sku = 284758393,

color = "gray"
)


>>> t
{'products': [{'name': 'Hammer', 'sku': 738594937}, {}, {'name': 'Nail', 'sku': 284758393, 'color': 'gray'}]}
```
