dotmap 1.3.30


pip install dotmap

  Latest version

Released: Apr 06, 2022

Project Links

Meta
Author: Chris Redford

Classifiers

DotMap

Build Status

Donate

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

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

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))

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

And key initialization

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

You can initialize it from dict and convert it to dict

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

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

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

And automatic addition initializations of any other type

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

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.

1.3.30 Apr 06, 2022
1.3.29 Apr 04, 2022
1.3.28 Apr 04, 2022
1.3.27 Apr 01, 2022
1.3.26 Dec 10, 2021
1.3.25 Oct 26, 2021
1.3.24 Jul 29, 2021
1.3.23 Oct 27, 2020
1.3.22 Oct 11, 2020
1.3.21 Oct 11, 2020
1.3.20 Oct 11, 2020
1.3.19 Oct 11, 2020
1.3.17 Jun 04, 2020
1.3.16 Jun 04, 2020
1.3.14 Apr 28, 2020
1.3.13 Feb 11, 2020
1.3.12 Feb 11, 2020
1.3.8 Mar 10, 2019
1.3.7 Mar 10, 2019
1.3.4 Nov 23, 2018
1.3.3 Nov 12, 2018
1.3.2 Nov 12, 2018
1.3.1 Nov 12, 2018
1.3.0 Nov 12, 2018
1.2.39 Sep 30, 2018
1.2.38 Sep 30, 2018
1.2.37 Sep 30, 2018
1.2.36 Sep 30, 2018
1.2.35 Sep 30, 2018
1.2.34 Sep 30, 2018
1.2.33 Sep 30, 2018
1.2.32 Sep 30, 2018
1.2.31 Sep 30, 2018
1.2.30 Sep 30, 2018
1.2.29 Sep 30, 2018
1.2.28 Sep 30, 2018
1.2.27 Sep 29, 2018
1.2.26 Sep 29, 2018
1.2.25 Sep 29, 2018
1.2.24 Sep 28, 2018
1.2.23 Sep 30, 2018
1.2.22 Sep 30, 2018
1.2.21 Sep 30, 2018
1.2.20 Sep 20, 2017
1.2.19 Aug 24, 2017
1.2.18 Sep 30, 2018
1.2.17 Mar 17, 2017
1.2.16 Mar 05, 2017
1.2.15 Jan 19, 2017
1.2.14 Dec 24, 2016
1.2.13 Dec 22, 2016
1.2.12 Dec 21, 2016
1.2.11 Dec 21, 2016
1.2.10 Dec 21, 2016
1.2.9 Dec 21, 2016
1.2.8 Dec 05, 2016
1.2.7 Oct 31, 2016
1.2.6 Oct 29, 2016
1.2.5 Oct 07, 2016
1.2.4 Sep 14, 2016
1.2.3 Aug 25, 2016
1.2.2 Aug 25, 2016
1.2.1 Aug 25, 2016
1.2.0 Jul 15, 2016
1.1.22 Jul 15, 2016
1.1.21 Jul 14, 2016
1.1.20 Jul 14, 2016
1.1.19 Jul 12, 2016
1.1.18 Jul 06, 2016
1.1.17 Jul 06, 2016
1.1.16 May 16, 2016
1.1.15 May 16, 2016
1.1.14 May 16, 2016
1.1.2 Sep 17, 2015
1.1.1 Aug 27, 2015
1.0.16 Aug 26, 2015
1.0.15 Aug 24, 2015
1.0.14 Aug 24, 2015
1.0.13 Aug 21, 2015
1.0.12 Sep 30, 2018
1.0.10 Aug 12, 2015
1.0.9 Aug 12, 2015
1.0.8 Aug 12, 2015
1.0.7 Aug 12, 2015
1.0.6 Aug 12, 2015
1.0.5 Aug 12, 2015
1.0.4 Aug 12, 2015
1.0.3 Aug 12, 2015
1.0.2 Aug 12, 2015
1.0.1 Aug 12, 2015
1.0 Aug 12, 2015

Wheel compatibility matrix

Platform Python 3
any

Files in release

No dependencies