A dictionary object with attributes support.
Project description
AttributeDict
A dictionary object with attributes support.
Install
Install using pip:
$ pip install attributedict
Use
Example:
from attributedict.collections import AttributeDict
data = AttributeDict({'foo': {'bar': [1, 2, 3]}})
data.foo # => `{'bar': [1, 2, 3]}}`
data.foo.bar # => `[1, 2, 3]`
data.foo = {'baz': True}
data.foo = # => `{'baz': True}`
del data.foo.baz
# and/or...
data = AttributeDict({'foo': {'bar': [1, 2, 3]}})
data['foo'] # => `{'bar': [1, 2, 3]}}`
data['foo']['bar'] # => `[1, 2, 3]`
data['foo'] = {'baz': True}
data['foo'] = # => `{'baz': True}`
del data['foo']['baz']
# instance of `dict`...
isinstance(data, dict) # => True
isinstance(data, attributedict.collections.AttributeDict) # => True
isinstance(data.__dict__, dict) # => True
isinstance(data.__dict__, attributedict.collections.AttributeDict) # => False
# no need for custom encoders...
data = AttributeDict({'foo': {'bar': [1, 2, 3]}})
json.dumps(data) # => `{"foo": {"bar": [1, 2, 3]}}`
json.dumps(data.__dict__) # => `{"foo": {"bar": [1, 2, 3]}}`
# etc.
Test
Clone down source code and run:
$ make install
$ make test
License
Released under the MIT license.
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
attributedict-0.1.3.tar.gz
(2.1 kB
view hashes)
Built Distribution
Close
Hashes for attributedict-0.1.3-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa9cd6f09829850cc581f2df8dc103dfe6e43b7d6912171e8864e874062fd3b8 |
|
MD5 | 1dd174dc296e6dafea6de1544d1dd643 |
|
BLAKE2b-256 | 3b4f71ac8638c9fce0bfa6f0a940c9366a0e73a12c352904d0f33d7573e1b849 |