MCPcopy Index your code
hub / github.com/drgrib/dotmap

github.com/drgrib/dotmap @1.3.8

Chat with this repo
repository ↗ · DeepWiki ↗ · release 1.3.8 ↗ · + Follow
118 symbols 275 edges 4 files 0 documented · 0% 1 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

DotMap

Build Status

DotMap is a dot-access dict subclass that * has dynamic hierarchy 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')

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.

A note on unpacking (using the ** operator)

Unpacking DotMap can be done like this

m = DotMap()
m.a = 1
simple_unpack = dict(**m.toDict())
print(simple_unpack)
# {'a': 1}

I've given multiple tries to getting the syntax to work with just **m and it's just not worth the effort when the workaround is this simple. If you can figure out a way to fully ace the dict subclass this way and still keep all the unit tests functioning, submit a PR and I'll be happy to review.

Core symbols most depended-on inside this repo

toDict
called by 11
dotmap/__init__.py
items
called by 8
dotmap/__init__.py
empty
called by 8
dotmap/__init__.py
parseOther
called by 7
dotmap/__init__.py
get
called by 6
dotmap/__init__.py
update
called by 5
dotmap/__init__.py
iteritems
called by 4
dotmap/__init__.py
copy
called by 4
dotmap/__init__.py

Shape

Method 98
Class 18
Function 2

Languages

Python100%

Modules by API surface

dotmap/__init__.py66 symbols
dotmap/test.py52 symbols

Used by 1 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add dotmap \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact