Skip to main content

simple class that merge dictionary and object API

Project description

simple python class that merges dictionary and object APIs

Those Namespace objects work in a similar way as javascript objects. intended to help deadling with deep json objects, and save you a lot of [‘’] in your code


from dictns import Namespace
n = Namespace(dict(a=1, b=3, c=dict(d=4)))
assert(n['a'] == n.a)
assert(n['c']['d'] == n.c.d)

you can wrap dicts and lists inside Namespace

n = Namespace([dict(a=1, b=3, c=[dict(d=4)])])
assert(n[0]['a'] == n[0].a)
assert(n[0]['c'][0]['d'] == n[0].c[0].d)

you can also wrap dict subclasses like OrderedDict, but the resulting Namespace does not inherit original object characteristics (i.e. order in OrderedDict)

see unit tests for more usage examples


  • 1.0: Initial version
  • 1.1: Added Namespace comparaison tools
  • 1.2: Namespace now support dict and list subclasses as input
  • 1.3:
    • Fix for compatibility with getattr() built-in method. When an invalid key is requested, it now raises an AttributeError instead of a KeyError.
    • Allow initialization without arg: Namespace() is equivalent to Namespace({}).
  • 1.4: Allow Namespace objects to be weak referenced
  • 1.5:
    • Fix tests for 3.5 and pypy
    • Readme cleanups


Launch unit tests:

python test/

Project details

Download files

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

Files for dictns, version 1.5
Filename, size File type Python version Upload date Hashes
Filename, size dictns-1.5-py2.py3-none-any.whl (5.5 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size dictns-1.5.tar.gz (5.2 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page