Skip to main content

Attribute-access ordered dictionary

Project description

PyPI version DOI Build Status codecov


An attribute-access ordered dictionary

atdict is an attribute-access ordered dictionary. You can use a key name as an attribute to access the value of the dictionary for a key, for example, o.key_name rather than o['key_name']. Only a minimum set of methods are implemented so as to minimize the chances of name conflicts.

atdict was originally developed in 2017 as the class Object, in scribblers, which represented event objects in alphatwirl. It was released as an independent package in 2019 as atdict.


  • Python 2.7, 3.6, or 3.7


You can install with pip.

$ pip install -U atdict

How to use

Import atdict

Import atdict from the package atdict.

from atdict import atdict

Initialize atdict

You can initialize an atdict with any arguments that can initialize collections.OrderedDict.

For example:

o1 = atdict([('foo', 40), ('bar', 'ham')])

It will print.

atdict(foo=40, bar='ham')

An atdict can be also initialized with another atdict.

o2 = atdict(o1)

The o2 is initialized with a (shallow) copy of the contents of o1.

atdict(foo=40, bar='ham')

Access to a value

Yon can use a key name as an attribute of atdict.


This will print the value for the key foo, which is 40.


Modify a value

To modify a value, you can assign a new value to the attribute. = 50
atdict(foo=50, bar='ham')

The value for the key foo changed from 40 to 50.

Add a key

To add a key, you can also assign a value to the attribute

o1.baz = 'eggs'
atdict(foo=50, bar='ham', baz='eggs')

Delete a key

del deletes a key.

atdict(foo=50, baz='eggs')

Copy and deepcopy

A copy will be created if atdict is initialized with another atdict. However, this will be a shallow copy.

l = [1, 2]
o1 = atdict([('foo', l)])
o2 = atdict(o1)
print( is

To make a deep copy, you can use copy.deepcopy().

import copy
l = [1, 2]
o1 = atdict([('foo', l)])
o2 = copy.deepcopy(o1)
atdict(foo=[1, 2]) and are not the same object.

print( is


An atdict is picklable as long as all values are picklable.

import pickle
o1 = atdict([('foo', 40), ('bar', 'ham')])
p1 = pickle.dumps(o1)
o2 = pickle.loads(p1)
atdict(foo=40, bar='ham')


  • atdict is licensed under the BSD license.


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 atdict, version 0.9.3
Filename, size File type Python version Upload date Hashes
Filename, size atdict-0.9.3-py2.py3-none-any.whl (5.2 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size atdict-0.9.3.tar.gz (20.6 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page