dotmap


Namedotmap JSON
Version 1.3.30 PyPI version JSON
download
home_pagehttps://github.com/drgrib/dotmap
Summaryordered, dynamically-expandable dot-access dictionary
upload_time2022-04-06 16:26:49
maintainer
docs_urlNone
authorChris Redford
requires_python
licenseMIT
keywords dict dot map order ordered ordereddict access dynamic
VCS
bugtrack_url
requirements pytest
Travis-CI
coveralls test coverage No coveralls.
            # DotMap

[![Build Status](https://travis-ci.com/drgrib/dotmap.svg?branch=master)](https://travis-ci.com/drgrib/dotmap)

[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/donate?business=N2GLXLS5KBFBY&item_name=Chris+Redford&currency_code=USD)

# Install

```
pip3 install dotmap
```

## Upgrade

Get updates for current installation

```
pip3 install --upgrade dotmap
```

# Features

`DotMap` is a dot-access `dict` subclass that

-   has dynamic hierarchy creation (autovivification)
-   can be initialized with keys
-   easily initializes from `dict`
-   easily converts to `dict`
-   is ordered by insertion

The key feature is exactly what you want: dot-access

```python
from dotmap import DotMap
m = DotMap()
m.name = 'Joe'
print('Hello ' + m.name)
# Hello Joe
```

However, `DotMap` is a `dict` and you can treat it like a `dict` as needed

```python
print(m['name'])
# Joe
m.name += ' Smith'
m['name'] += ' Jr'
print(m.name)
# Joe Smith Jr
```

It also has fast, automatic hierarchy (which can be deactivated by initializing with `DotMap(_dynamic=False)`)

```python
m = DotMap()
m.people.steve.age = 31
```

And key initialization

```python
m = DotMap(a=1, b=2)
```

You can initialize it from `dict` and convert it to `dict`

```python
d = {'a':1, 'b':2}

m = DotMap(d)
print(m)
# DotMap(a=1, b=2)

print(m.toDict())
# {'a': 1, 'b': 2}
```

And it has iteration that is ordered by insertion

```python
m = DotMap()

m.people.john.age = 32
m.people.john.job = 'programmer'
m.people.mary.age = 24
m.people.mary.job = 'designer'
m.people.dave.age = 55
m.people.dave.job = 'manager'

for k, v in m.people.items():
	print(k, v)
print

# john DotMap(age=32, job='programmer')
# mary DotMap(age=24, job='designer')
# dave DotMap(age=55, job='manager')
```

It also has automatic counter initialization

```python
m = DotMap()
for i in range(7):
	m.counter += 1
print(m.counter)
# 7
```

And automatic addition initializations of any other type

```python
m = DotMap()
m.quote += 'lions'
m.quote += ' and tigers'
m.quote += ' and bears'
m.quote += ', oh my'
print(m.quote)
# lions and tigers and bears, oh my
```

There is also built-in `pprint` as `dict` or `json` for debugging a large `DotMap`

```python
m.pprint()
# {'people': {'dave': {'age': 55, 'job': 'manager'},
#             'john': {'age': 32, 'job': 'programmer'},
#             'mary': {'age': 24, 'job': 'designer'}}}
m.pprint(pformat='json')
# {
#     "people": {
#         "dave": {
#	      "age": 55,
#	      "job": "manager"
# 	  },
# 	  "john": {
#	      "age": 32,
#	      "job": "programmer"
# 	  },
# 	  "mary": {
#	      "age": 24,
#	      "job": "designer"
# 	  }
#     }
# }
```

And many other features involving dots and dictionaries that will be immediately intuitive when used.



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/drgrib/dotmap",
    "name": "dotmap",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "dict,dot,map,order,ordered,ordereddict,access,dynamic",
    "author": "Chris Redford",
    "author_email": "credford@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/bc/68/c186606e4f2bf731abd18044ea201e70c3c244bf468f41368820d197fca5/dotmap-1.3.30.tar.gz",
    "platform": null,
    "description": "# DotMap\n\n[![Build Status](https://travis-ci.com/drgrib/dotmap.svg?branch=master)](https://travis-ci.com/drgrib/dotmap)\n\n[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/donate?business=N2GLXLS5KBFBY&item_name=Chris+Redford&currency_code=USD)\n\n# Install\n\n```\npip3 install dotmap\n```\n\n## Upgrade\n\nGet updates for current installation\n\n```\npip3 install --upgrade dotmap\n```\n\n# Features\n\n`DotMap` is a dot-access `dict` subclass that\n\n-   has dynamic hierarchy creation (autovivification)\n-   can be initialized with keys\n-   easily initializes from `dict`\n-   easily converts to `dict`\n-   is ordered by insertion\n\nThe key feature is exactly what you want: dot-access\n\n```python\nfrom dotmap import DotMap\nm = DotMap()\nm.name = 'Joe'\nprint('Hello ' + m.name)\n# Hello Joe\n```\n\nHowever, `DotMap` is a `dict` and you can treat it like a `dict` as needed\n\n```python\nprint(m['name'])\n# Joe\nm.name += ' Smith'\nm['name'] += ' Jr'\nprint(m.name)\n# Joe Smith Jr\n```\n\nIt also has fast, automatic hierarchy (which can be deactivated by initializing with `DotMap(_dynamic=False)`)\n\n```python\nm = DotMap()\nm.people.steve.age = 31\n```\n\nAnd key initialization\n\n```python\nm = DotMap(a=1, b=2)\n```\n\nYou can initialize it from `dict` and convert it to `dict`\n\n```python\nd = {'a':1, 'b':2}\n\nm = DotMap(d)\nprint(m)\n# DotMap(a=1, b=2)\n\nprint(m.toDict())\n# {'a': 1, 'b': 2}\n```\n\nAnd it has iteration that is ordered by insertion\n\n```python\nm = DotMap()\n\nm.people.john.age = 32\nm.people.john.job = 'programmer'\nm.people.mary.age = 24\nm.people.mary.job = 'designer'\nm.people.dave.age = 55\nm.people.dave.job = 'manager'\n\nfor k, v in m.people.items():\n\tprint(k, v)\nprint\n\n# john DotMap(age=32, job='programmer')\n# mary DotMap(age=24, job='designer')\n# dave DotMap(age=55, job='manager')\n```\n\nIt also has automatic counter initialization\n\n```python\nm = DotMap()\nfor i in range(7):\n\tm.counter += 1\nprint(m.counter)\n# 7\n```\n\nAnd automatic addition initializations of any other type\n\n```python\nm = DotMap()\nm.quote += 'lions'\nm.quote += ' and tigers'\nm.quote += ' and bears'\nm.quote += ', oh my'\nprint(m.quote)\n# lions and tigers and bears, oh my\n```\n\nThere is also built-in `pprint` as `dict` or `json` for debugging a large `DotMap`\n\n```python\nm.pprint()\n# {'people': {'dave': {'age': 55, 'job': 'manager'},\n#             'john': {'age': 32, 'job': 'programmer'},\n#             'mary': {'age': 24, 'job': 'designer'}}}\nm.pprint(pformat='json')\n# {\n#     \"people\": {\n#         \"dave\": {\n#\t      \"age\": 55,\n#\t      \"job\": \"manager\"\n# \t  },\n# \t  \"john\": {\n#\t      \"age\": 32,\n#\t      \"job\": \"programmer\"\n# \t  },\n# \t  \"mary\": {\n#\t      \"age\": 24,\n#\t      \"job\": \"designer\"\n# \t  }\n#     }\n# }\n```\n\nAnd many other features involving dots and dictionaries that will be immediately intuitive when used.\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "ordered, dynamically-expandable dot-access dictionary",
    "version": "1.3.30",
    "split_keywords": [
        "dict",
        "dot",
        "map",
        "order",
        "ordered",
        "ordereddict",
        "access",
        "dynamic"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "6ec8546fc804658647549ab9700b895f",
                "sha256": "bd9fa15286ea2ad899a4d1dc2445ed85a1ae884a42effb87c89a6ecce71243c6"
            },
            "downloads": -1,
            "filename": "dotmap-1.3.30-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6ec8546fc804658647549ab9700b895f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 11464,
            "upload_time": "2022-04-06T16:26:47",
            "upload_time_iso_8601": "2022-04-06T16:26:47.103467Z",
            "url": "https://files.pythonhosted.org/packages/4d/f9/976d6813c160d6c89196d81e9466dca1503d20e609d8751f3536daf37ec6/dotmap-1.3.30-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "7c9ca326427eb42ff3680740814e06db",
                "sha256": "5821a7933f075fb47563417c0e92e0b7c031158b4c9a6a7e56163479b658b368"
            },
            "downloads": -1,
            "filename": "dotmap-1.3.30.tar.gz",
            "has_sig": false,
            "md5_digest": "7c9ca326427eb42ff3680740814e06db",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 12391,
            "upload_time": "2022-04-06T16:26:49",
            "upload_time_iso_8601": "2022-04-06T16:26:49.211470Z",
            "url": "https://files.pythonhosted.org/packages/bc/68/c186606e4f2bf731abd18044ea201e70c3c244bf468f41368820d197fca5/dotmap-1.3.30.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-04-06 16:26:49",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "drgrib",
    "github_project": "dotmap",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "pytest",
            "specs": [
                [
                    "==",
                    "6.1.2"
                ]
            ]
        }
    ],
    "lcname": "dotmap"
}
        
Elapsed time: 0.01443s