https://github.com/grimen/python-attributedict
A dictionary object with attributes support - for Python.
https://github.com/grimen/python-attributedict
attribute attributes custom data dict dictionary object properties property python struct
Last synced: 22 days ago
JSON representation
A dictionary object with attributes support - for Python.
- Host: GitHub
- URL: https://github.com/grimen/python-attributedict
- Owner: grimen
- License: mit
- Created: 2018-06-24T07:20:56.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2020-03-29T13:34:30.000Z (about 5 years ago)
- Last Synced: 2025-04-07T19:51:57.285Z (about 2 months ago)
- Topics: attribute, attributes, custom, data, dict, dictionary, object, properties, property, python, struct
- Language: Python
- Homepage: https://pypi.org/project/attributedict
- Size: 38.1 KB
- Stars: 19
- Watchers: 3
- Forks: 4
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: MIT-LICENSE
Awesome Lists containing this project
README
# `attributedict` [](https://badge.fury.io/py/attributedict) [](https://travis-ci.com/grimen/python-attributedict) [](https://codecov.io/gh/grimen/python-attributedict)
*A dictionary object with attributes support.*
## Install
Install using **pip**:
```sh
$ pip install attributedict
```## Use
Example:
```python
from attributedict.collections import AttributeDictdata = 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) # => Trueisinstance(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:
```sh
$ make install
$ make test
```## License
Released under the MIT license.