attrify


Nameattrify JSON
Version 3.0 PyPI version JSON
download
home_pagehttps://github.com/DragSama/attrify
SummaryConvert dict to access dict keys as attributes.
upload_time2021-01-06 07:17:34
maintainer
docs_urlNone
authorDragSama
requires_python>=3.6
licenseMIT
keywords dict python3 attrify attributes
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Attrify
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/1daae9072d214d199f95c53c8fe16d05)](https://www.codacy.com/gh/DragSama/Attrify/dashboard?utm_source=github.com&utm_medium=referral&utm_content=DragSama/Attrify&utm_campaign=Badge_Grade)
[![PyPI Download Stats](https://img.shields.io/pypi/dd/attrify)](https://pypi.org/project/attrify/)
[![PyPI Version](https://img.shields.io/pypi/v/attrify?color=brightgreen)](https://pypi.org/project/attrify/)
[![Code style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

**Access python dict keys as attributes**

## Installation

- Install using pip: `pip install attrify`


## Examples

-  Convert normal dict
```python
from attrify import Attrify

normal_dict = {'name': 'Cool'}
attrified_dict = Attrify(normal_dict)
# or
attrified_dict = Attrify(**normal_dict)

assert attrified_dict['name'] == attrified_dict.name
```
-  Convert complex nested dict
```python
complex_nested_normal_dict = {"data": {"results": [{"name": "something"}, {"name": "anything"}]}}
complex_nested_attrified_dict = Attrify(complex_nested_normal_dict)
# or
complex_nested_attrified_dict = Attrify(**complex_nested_normal_dict)

assert complex_nested_attrified_dict.data.results[0].name == complex_nested_normal_dict['data']['results'][0]['name']
```
-  Convert back to dict
```python
normal_dict = {'name': 'Cool'}
attrified_dict = Attrify(normal_dict)
assert type(attrified_dict.to_dict()) == type(normal_dict)
```
-  Keys inside dir: **Will only contain with alphabetic keys, To see which keys are considered alphabetic see `help(str.isalpha)`**
```python
attrified_dict = Attrify({'name': 'Cool'})
print(dir(attrified_dict)) # List return will contain the key 'name'.
```
-  There is also a shortcut method to prettify dict, Just calls json.dumps with some args set.
```python
print(complex_nested_attrified_dict.prettify())
```
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/DragSama/attrify",
    "name": "attrify",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "dict python3 attrify attributes",
    "author": "DragSama",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/9e/76/6b6fb6309d56b7547e8368e378877e34f8f006ae3769a3109e9fe46eee4a/attrify-3.0.tar.gz",
    "platform": "",
    "description": "# Attrify\n[![Codacy Badge](https://app.codacy.com/project/badge/Grade/1daae9072d214d199f95c53c8fe16d05)](https://www.codacy.com/gh/DragSama/Attrify/dashboard?utm_source=github.com&utm_medium=referral&utm_content=DragSama/Attrify&utm_campaign=Badge_Grade)\n[![PyPI Download Stats](https://img.shields.io/pypi/dd/attrify)](https://pypi.org/project/attrify/)\n[![PyPI Version](https://img.shields.io/pypi/v/attrify?color=brightgreen)](https://pypi.org/project/attrify/)\n[![Code style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n\n**Access python dict keys as attributes**\n\n## Installation\n\n- Install using pip: `pip install attrify`\n\n\n## Examples\n\n-  Convert normal dict\n```python\nfrom attrify import Attrify\n\nnormal_dict = {'name': 'Cool'}\nattrified_dict = Attrify(normal_dict)\n# or\nattrified_dict = Attrify(**normal_dict)\n\nassert attrified_dict['name'] == attrified_dict.name\n```\n-  Convert complex nested dict\n```python\ncomplex_nested_normal_dict = {\"data\": {\"results\": [{\"name\": \"something\"}, {\"name\": \"anything\"}]}}\ncomplex_nested_attrified_dict = Attrify(complex_nested_normal_dict)\n# or\ncomplex_nested_attrified_dict = Attrify(**complex_nested_normal_dict)\n\nassert complex_nested_attrified_dict.data.results[0].name == complex_nested_normal_dict['data']['results'][0]['name']\n```\n-  Convert back to dict\n```python\nnormal_dict = {'name': 'Cool'}\nattrified_dict = Attrify(normal_dict)\nassert type(attrified_dict.to_dict()) == type(normal_dict)\n```\n-  Keys inside dir: **Will only contain with alphabetic keys, To see which keys are considered alphabetic see `help(str.isalpha)`**\n```python\nattrified_dict = Attrify({'name': 'Cool'})\nprint(dir(attrified_dict)) # List return will contain the key 'name'.\n```\n-  There is also a shortcut method to prettify dict, Just calls json.dumps with some args set.\n```python\nprint(complex_nested_attrified_dict.prettify())\n```",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Convert dict to access dict keys as attributes.",
    "version": "3.0",
    "project_urls": {
        "Homepage": "https://github.com/DragSama/attrify"
    },
    "split_keywords": [
        "dict",
        "python3",
        "attrify",
        "attributes"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9e766b6fb6309d56b7547e8368e378877e34f8f006ae3769a3109e9fe46eee4a",
                "md5": "1a3f768d9e61a5523099e3e4f1355e3b",
                "sha256": "3446ac32140c6a4ad2a5d6fc4a9aa42c7f1cc3f4b9ff916fef88dc27fcfe3cd3"
            },
            "downloads": -1,
            "filename": "attrify-3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "1a3f768d9e61a5523099e3e4f1355e3b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 4033,
            "upload_time": "2021-01-06T07:17:34",
            "upload_time_iso_8601": "2021-01-06T07:17:34.410833Z",
            "url": "https://files.pythonhosted.org/packages/9e/76/6b6fb6309d56b7547e8368e378877e34f8f006ae3769a3109e9fe46eee4a/attrify-3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-01-06 07:17:34",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "DragSama",
    "github_project": "attrify",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "attrify"
}
        
Elapsed time: 0.10341s