Metadata-Version: 2.1
Name: dictdot
Version: 1.3.0
Summary: Python dict accessible by dot.
Home-page: https://github.com/nchz/dictdot
Author: nchz
License: UNKNOWN
Platform: UNKNOWN
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE

Python dict accessible by dot.

Usage:

    from dictdot import dictdot

    d = dictdot()

    d["a"] = 1
    assert d["a"] == d.a

    d.b = 2
    assert d["b"] == d.b

    # builtin attributes are not overriden.
    d.items = "foo"
    assert d.items != d["items"]
    assert hasattr(d.items, "__call__")

    # d["NA"] will raise KeyError, but
    assert d.NA is None

    # delete by attribute name.
    del d.b
    assert "b" not in d.keys()

    # `copy` method returns a dictdot.
    d2 = d.copy()
    assert d2 == d
    assert type(d2) is dictdot

    # nested dicts are also dictdot.
    d = dictdot(
        a={
            "x": 0,
            "y": 0,
        },
        b=[
            {"w": 1},
            {"z": 2},
        ],
    )
    assert d["a"]["x"] == d.a.y
    assert d.b[0].w == 1
    assert d.b[0].z is None
    assert d.b[1].z == 2
    

