Skip to main content

attridict

Build Status GitHub

A Python package implementing atrribute dictionary.

This provides an easier and cleaner way to access dict values using their keys as attributes. It is typically a dict child, maintaining all the dict functionalities, but including some extra features.

Installation

To install the package from PyPI, use:

pip install attridict

Usage

Creating an attridict object

>>> import attridict
>>> att = attridict()
>>> att
{}
>>> att.foo = "bar"
>>> att.foo
'bar'
>>> att
{'foo': 'bar'}

A dict can be converted into an attridict object by passing it as an argument

>>> import attridict

>>> data = {'red': 'hot', 'blue': 'cold'}

>>> colors = attridict(data)
>>> colors
{'red': 'hot', 'blue': 'cold'}

>>> colors.red
'hot'

Modifying attridict object

>>> import attridict

>>> data = {'red': 'hot', 'blue': 'cold'}

>>> colors = attridict(data)
>>> colors
{'red': 'hot', 'blue': 'cold'}

>>> colors.blue
'cold'

>>> colors.blue = "sky"
>>> colors.red = "rose"
>>> colors.blue
'sky'
>>> colors.red
'rose'
>>> colors
{'red': 'rose', 'blue': 'sky'}

>>> colors.green = "grass"
>>> colors
{'red': 'rose', 'blue': 'sky', 'green': 'grass'}

Typical dict operations work on attridict objects

>>> import attridict

>>> data = {'red': 'rose', 'blue': 'sky'}

>>> colors = attridict(data)
>>> colors
{'red': 'rose', 'blue': 'sky'}

>>> colors.red
'rose'
>>> colors["red"]
'rose'

>>> colors["red"] = "tomato"
>>> colors["red"]
'tomato'
>>> colors.red
'tomato'

Nested attribute access

>>> import attridict

>>> data = {'foo': {}}
>>> att = attridict(data)

>>> att
{'foo': {}}

>>> att.foo.bar = 'baz'

>>> att.foo.bar
'baz'

>>> att
{'foo': {'bar': 'baz'}}

YAML serializable

>>> import attridict
>>> import yaml

>>> data = {'foo': {'bar': 'baz'}}

>>> att = attridict(data)

>>> yaml.dump(att)
'!attridict\nfoo:\n  bar: baz\n'

>>> yaml.safe_dump(att)
'foo:\n  bar: baz\n'

License

The project is MIT licensed

Metadata

Release files for attridict 0.0.9

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

Source distribution (sdist)

Source distribution for attridict 0.0.9
File Size Uploaded Provenance Actions
attridict-0.0.9.tar.gz 5.4 kB Without provenance Details for attridict-0.0.9.tar.gz

Built distribution (wheel)

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

Total release size: 11.3 kB

Release files / attridict-0.0.9.tar.gz

Download URL attridict-0.0.9.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
a0d6b140a17998f32dd71268b3f20a7b74ae5c7d14d628de75cf68f83c61f4ee
BLAKE2b-256 checksum
How to use checksums
846e244ca3d5a0d10a575caeb907827741dd0c86afe47c45729c07db46f69037
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release files / attridict-0.0.9-py3-none-any.whl

Download URL attridict-0.0.9-py3-none-any.whl
Size 5.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a6498b2f4e669105225b759feb2e47af8782fdbdb33610b50dd5d086d1875e49
BLAKE2b-256 checksum
How to use checksums
e688356373ef3556e65a495f0adc62177cf435314936cf4187f31e6e1ab97ddf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Security for attridict 0.0.9

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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