Card#

Classes related to card endpoints

class metabase_tools.models.card_model.CardItem(*, id, name=None, description=None, archived, collection_position=None, table_id=None, result_metadata=None, creator, database_id=None, enable_embedding, collection_id=None, query_type=None, creator_id, updated_at, made_public_by_id=None, embedding_params=None, cache_ttl=None, dataset_query, display, visualization_settings, collection=None, dataset=None, created_at, public_uuid=None, can_write=None, is_write=None, dashboard_count=None, favorite=None, average_query_time=None, collection_preview=None, entity_id=None, last_query_start=None, moderation_reviews=None, parameter_mappings=None, parameters=None, **extra_data)#

Card object class with related methods

Parameters:
  • id (int | str) –

  • name (str | None) –

  • description (str | None) –

  • archived (bool) –

  • collection_position (int | None) –

  • table_id (int | None) –

  • result_metadata (list[dict[str, Any]] | None) –

  • creator (UserItem) –

  • database_id (int | None) –

  • enable_embedding (bool) –

  • collection_id (int | None) –

  • query_type (str | None) –

  • creator_id (int) –

  • updated_at (datetime) –

  • made_public_by_id (int | None) –

  • embedding_params (dict[str, Any] | None) –

  • cache_ttl (str | None) –

  • dataset_query (dict[str, Any]) –

  • display (str) –

  • visualization_settings (dict[str, Any]) –

  • collection (CollectionItem | None) –

  • dataset (int | None) –

  • created_at (datetime) –

  • public_uuid (UUID | None) –

  • can_write (bool | None) –

  • is_write (bool | None) –

  • dashboard_count (int | None) –

  • favorite (bool | None) –

  • average_query_time (int | None) –

  • collection_preview (bool | None) –

  • entity_id (str | None) –

  • last_query_start (datetime | None) –

  • moderation_reviews (list[Any] | None) –

  • parameter_mappings (list[Any] | None) –

  • parameters (list[Any] | None) –

  • extra_data (Any) –

archive()#

Method for archiving a card

Raises:

InvalidParameters – Targets and jsons are both None

Returns:

Object of the relevant type

Return type:

CardItem

Parameters:

self (CardItem) –

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 (CardItem) –

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

favorite()#

Mark card as favorite

Returns:

Result of favoriting operation

Return type:

dict

Parameters:

self (CardItem) –

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

query()#

Execute a query stored in card(s)

Returns:

Results of query

Return type:

CardQueryResult

Parameters:

self (CardItem) –

refresh()#

Returns refreshed copy of the card

Returns:

self

Return type:

CardItem

Parameters:

self (CardItem) –

related()#

Objects related to target

Returns:

CardRelatedObjects

Parameters:

self (CardItem) –

Return type:

CardRelatedObjects

set_adapter(adapter)#

Sets the adapter on an object

Parameters:

adapter (MetabaseApi) – Connection to MetabaseApi

Return type:

None

share()#

Generate publicly-accessible link for card

Returns:

UUID to be used in public link.

Return type:

dict

Parameters:

self (CardItem) –

unarchive()#

Method for unarchiving a card

Raises:

InvalidParameters – Targets and jsons are both None

Returns:

Object of the relevant type

Return type:

CardItem

Parameters:

self (CardItem) –

unfavorite()#

Unfavorite card

Returns:

Result of unfavoriting operation

Return type:

dict

Parameters:

self (CardItem) –

unshare()#

Remove publicly-accessible links for card

Returns:

UUID to be used in public link.

Return type:

dict

Parameters:

self (CardItem) –

update(visualization_settings=MissingParam(), description=MissingParam(), archived=MissingParam(), collection_position=MissingParam(), result_metadata=MissingParam(), metadata_checksum=MissingParam(), enable_embedding=MissingParam(), collection_id=MissingParam(), name=MissingParam(), embedding_params=MissingParam(), dataset_query=MissingParam(), display=MissingParam(), **kwargs)#

Updates a card using the provided parameters

Parameters:
  • self (CardItem) –

  • visualization_settings (dict[str, str], optional) –

  • description (str, optional) –

  • archived (bool, optional) –

  • collection_position (int, optional) –

  • result_metadata (list[dict[str, str]], optional) –

  • metadata_checksum (str, optional) –

  • enable_embedding (bool, optional) –

  • collection_id (int, optional) –

  • name (str, optional) –

  • embedding_params (dict[str, str], optional) –

  • dataset_query (dict[str, Any], optional) –

  • display (str, optional) –

  • kwargs (Any) –

Returns:

_description_

Return type:

CardItem

classmethod update_forward_refs(**localns)#

Try to update ForwardRefs on fields based on this Model, globalns and localns.

Parameters:

localns (Any) –

Return type:

None

class metabase_tools.models.card_model.CardQueryResult(*, data, database_id, started_at, json_query, average_execution_time=None, status, context, row_count, running_time)#

Object for results of a card query

Parameters:
  • data (dict[str, Any]) –

  • database_id (int) –

  • started_at (datetime) –

  • json_query (dict[str, Any]) –

  • average_execution_time (int | None) –

  • status (str) –

  • context (str) –

  • row_count (int) –

  • running_time (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

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

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

classmethod update_forward_refs(**localns)#

Try to update ForwardRefs on fields based on this Model, globalns and localns.

Parameters:

localns (Any) –

Return type:

None

class metabase_tools.models.card_model.CardRelatedObjects(*, card_id, table=None, metrics, segments, dashboards, collections, **extra_data)#

Objects related to the specified card

Parameters:
  • card_id (int) –

  • table (str | None) –

  • metrics (list[dict[str, int]]) –

  • segments (list[dict[str, int]]) –

  • dashboards (list[dict[str, Any]]) –

  • collections (list[dict[str, Any]]) –

  • extra_data (Any) –

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

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

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

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 card endpoints

class metabase_tools.endpoints.cards_endpoint.Cards(adapter)#

Card related endpoint methods

Parameters:

adapter (MetabaseApi) –

create(visualization_settings=MissingParam(), name=MissingParam(), dataset_query=MissingParam(), display=MissingParam(), description=MissingParam(), collection_position=MissingParam(), result_metadata=MissingParam(), metadata_checksum=MissingParam(), collection_id=MissingParam(), **kwargs)#

Creates a new card

Parameters:
  • visualization_settings (dict[str, Any]) –

  • name (str) –

  • dataset_query (dict[str, Any]) –

  • display (str) –

  • description (str, optional) –

  • collection_position (int, optional) –

  • result_metadata (list[dict[str, Any]], optional) –

  • metadata_checksum (str, optional) –

  • collection_id (int, optional) –

  • kwargs (Any) –

Returns:

CardItem

Return type:

CardItem

embeddable()#

Fetch list of cards with embedding enabled

Raises:

EmptyDataReceived – If no cards have embedding enabled

Returns:

List of cards with embedding enabled

Return type:

list[CardItem]

get(targets=None)#

Fetch list of cards

Parameters:

targets (list[int], optional) – If provided, the list of cards to fetch

Returns:

list[CardItem]

Return type:

list[CardItem]

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[CardItem], optional) – Provide to search an existing list, by default pulls from API

Returns:

List of cards of the relevant type

Return type:

list[CardItem]