Skip to main content

PyPI version Anaconda-Server Badge DOI Test Status codecov

atdict

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.



Requirement

  • Python 3.6, 3.7, 3.8, or 3.9

Install

You can install with conda from conda-forge:

conda install -c conda-forge atdict

or 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')])
print(o1)

It will print.

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

An atdict can be also initialized with another atdict.

o2 = atdict(o1)
print(o2)

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.

print(o1.foo)

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

40

Modify a value

To modify a value, you can assign a new value to the attribute.

o1.foo = 50
print(o1)
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'
print(o1)
atdict(foo=50, bar='ham', baz='eggs')

Delete a key

del deletes a key.

del o1.bar
print(o1)
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(o2.foo is o1.foo)
True

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

import copy
l = [1, 2]
o1 = atdict([('foo', l)])
o2 = copy.deepcopy(o1)
print(o2)
atdict(foo=[1, 2])

o2.foo and o1.foo are not the same object.

print(o2.foo is o1.foo)
False

Pickle

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)
print(o2)
atdict(foo=40, bar='ham')

License

  • atdict is licensed under the BSD license.

Contact

Metadata

Release files for atdict 0.9.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for atdict 0.9.4
File Size Uploaded Provenance
atdict-0.9.4.tar.gz 21.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for atdict 0.9.4
File Interpreter ABI Platform
atdict-0.9.4-py3-none-any.whl Python 3 none any Details

Total release size: 26.7 kB

Release files / atdict-0.9.4.tar.gz

Download URL atdict-0.9.4.tar.gz
Size 21.3 kB
Tags Source
SHA-256 checksum
How to use checksums
52fa9afbd80cd66baf20b8a8f22995ca7579f1255cbc22a66a38c2aa91fbb39c
BLAKE2b-256 checksum
How to use checksums
6181300e1b4adf35477483452f4d6eae2419e6e2198549132a1d637dfc5fa998
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5

Release files / atdict-0.9.4-py3-none-any.whl

Download URL atdict-0.9.4-py3-none-any.whl
Size 5.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a8521b2257ad5fca4a4e0f2e0eaa222684f69b91facc8ca5a98ff561a8a358f5
BLAKE2b-256 checksum
How to use checksums
aadbfb55b27dcc912c7b556e6333648a1ad914d155fa8a9219e81173eb922ecf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5

Security for atdict 0.9.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page