Skip to main content

ordered, dynamically-expandable dot-access dictionary

Project description

DotMap is a dot-access dict subclass that

  • has dynamic child creation

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

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

m.pprint()
# {'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.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dotmap-1.2.10.tar.gz (5.1 kB view details)

Uploaded Source

File details

Details for the file dotmap-1.2.10.tar.gz.

File metadata

  • Download URL: dotmap-1.2.10.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for dotmap-1.2.10.tar.gz
Algorithm Hash digest
SHA256 ec92f0bf06c7be0de8f1be1601b1bd74b7abf73406c8942922058a12453756dd
MD5 7122506874a2da8b8b9eccbd0dc706f3
BLAKE2b-256 464bd9b746f6736f644351984b12e1697ae1103880af4a1f485962778c52d2be

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page