attridict


Nameattridict JSON
Version 0.0.9 PyPI version JSON
download
home_pagehttps://github.com/alvinshaita/attridict
SummaryA dict implementation with support for easy and clean access of its values through attributes
upload_time2024-02-22 12:29:43
maintainer
docs_urlNone
authorAlvin Shaita
requires_python
licenseMIT License
keywords attridict attrdict struct dict dot attribute attributes dictionary attr object
VCS
bugtrack_url
requirements PyYAML
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # attridict
![Build Status](https://github.com/alvinshaita/attridict/actions/workflows/attridict.yml/badge.svg?branch=main)
![GitHub](https://img.shields.io/github/license/alvinshaita/attridict.svg)


A Python package implementing atrribute dictionary.

This provides an easier and cleaner way to access dict values using their keys as attributes. It is typically a dict child, maintaining all the dict functionalities, but including some extra features.



## Installation
To install the package from PyPI, use:
```
pip install attridict
```




## Usage

Creating an attridict object
```python
>>> import attridict
>>> att = attridict()
>>> att
{}
>>> att.foo = "bar"
>>> att.foo
'bar'
>>> att
{'foo': 'bar'}
```
<br/>

A dict can be converted into an attridict object by passing it as an argument
```python
>>> import attridict

>>> data = {'red': 'hot', 'blue': 'cold'}

>>> colors = attridict(data)
>>> colors
{'red': 'hot', 'blue': 'cold'}

>>> colors.red
'hot'
```
<br/>

Modifying attridict object
```python
>>> import attridict

>>> data = {'red': 'hot', 'blue': 'cold'}

>>> colors = attridict(data)
>>> colors
{'red': 'hot', 'blue': 'cold'}

>>> colors.blue
'cold'

>>> colors.blue = "sky"
>>> colors.red = "rose"
>>> colors.blue
'sky'
>>> colors.red
'rose'
>>> colors
{'red': 'rose', 'blue': 'sky'}

>>> colors.green = "grass"
>>> colors
{'red': 'rose', 'blue': 'sky', 'green': 'grass'}
```
<br/>

Typical `dict` operations work on attridict objects
```python
>>> import attridict

>>> data = {'red': 'rose', 'blue': 'sky'}

>>> colors = attridict(data)
>>> colors
{'red': 'rose', 'blue': 'sky'}

>>> colors.red
'rose'
>>> colors["red"]
'rose'

>>> colors["red"] = "tomato"
>>> colors["red"]
'tomato'
>>> colors.red
'tomato'
```
<br/>

Nested attribute access
```python
>>> import attridict

>>> data = {'foo': {}}
>>> att = attridict(data)

>>> att
{'foo': {}}

>>> att.foo.bar = 'baz'

>>> att.foo.bar
'baz'

>>> att
{'foo': {'bar': 'baz'}}
```
<br/>

YAML serializable
```python
>>> import attridict
>>> import yaml

>>> data = {'foo': {'bar': 'baz'}}

>>> att = attridict(data)

>>> yaml.dump(att)
'!attridict\nfoo:\n  bar: baz\n'

>>> yaml.safe_dump(att)
'foo:\n  bar: baz\n'
```
## License
The project is MIT licensed

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/alvinshaita/attridict",
    "name": "attridict",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "attridict,attrdict,struct,dict,dot,attribute,attributes,dictionary,attr,object",
    "author": "Alvin Shaita",
    "author_email": "alvinshaita@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/84/6e/244ca3d5a0d10a575caeb907827741dd0c86afe47c45729c07db46f69037/attridict-0.0.9.tar.gz",
    "platform": null,
    "description": "# attridict\n![Build Status](https://github.com/alvinshaita/attridict/actions/workflows/attridict.yml/badge.svg?branch=main)\n![GitHub](https://img.shields.io/github/license/alvinshaita/attridict.svg)\n\n\nA Python package implementing atrribute dictionary.\n\nThis provides an easier and cleaner way to access dict values using their keys as attributes. It is typically a dict child, maintaining all the dict functionalities, but including some extra features.\n\n\n\n## Installation\nTo install the package from PyPI, use:\n```\npip install attridict\n```\n\n\n\n\n## Usage\n\nCreating an attridict object\n```python\n>>> import attridict\n>>> att = attridict()\n>>> att\n{}\n>>> att.foo = \"bar\"\n>>> att.foo\n'bar'\n>>> att\n{'foo': 'bar'}\n```\n<br/>\n\nA dict can be converted into an attridict object by passing it as an argument\n```python\n>>> import attridict\n\n>>> data = {'red': 'hot', 'blue': 'cold'}\n\n>>> colors = attridict(data)\n>>> colors\n{'red': 'hot', 'blue': 'cold'}\n\n>>> colors.red\n'hot'\n```\n<br/>\n\nModifying attridict object\n```python\n>>> import attridict\n\n>>> data = {'red': 'hot', 'blue': 'cold'}\n\n>>> colors = attridict(data)\n>>> colors\n{'red': 'hot', 'blue': 'cold'}\n\n>>> colors.blue\n'cold'\n\n>>> colors.blue = \"sky\"\n>>> colors.red = \"rose\"\n>>> colors.blue\n'sky'\n>>> colors.red\n'rose'\n>>> colors\n{'red': 'rose', 'blue': 'sky'}\n\n>>> colors.green = \"grass\"\n>>> colors\n{'red': 'rose', 'blue': 'sky', 'green': 'grass'}\n```\n<br/>\n\nTypical `dict` operations work on attridict objects\n```python\n>>> import attridict\n\n>>> data = {'red': 'rose', 'blue': 'sky'}\n\n>>> colors = attridict(data)\n>>> colors\n{'red': 'rose', 'blue': 'sky'}\n\n>>> colors.red\n'rose'\n>>> colors[\"red\"]\n'rose'\n\n>>> colors[\"red\"] = \"tomato\"\n>>> colors[\"red\"]\n'tomato'\n>>> colors.red\n'tomato'\n```\n<br/>\n\nNested attribute access\n```python\n>>> import attridict\n\n>>> data = {'foo': {}}\n>>> att = attridict(data)\n\n>>> att\n{'foo': {}}\n\n>>> att.foo.bar = 'baz'\n\n>>> att.foo.bar\n'baz'\n\n>>> att\n{'foo': {'bar': 'baz'}}\n```\n<br/>\n\nYAML serializable\n```python\n>>> import attridict\n>>> import yaml\n\n>>> data = {'foo': {'bar': 'baz'}}\n\n>>> att = attridict(data)\n\n>>> yaml.dump(att)\n'!attridict\\nfoo:\\n  bar: baz\\n'\n\n>>> yaml.safe_dump(att)\n'foo:\\n  bar: baz\\n'\n```\n## License\nThe project is MIT licensed\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "A dict implementation with support for easy and clean access of its values through attributes",
    "version": "0.0.9",
    "project_urls": {
        "Homepage": "https://github.com/alvinshaita/attridict"
    },
    "split_keywords": [
        "attridict",
        "attrdict",
        "struct",
        "dict",
        "dot",
        "attribute",
        "attributes",
        "dictionary",
        "attr",
        "object"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e688356373ef3556e65a495f0adc62177cf435314936cf4187f31e6e1ab97ddf",
                "md5": "68f76a9253a9a8d40ba5bd1f9b21de01",
                "sha256": "a6498b2f4e669105225b759feb2e47af8782fdbdb33610b50dd5d086d1875e49"
            },
            "downloads": -1,
            "filename": "attridict-0.0.9-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "68f76a9253a9a8d40ba5bd1f9b21de01",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 5917,
            "upload_time": "2024-02-22T12:29:41",
            "upload_time_iso_8601": "2024-02-22T12:29:41.986313Z",
            "url": "https://files.pythonhosted.org/packages/e6/88/356373ef3556e65a495f0adc62177cf435314936cf4187f31e6e1ab97ddf/attridict-0.0.9-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "846e244ca3d5a0d10a575caeb907827741dd0c86afe47c45729c07db46f69037",
                "md5": "5703cfd050f894f17f880bef01aae048",
                "sha256": "a0d6b140a17998f32dd71268b3f20a7b74ae5c7d14d628de75cf68f83c61f4ee"
            },
            "downloads": -1,
            "filename": "attridict-0.0.9.tar.gz",
            "has_sig": false,
            "md5_digest": "5703cfd050f894f17f880bef01aae048",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 5364,
            "upload_time": "2024-02-22T12:29:43",
            "upload_time_iso_8601": "2024-02-22T12:29:43.618296Z",
            "url": "https://files.pythonhosted.org/packages/84/6e/244ca3d5a0d10a575caeb907827741dd0c86afe47c45729c07db46f69037/attridict-0.0.9.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-22 12:29:43",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "alvinshaita",
    "github_project": "attridict",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "PyYAML",
            "specs": [
                [
                    "==",
                    "6.0.1"
                ]
            ]
        }
    ],
    "lcname": "attridict"
}
        
Elapsed time: 4.12193s