Python module for interacting with nested dicts as a single level dict with delimited keys.
Project description
FlatDict is a dict object that allows for single level, delimited key/value pair mapping of nested dictionaries. You can interact with FlatDict like a normal dictionary and access child dicts as you normally would or with the composited key.
For example:
foo = {'foo': {'bar': 'baz', 'qux': 'corge'}}
is represented as:
{'foo:bar': 'baz',
'foo:qux': 'corge'}
And can still be accessed as:
foo['foo']['bar']
and
foo['foo:bar']
API
FlatDict has the same methods as dict in Python 2.6. In addition, it has a FlatDict.as_dict method which will return a pure nested dictionary from a FlatDict value.
Documentation is available at http://flatdict.readthedocs.org
Installation
$ pip install flatdict
Example Use
import flatdict
values = {'foo': {'bar': {'baz': 0,
'qux': 1,
'corge': 2},
'grault': {'baz': 3,
'qux': 4,
'corge': 5}},
'garply': {'foo': 0, 'bar': 1, 'baz': 2, 'qux': {'corge': 3}}}
flat = flatdict.FlatDict(values)
print flat['foo:bar:baz']
flat['test:value:key'] = 10
del flat['test']
for key in flat:
print key
for values in flat.itervalues():
print key
print repr(flat.as_dict())
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file flatdict-1.1.1.tar.gz.
File metadata
- Download URL: flatdict-1.1.1.tar.gz
- Upload date:
- Size: 2.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c95955c9d46807afe301437e8bab7d647a8ff5719544f5d4929605da73e41a08
|
|
| MD5 |
38b08d8cec99bcbf6b7275332d93691d
|
|
| BLAKE2b-256 |
4b845f4fa0924be2ce65c705973c5f1fd4892c094e1965eb1643f401fcde20e3
|