dot_dict
Dict wrapper that also allows attribute access.
- class atproto_client.models.dot_dict.DotDict(data: Dict[str, Any])
Bases:
UnknownDictDot notation for dictionaries.
Note
If the record is out of the official lexicon, it`s impossible to deserialize it to a proper data model. Such models will fall back to dictionaries. All unknown βUnionβ types will also be caught as dicts. This class exists to provide an ability to use such fallbacks as βrealβ data models.
Example
>>> test_data = {'a': 1, 'b': {'c': 2}, 'd': [{'e': 3}, 4, 5]} >>> model = DotDict(test_data) >>> assert isinstance(model, DotDict) >>> assert model.nonExistingField is None >>> assert model.a == 1 >>> assert model['a'] == 1 >>> assert model['b']['c'] == 2 >>> assert model.b.c == 2 >>> assert model.b['c'] == 2 >>> assert model['b'].c == 2 >>> assert model.d[0].e == 3 >>> assert model['d'][0]['e'] == 3 >>> assert model['d'][0].e == 3 >>> assert model['d'][1] == 4 >>> assert model['d'][2] == 5 >>> model['d'][0]['e'] = 6 >>> assert model['d'][0]['e'] == 6 >>> assert DotDict(test_data) == DotDict(test_data) >>> assert model.to_dict() == test_data- keys() KeysView
- values() ValuesView
- items() ItemsView