Containers

class chipscopy.api.containers.QueryDict(dict=None, /, **kwargs)[source]

Dictionary with bells and whistles

flatten(sort_by_key=True, separator='/')[source]

Flatten a nested dictionary

Parameters
  • sort_by_key (bool) – True if keys should be sorted alphabetically

  • separator (str) – The character(s) to use when joining parent and child key

class chipscopy.api.containers.QueryList(initlist=None)[source]

QueryList is a simple custom list with a few extra bells and whistles.

QueryList elements can be any object. If the elements contain a dictionary member called “filter_by”, those key/value pairs in the dictionary are used for filtering.

A custom matching function can be specified in this querylist using set_custom_match_function. Any custom match function takes priority when matching over the optional filter_by attribute.

all()[source]

Returns: every element in list

Return type

QueryList[~T]

at(index)[source]

Return value from index

Parameters

index – Index of the element to get

Return type

~T

Returns

Element at index

filter_by(**filters)[source]

Iterate through list and return only those elements that match specifications in filters. For an item to qualify as ‘filterable’, the item must be an object and have an attribute named filter_by of type Dict[str, Any].

This function will use the filters provided to it and match all the specifications against the data in the filter_by attribute of the each element in the list.

Parameters
  • **filters – attribute=`value` syntax, will try to access this attribute of the object and if there is a

  • objects with matching values for said attribute shall be returned. Example (match) – family=”versal”

Return type

QueryList[~T]

Returns

List of elements that match the specifications provided

get(**filters)[source]

Get one list item matching the filter. If exactly one list item does not match the filter, a ValueError is raised.

Parameters

**filters

Return type

~T

Returns

The one element matching the filter

set_custom_match_function(match_function)[source]

Sets an optional custom match function for the QueryList. If a custom match function is set, each list item is compared using the match function. The match function is expected to return True if the list_item matches the passed in key/value pair.

Parameters

match_function (list_item, key, value) –