Skip to main content

Attribute dictionary implementation that allow get access to their elements by keys (as native dict) and attributes.

Installation:

pip install attrd

Usage:

    from attrd import AttrDict

    a = AttrDict(key1=123)

    # Set value by attribute
    a.key2 = 123

    # Set value by key
    a['key3'] = 123

    # Set and delete value by attribute
    a.key4 = 123
    del a.key4

    # Set and delete value by key
    a['key5'] = 123
    del a['key5']

    print(a) # -> {'key1': 123, 'key2': 123, 'key3': 123}

Convert existed dict to AttrDict:

    print(AttrDict({'key1': 123, 'key2': 123})) # -> {'key1': 123, 'key2': 123}

    print(AttrDict(**{'key1': 123, 'key2': 123})) # -> {'key1': 123, 'key2': 123}

Nested level:

    d = {
        'key1': {
            'sub_key1': 123,
            'sub_key2': {
                'deep_key': 'abc'
            }
        }
    }

    d = AttrDict(d)
    d.key1.sub_key3 = 123

    print(d.key1) # -> {'sub_key1': 123, 'sub_key2': {'deep_key': 'abc'}, 'sub_key3': 123}
    print(d.key1.sub_key1) # -> 123
    print(d.key1.sub_key2.deep_key) # -> abc

    del d.key1.sub_key2
    print(d) # -> {'key1': {'sub_key1': 123, 'sub_key3': 123}}

Nested values with kwargs:

    d = AttrDict(key1={'sub_key1': 123, 'sub_key2': 123})

    print(d) # -> {'key1': {'sub_key1': 123, 'sub_key2': 123}}
    print(d.key1.sub_key1) # -> 123

    del d.key1.sub_key2
    print(d) # -> {'key1': {'sub_key1': 123}}

Dicts in lists:

    d = AttrDict({
        'key1': [
            {'sub_key1': 123, 'sub_key2': 456},
            {'sub_key1': 123, 'sub_key2': 456},
        ]
    })

    del d.key1[0].sub_key2, d.key1[1].sub_key1
    print(d) # -> {'key1': [{'sub_key1': 123}, {'sub_key2': 456}]}
    print(d.key1[0].sub_key1) # -> 123

Iterate items:

    g = AttrDict(a=1, b=2, c=3, items=[10, 11, 12])

    print(g.items) # -> <built-in method items of AttrDict>
    print(g.get('items')) # -> [10, 11, 12]

    for k, v in g.items():
        print(k, v)

    # a 1
    # b 2
    # c 3

Metadata

Release files for attrd 0.0.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 attrd 0.0.4
File Size Uploaded Provenance Actions
attrd-0.0.4.tar.gz 3.0 kB Without provenance Details for attrd-0.0.4.tar.gz

Built distribution (wheel)

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

Total release size: 5.9 kB

Release files / attrd-0.0.4.tar.gz

Download URL attrd-0.0.4.tar.gz
Size 3.0 kB
Tags Source
SHA-256 checksum
How to use checksums
696921c5e5804852e5958681eaffbcae38abc1ccecd0ffdec0bdfeaed9e47e6b
BLAKE2b-256 checksum
How to use checksums
ea0abd435bf67280f57af9033a52d4c9aca11bf32857aeb7a454e02b3a68d717
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.1

Release files / attrd-0.0.4-py3-none-any.whl

Download URL attrd-0.0.4-py3-none-any.whl
Size 2.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f35f6d2f66fd6d6abd7928873036bcff03b32eca50405d6930e9daa22416320e
BLAKE2b-256 checksum
How to use checksums
40cbb4d4dfb0b7f5dafde8f7a58f222d31a0d412a9e026361c0a83c9ecfce6dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.1

Security for attrd 0.0.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.

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