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.5.tar.gz
(8.0 kB
view hashes)
Built Distribution
Close
Hashes for attributedict-0.1.5-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb9599c4fd91f8d529c17c8f69bc2f9321bdb5f8cbf1c7a88984cab5ed816c6e |
|
MD5 | b1aa9fbb4ed1ed79d7b0724c84b91f19 |
|
BLAKE2b-256 | 50f84e959fefff3234f8668fd79f8f9d90d677d92af7b93701650331d82f702d |