# DotDict¶

Classes:

 DotDict Subclass of dict, with “dot” (attribute) access to keys, a pretty-printed repr, which indents and truncates large containers, and a JSON repr for Jupyter Lab. DotDict_items(dotdict) Wrapper around a dict_values object that yields dicts and lists as DotDicts and DotLists when iterated. DotDict_values(dotdict) Wrapper around a dict_values object that yields dicts and lists as DotDicts and DotLists when iterated. DotDict_view(dotdict) Wrapper around a dictionary view object that yields dicts and lists as DotDicts and DotLists when iterated. DotList Returns contained dicts as DotDicts (and contained lists as DotLists), soley to allow attribute access past list indexing
class DotDict[source]

Subclass of dict, with “dot” (attribute) access to keys, a pretty-printed repr, which indents and truncates large containers, and a JSON repr for Jupyter Lab.

Any dicts stored in DotDict are returned as DotDicts, to allow chained attribute access. Any lists stored in DotDict are returned as DotLists, which return any contained dict items as DotDicts, allowing chained attribute access past list indexing.

The repr() of a DotDict is truncated for readability, but str() is not.

Example

>>> d = DotDict(a=1, b=[{"foo": "bar"}])
>>> d.a
1
>>> d["a"]
1
>>> d.b
[
{
'foo': 'bar'
}
]
>>> d.b[0].foo
'bar'


Methods:

 Raises RuntimeError if the container is recursive (contains itself as a value). get(k[,d]) Values that are dicts or lists are cast to DotDicts and DotLists. Equivalent to dict.items. pop(k[,d]) If key is not found, d is returned if given, otherwise KeyError is raised. 2-tuple; but raise KeyError if D is empty. setdefault(k[,d]) If d is a dict or list, it is returned as a DotDict or DotList. Equivalent to dict.values.
asdict() → a deep copy of D, where any DotDicts or DotLists contained are converted to plain types.[source]

Raises RuntimeError if the container is recursive (contains itself as a value).

get(k[, d]) → D[k] if k in D, else d. d defaults to None.[source]

Values that are dicts or lists are cast to DotDicts and DotLists.

items()[source]

Equivalent to dict.items. Values that are plain dicts or lists are returned as DotDicts or DotLists.

pop(k[, d]) → v, remove specified key and return the corresponding value.[source]

If key is not found, d is returned if given, otherwise KeyError is raised. If v is a dict or list, it is returned as a DotDict or DotList.

popitem() → (k, v), remove and return some (key, value) pair as a[source]

2-tuple; but raise KeyError if D is empty. If v is a dict or list, it is returned as a DotDict or DotList.

setdefault(k[, d]) → D.get(k,d), also set D[k]=d if k not in D[source]

If d is a dict or list, it is returned as a DotDict or DotList.

values()[source]

Equivalent to dict.values. Values that are plain dicts or lists are returned as DotDicts or DotLists.

class DotDict_items(dotdict)[source]

Wrapper around a dict_values object that yields dicts and lists as DotDicts and DotLists when iterated.

Methods:

 isdisjoint(iterable) Return True if the view and the given iterable have a null intersection.
isdisjoint(iterable)[source]

Return True if the view and the given iterable have a null intersection.

class DotDict_values(dotdict)[source]

Wrapper around a dict_values object that yields dicts and lists as DotDicts and DotLists when iterated.

class DotDict_view(dotdict)[source]

Wrapper around a dictionary view object that yields dicts and lists as DotDicts and DotLists when iterated.

class DotList[source]

Returns contained dicts as DotDicts (and contained lists as DotLists), soley to allow attribute access past list indexing

Methods:

 Raises RuntimeError if the container is recursive (contains itself as a value). pop([index]) If item is a dict or list, it is returned as a DotDict or DotList.
aslist() → a deep copy of L, where any DotDicts or DotLists contained are converted to plain types.[source]

Raises RuntimeError if the container is recursive (contains itself as a value).

pop([index]) → item -- remove and return item at index (default last).[source]

If item is a dict or list, it is returned as a DotDict or DotList. Raises IndexError if list is empty or index is out of range.

# Properties¶

Classes:

 EqExpression(name, value) Expression An expression for filtering a property against a value or set of values. GenericProperties A wrapper object to allow constructing filter expressions using properties. LikeExpression(name, value) NeExpression(name, value) Properties(*args) A wrapper object to allow constructing filter expressions using properties Property(name[, parts]) A wrapper object for a single property RangeExpression(name, parts)
class EqExpression(name, value)[source]
class Expression[source]

An expression for filtering a property against a value or set of values.

An expression contains a Property, a comparison operator, and a value (or set of values):

property operator value
or
value operator property

where the operator can be

• ==

• !=

• <

• <=

• >

• >=

If the operator is <, <=, > or >=, you can construct a range using

value operator property operator value

Expressions can be combined using the Boolean operators and or or, but due to language limitations the operator for and is expressed as & and the operator for or is expressed as |.

In addition there are a couple of method-like operators that can be used on a property:

Example

>>> from descarteslabs.common.property_filtering import GenericProperties
>>> p = GenericProperties()
>>> e = p.foo == 5
>>> type(e)
<class 'descarteslabs.common.property_filtering.filtering.EqExpression'>
>>> e = p.foo.any_of([1, 2, 3, 4, 5])
>>> type(e)
<class 'descarteslabs.common.property_filtering.filtering.OrExpression'>
>>> e = 5 < p.foo < 10
>>> type(e)
<class 'descarteslabs.common.property_filtering.filtering.RangeExpression'>
>>> e = (5 < p.foo < 10) & p.foo.any_of([1, 2, 3, 4, 5])
>>> type(e)
<class 'descarteslabs.common.property_filtering.filtering.AndExpression'>

class GenericProperties[source]

A wrapper object to allow constructing filter expressions using properties.

You can construct filter expression using the ==, !=, <, >, <= and >= operators as well as the like() and in_() or any_of() method. You cannot use the boolean keywords and and or because of Python language limitations; instead you can combine filter expressions with & (boolean “and”) and | (boolean “or”).

class LikeExpression(name, value)[source]
class NeExpression(name, value)[source]
class Properties(*args)[source]

A wrapper object to allow constructing filter expressions using properties

class Property(name, parts=None)[source]

A wrapper object for a single property

Methods:

 any_of(iterable) Asserts that this property must have a value equal to one of the values in the given iterable. in_(iterable) Asserts that this property must have a value equal to one of the values in the given iterable. like(other) Compare against a wildcard string.
any_of(iterable)

Asserts that this property must have a value equal to one of the values in the given iterable. This can be thought of as behaving like an in expression in Python or an IN expression in SQL.

in_(iterable)[source]

Asserts that this property must have a value equal to one of the values in the given iterable. This can be thought of as behaving like an in expression in Python or an IN expression in SQL.

like(other)[source]

Compare against a wildcard string.

This allows for wildcards, e.g. like("bar%foo") where any string that starts with 'bar' and ends with 'foo' will be matched.

This uses the SQL LIKE syntax with single character wildcard '_' and arbitrary character wildcard '%'.

To escape either of these wilcard characters prepend it with a backslash, which becomes a double backslash in the python string, i.e. use like("bar\\%foo") to match exactly 'bar%foo'.

class RangeExpression(name, parts)[source]