Skip to main content

SickDict - An IDE-friendly python dictionary

Project description

SickDict

An IDE friendly (auto-completion) python dictionary with dot-accessible attributes.

Why?

  • The pythonic way to access the dictionary d['key'] is prone to errors and honestly, pretty ugly.
  • The case becomes worse when the dictionary is a nested one d['key1]['key2']. Now obviously d.key1.key2.key3 is much better.
  • Default python dictionary does not support auto-completion in almost all the IDE's, but SickDict will.

How to use it?

  1. Install the package:
pip install sick-dict
  1. Import the package:
from sick_dict import SickDict

Features

  1. Create a dictionary without defining it keys beforehand
sd = SickDict()
sd.hello = "world"
  1. Pass a dictionary and all the keys in dictionary will become properties
d = {'hello': 'world'}
sd = SickDict(d)
print(sd.hello)     # world
  1. Pass keyword arguments and all the arguments will become properties
sd = SickDict(hello="world", this_is="awesome")
print(sd.hello)     # world
print(sd.this_is)     # awesome
  1. Pass both dictionary and keyword arguments
d = {'hello': 'world'}
sd = SickDict(d, this_is="awesome")
print(sd.hello)     # world
print(sd.this_is)     # awesome
  1. Pass a nested dictionary with a list
foo = {
    "bar" : {
        "baz" : [{"boo" : "hoo"}, {"baba" : "loo"}]
    }
}
sd = SickDict(foo)
print(sd.bar.baz[0].boo)     # hoo
  1. Use del keyword to remove a key
sd = SickDict(hello="world", this_is="awesome")
del sd.hello
print(sd.hello)     # Key
  1. Use + operator to combine two instances of SickDict
sd1 = SickDict(hello="world")
print(sd1)      # SickDict({'hello': 'world'})

sd2 = SickDict(this_is="awesome")
print(sd2)      # SickDict({'this_is': 'awesome'})

print(sd1 + sd2)    # SickDict({'hello': 'world', 'this_is': 'awesome'})
  1. Use other dictionary functions like get(), update() etc.
sd = SickDict(hello="world")
print(sd.get('hello'))     # world

sd.update({'who_are_you': 'developer'}, this_is="awesome")
print(sd)      # SickDict({'hello': 'world', 'who_are_you': 'developer', 'this_is': 'awesome'})

Project details


Download files

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

Source Distribution

sick-dict-0.2.tar.gz (3.6 kB view hashes)

Uploaded Source

Supported by

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