Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
pip3 install dotmap
Get updates for current installation
pip3 install --upgrade dotmap
DotMap
is a dot-access dict
subclass that
dict
dict
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.
FAQs
ordered, dynamically-expandable dot-access dictionary
We found that dotmap demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.