Skip to content

core

core

Core DomoCard classes

DomoCard dataclass

DomoCard(
    auth: DomoAuth,
    id: str,
    raw: dict,
    Lineage: DomoLineage | None = None,
    Definition: DomoCard_DefinitionManager | None = None,
    Datasets: DomoCard_DatasetsManager | None = None,
    Owners: DomoCard_OwnerManager | None = None,
    Pages: DomoCard_PageManager | None = None,
    Access: DomoCardAccessController | None = None,
    BeastModes: DomoCard_BeastModesManager | None = None,
    title: str | None = None,
    description: str | None = None,
    type: str | None = None,
    urn: str | None = None,
    chart_type: str | None = None,
    badge_type: str | None = None,
    dataset_id: str | None = None,
    datastore_id: str | None = None,
    domo_collections: list[Any] = list(),
    domo_source_code: Any = None,
    certification: dict | None = None,
    _init_owners: InitVar[list[Any] | None] = None,
    pages: list[Any] = list(),
)

Bases: DomoCard_Default

DomoCard factory class that uses composition for federated support

create async classmethod

create(
    auth: DomoAuth,
    chart_type: str,
    dataset_id: str,
    title: str,
    *,
    measure_column: str | None = None,
    aggregation: str = "SUM",
    measure_formula: dict[str, Any] | None = None,
    measure_beastmode: dict[str, Any] | None = None,
    dimension_column: str | None = None,
    series_column: str | None = None,
    filters: list[Any] | None = None,
    order_by: list[Any] | None = None,
    overrides: dict[str, Any] | None = None,
    description: str | None = None,
    definition: dict[str, Any] | None = None,
    return_raw: bool = False,
    context: RouteContext | None = None,
    **context_kwargs
) -> DomoCard

Create a new KPI card and return the hydrated :class:DomoCard.

This is the high-level entry point that ties the kpi_builder write side to the create_card route. It builds the card definition from the supplied chart parameters (or accepts a pre-built definition), binds it to dataset_id, and returns a fully-loaded card.

Passing the builder output straight through is deliberately safe: this method sends the inner definition to the route, so callers never have to unwrap the {"definition": ...} envelope themselves.

Parameters:

Name Type Description Default
auth DomoAuth

DomoAuth instance.

required
chart_type str

Friendly chart-type name (e.g. "bar", "single_value"). See kpi_builder.get_registered_card_types().

required
dataset_id str

The dataSourceId to bind the card to.

required
title str

Card title.

required
measure_column str | None

VALUE column (aggregated numeric measure).

None
aggregation str

Aggregation applied to measure_column.

'SUM'
dimension_column str | None

ITEM / primary groupBy column.

None
series_column str | None

Optional SERIES / secondary grouping column.

None
filters list[Any] | None

Optional filters (raw dicts or Filter instances).

None
order_by list[Any] | None

Optional sorts (raw dicts or SortColumn instances).

None
overrides dict[str, Any] | None

Chart overrides (title_x, title_y, footer).

None
description str | None

Optional card description.

None
definition dict[str, Any] | None

Escape hatch — a pre-built inner definition dict (from KpiDefinition.definition or build_kpi_card_definition(...)["definition"]). When given, the chart-parameter args are ignored.

None
return_raw bool

Return the raw create response instead of a DomoCard.

False
context RouteContext | None

Optional RouteContext.

None

Returns:

Type Description
DomoCard

The created card, hydrated via :meth:get_by_id (or the raw

DomoCard

response when return_raw is True).

Raises:

Type Description
CardApiError

If the create call fails.

ValueError

If the create response has no resolvable card id.

Source code in src/crew_dcs/classes/DomoCard/core.py
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
@classmethod
async def create(
    cls,
    auth: DomoAuth,
    chart_type: str,
    dataset_id: str,
    title: str,
    *,
    measure_column: str | None = None,
    aggregation: str = "SUM",
    measure_formula: dict[str, Any] | None = None,
    measure_beastmode: dict[str, Any] | None = None,
    dimension_column: str | None = None,
    series_column: str | None = None,
    filters: list[Any] | None = None,
    order_by: list[Any] | None = None,
    overrides: dict[str, Any] | None = None,
    description: str | None = None,
    definition: dict[str, Any] | None = None,
    return_raw: bool = False,
    context: RouteContext | None = None,
    **context_kwargs,
) -> "DomoCard":
    """Create a new KPI card and return the hydrated :class:`DomoCard`.

    This is the high-level entry point that ties the ``kpi_builder`` write
    side to the ``create_card`` route. It builds the card definition from
    the supplied chart parameters (or accepts a pre-built ``definition``),
    binds it to ``dataset_id``, and returns a fully-loaded card.

    Passing the builder output straight through is deliberately safe: this
    method sends the *inner* definition to the route, so callers never have
    to unwrap the ``{"definition": ...}`` envelope themselves.

    Args:
        auth: DomoAuth instance.
        chart_type: Friendly chart-type name (e.g. ``"bar"``,
            ``"single_value"``). See
            ``kpi_builder.get_registered_card_types()``.
        dataset_id: The dataSourceId to bind the card to.
        title: Card title.
        measure_column: VALUE column (aggregated numeric measure).
        aggregation: Aggregation applied to ``measure_column``.
        dimension_column: ITEM / primary groupBy column.
        series_column: Optional SERIES / secondary grouping column.
        filters: Optional filters (raw dicts or ``Filter`` instances).
        order_by: Optional sorts (raw dicts or ``SortColumn`` instances).
        overrides: Chart overrides (``title_x``, ``title_y``, ``footer``).
        description: Optional card description.
        definition: Escape hatch — a pre-built *inner* definition dict
            (from ``KpiDefinition.definition`` or
            ``build_kpi_card_definition(...)["definition"]``). When given,
            the chart-parameter args are ignored.
        return_raw: Return the raw create response instead of a DomoCard.
        context: Optional RouteContext.

    Returns:
        The created card, hydrated via :meth:`get_by_id` (or the raw
        response when ``return_raw`` is True).

    Raises:
        CardApiError: If the create call fails.
        ValueError: If the create response has no resolvable card id.
    """
    # create + hydrate reuse one pooled session automatically via auth-level
    # connection reuse (RouteContext.reuse_session, default on) — no explicit
    # session handling needed. Lazy import avoids a route<->class cycle.
    from ...routes import card as card_routes
    from .kpi_builder import build_kpi_card_definition

    if definition is None:
        envelope = build_kpi_card_definition(
            chart_type,
            dataset_id=dataset_id,
            title=title,
            measure_column=measure_column,
            aggregation=aggregation,
            measure_formula=measure_formula,
            measure_beastmode=measure_beastmode,
            dimension_column=dimension_column,
            series_column=series_column,
            filters=filters or [],
            order_by=order_by or [],
            overrides=overrides or {},
            description=description,
        )
        definition = envelope["definition"]

    res = await card_routes.create_card(
        auth=auth,
        definition=definition,
        dataset_id=dataset_id,
        context=context,
    )

    if return_raw:
        return res

    body = res.response if isinstance(res.response, dict) else {}
    card_id = body.get("id") or body.get("cardId") or body.get("urn")
    if not card_id:
        raise ValueError(
            f"create_card response did not contain a card id: {res.response!r}"
        )

    return await cls.get_by_id(auth=auth, card_id=str(card_id), context=context)

delete async

delete(
    *, context: RouteContext | None = None, **context_kwargs
) -> Any

Delete this card.

Source code in src/crew_dcs/classes/DomoCard/core.py
127
128
129
130
131
132
133
134
135
136
137
138
139
async def delete(
    self,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
) -> Any:
    """Delete this card."""
    from ...routes import card as card_routes

    context = RouteContext.build_context(context=context, **context_kwargs)
    return await card_routes.delete_card(
        auth=self.auth, card_id=str(self.id), context=context
    )

from_dict classmethod

from_dict(
    auth: DomoAuth,
    obj: dict,
    owners: list[Any] | None = None,
    pages: list[Any] | None = None,
    is_published: bool = False,
    parent_auth_retrieval_fn: Callable | None = None,
    parent_auth: DomoAuth | None = None,
    **kwargs
) -> DomoCard

Convert API response dictionary to DomoCard instance.

For federated cards, use composition via card.Federation helper.

Source code in src/crew_dcs/classes/DomoCard/core.py
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
@classmethod
def from_dict(
    cls,
    auth: DomoAuth,
    obj: dict,
    owners: list[Any] | None = None,
    pages: list[Any] | None = None,
    is_published: bool = False,
    parent_auth_retrieval_fn: Callable | None = None,
    parent_auth: DomoAuth | None = None,
    **kwargs,
) -> "DomoCard":
    """Convert API response dictionary to DomoCard instance.

    For federated cards, use composition via card.Federation helper.
    """

    # Build the card instance
    card = cls(
        auth=auth,
        id=obj.get("id"),
        raw=obj,
        title=obj.get("title"),
        description=obj.get("description"),
        type=obj.get("type"),
        urn=obj.get("urn"),
        certification=obj.get("certification"),
        chart_type=obj.get("metadata", {}).get("chartType"),
        badge_type=obj.get("metadata", {}).get("chartType"),
        dataset_id=(
            obj.get("datasources", [])[0].get("dataSourceId")
            if obj.get("datasources")
            else None
        ),
        _init_owners=owners or [],
        pages=pages or [],
        datastore_id=obj.get("domoapp", {}).get("id"),
    )

    # Enable federation support if card is federated
    if card.is_federated:
        card.enable_federation_support()

    return card