Collection#
Classes related to collections endpoints
- class metabase_tools.models.collection_model.CollectionItem(*, id, name=None, description=None, archived=None, slug=None, color=None, personal_owner_id=None, location=None, namespace=None, effective_location=None, effective_ancestors=None, can_write=None, parent_id=None, authority_level=None, entity_id=None, created_at=None)#
Collection object class with related methods
- Parameters:
id (int | str) –
name (str | None) –
description (str | None) –
archived (bool | None) –
slug (str | None) –
color (str | None) –
personal_owner_id (int | None) –
location (str | None) –
namespace (int | None) –
effective_location (str | None) –
effective_ancestors (list[dict[str, Any]] | None) –
can_write (bool | None) –
parent_id (int | None) –
authority_level (Any | None) –
entity_id (str | None) –
created_at (datetime | None) –
- archive()#
Method for archiving a collection
- Returns:
Object of the relevant type
- Return type:
- Parameters:
self (CollectionItem) –
- check_for_object(item_name)#
Checks for object in the collection and returns the id, if found
- Parameters:
item_name (str) – Name of the item being located
- Raises:
MetabaseApiException – Item not found
- Returns:
id of the item being located
- Return type:
int
- classmethod construct(_fields_set=None, **values)#
Creates a new model setting __dict__ and __fields_set__ from trusted or pre-validated data. Default values are respected, but no other validation is performed. Behaves as if Config.extra = ‘allow’ was set since it adds all passed values
- Parameters:
_fields_set (SetStr | None) –
values (Any) –
- Return type:
Model
- copy(*, include=None, exclude=None, update=None, deep=False)#
Duplicate a model, optionally choose which fields to include, exclude and change.
- Parameters:
include (AbstractSetIntStr | MappingIntStrAny | None) – fields to include in new model
exclude (AbstractSetIntStr | MappingIntStrAny | None) – fields to exclude from new model, as with values this takes precedence over include
update (DictStrAny | None) – values to change/add in the new model. Note: the data is not validated before creating the new model: you should trust this data
deep (bool) – set to True to make a deep copy of the model
self (Model) –
- Returns:
new model instance
- Return type:
Model
- delete()#
DEPRECATED; use archive instead
- Parameters:
self (CollectionItem) –
- Return type:
None
- dict(*, include=None, exclude=None, by_alias=False, skip_defaults=None, exclude_unset=False, exclude_defaults=False, exclude_none=False)#
Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
- Parameters:
include (AbstractSetIntStr | MappingIntStrAny | None) –
exclude (AbstractSetIntStr | MappingIntStrAny | None) –
by_alias (bool) –
skip_defaults (bool | None) –
exclude_unset (bool) –
exclude_defaults (bool) –
exclude_none (bool) –
- Return type:
DictStrAny
- get_contents(model_type=None, archived=False)#
Get the contents of the provided collection
- Parameters:
adapter (MetabaseApi) – Connection to Metabase API
collection_id (int) – ID of the requested collection
model_type (str, optional) – Filter to provided model. Defaults to all.
archived (bool, optional) – Archived objects. Defaults to False.
- Raises:
EmptyDataReceived – No results from API
- Returns:
Contents of collection
- Return type:
list
- json(*, include=None, exclude=None, by_alias=False, skip_defaults=None, exclude_unset=False, exclude_defaults=False, exclude_none=False, encoder=None, models_as_dict=True, **dumps_kwargs)#
Generate a JSON representation of the model, include and exclude arguments as per dict().
encoder is an optional function to supply as default to json.dumps(), other arguments as per json.dumps().
- Parameters:
include (AbstractSetIntStr | MappingIntStrAny | None) –
exclude (AbstractSetIntStr | MappingIntStrAny | None) –
by_alias (bool) –
skip_defaults (bool | None) –
exclude_unset (bool) –
exclude_defaults (bool) –
exclude_none (bool) –
encoder (Callable[[Any], Any] | None) –
models_as_dict (bool) –
dumps_kwargs (Any) –
- Return type:
unicode
- refresh()#
Returns refreshed copy of the collection
- Returns:
self
- Return type:
- Parameters:
self (CollectionItem) –
- set_adapter(adapter)#
Sets the adapter on an object
- Parameters:
adapter (MetabaseApi) – Connection to MetabaseApi
- Return type:
None
- unarchive()#
Method for unarchiving a collection
- Returns:
Object of the relevant type
- Return type:
- Parameters:
self (CollectionItem) –
- update(name=MissingParam(), color=MissingParam(), description=MissingParam(), archived=MissingParam(), parent_id=MissingParam(), **kwargs)#
Updates a collection using the provided parameters
- Parameters:
self (CollectionItem) –
name (str, optional) –
color (str, optional) –
description (str, optional) –
archived (bool, optional) –
parent_id (int, optional) –
kwargs (Any) –
- Returns:
CollectionItem
- Return type:
- classmethod update_forward_refs(**localns)#
Try to update ForwardRefs on fields based on this Model, globalns and localns.
- Parameters:
localns (Any) –
- Return type:
None
Classes related to collection endpoints
- class metabase_tools.endpoints.collections_endpoint.Collections(adapter)#
Card related endpoint methods
- Parameters:
adapter (MetabaseApi) –
- create(name=MissingParam(), color=MissingParam(), description=MissingParam(), parent_id=MissingParam(), namespace=MissingParam(), **kwargs)#
Creates a new collection
- Parameters:
name (str, optional) –
color (str, optional) –
description (str, optional) –
parent_id (int, optional) –
namespace (str, optional) –
kwargs (Any) –
- Returns:
CollectionItem
- Return type:
- get(targets=None)#
Fetch list of collections
- Parameters:
targets (list[int], optional) – If provided, the list of collections to fetch
- Returns:
list[CollectionItem]
- Return type:
list[CollectionItem]
- get_flat_list()#
Flattens collection tree so the full path of each collection is shown
- Parameters:
adapter (MetabaseApi) – Connection to Metabase API
- Returns:
Flattened collection tree
- Return type:
list[dict]
- get_tree()#
Collection tree
- Parameters:
adapter (MetabaseApi) – Connection to Metabase API
- Raises:
EmptyDataReceived – No data returned from API
- Returns:
Representation of collection tree
- Return type:
list[dict]
- graph()#
Graph of collection permissions
- Returns:
graph of collection
- Return type:
dict
- search(search_params, search_list=None)#
Method to search a list of cards meeting a list of parameters
- Parameters:
search_params (list[dict]) – Each dict contains search criteria and returns 1 result
search_list (list[CollectionItem], optional) – Provide to search an existing list, by default pulls from API
- Returns:
List of cards of the relevant type
- Return type:
list[CollectionItem]