Skip to main content

SDK Entities Reference

The DataHub SDK provides a set of entities that can be used to interact with DataHub’s metadata.

Dataset

class datahub.sdk.dataset.Dataset(*, platform, name, platform_instance = None, env = 'PROD', description = None, display_name = None, qualified_name = None, external_url = None, custom_properties = None, created = None, last_modified = None, view_definition = None, parent_container = Unset.token, subtype = None, owners = None, links = None, tags = None, terms = None, domain = None, schema = None, upstreams = None, structured_properties = None, extra_aspects = None, parse_view_lineage = None)

Bases: HasPlatformInstance, HasSubtype, HasContainer, HasOwnership, HasInstitutionalMemory, HasTags, HasTerms, HasDomain, HasStructuredProperties, Entity

Represents a dataset in DataHub.

A dataset represents a collection of data, such as a table, view, or file. This class provides methods for managing dataset metadata including schema, lineage, and various aspects like ownership, tags, and terms.

Automatic View Lineage Parsing

When a view_definition SQL string is provided, the SDK can automatically parse it to extract upstream table references using sqlglot. This behavior is controlled by the parse_view_lineage parameter:

  • None (default): Auto-parse in SDK mode, skip in ingestion framework (where SqlParsingAggregator handles lineage more accurately)
  • True: Force parsing (even within the ingestion framework)
  • False: Never parse automatically

Features:

  • Supports all major SQL dialects (Snowflake, BigQuery, Postgres, etc.)
  • Filters out CTEs (Common Table Expressions) from upstream tables
  • Gracefully handles parse errors without raising exceptions

Limitations:

  • Table-level lineage only (no column-level lineage)
  • No schema resolution: table names are taken as-is from the SQL. For fully-qualified references, ensure your view definition includes the database and schema (e.g., db.schema.table)
  • Best-effort extraction; for production-grade lineage with schema resolution and additional context (e.g., temporary tables), use SqlParsingAggregator

Example:

# Auto-parsing enabled by default
view = Dataset(
platform="snowflake",
name="analytics.reporting.sales_summary",
view_definition="SELECT * FROM analytics.raw.sales WHERE year = 2024",
)
# view.upstreams now contains analytics.raw.sales

# Disable auto-parsing
view = Dataset(
platform="snowflake",
name="analytics.reporting.sales_summary",
view_definition="SELECT * FROM analytics.raw.sales",
parse_view_lineage=False, # Must set upstreams manually
)
  • Parameters:
    • platform (str)
    • name (str)
    • platform_instance (Optional [str])
    • env (str)
    • description (Optional [str])
    • display_name (Optional [str])
    • qualified_name (Optional [str])
    • external_url (Optional [str])
    • custom_properties (Optional [Dict[str,str] ])
    • created (Optional [datetime])
    • last_modified (Optional [datetime])
    • view_definition (Optional [ViewDefinitionInputType])
    • parent_container (ParentContainerInputType | Unset)
    • subtype (Optional [str])
    • owners (Optional [OwnersInputType])
    • links (Optional [LinksInputType])
    • tags (Optional [TagsInputType])
    • terms (Optional [TermsInputType])
    • domain (Optional [DomainInputType])
    • schema (Optional [SchemaFieldsInputType])
    • upstreams (Optional [UpstreamLineageInputType])
    • structured_properties (Optional [StructuredPropertyInputType])
    • extra_aspects (ExtraAspectsType)
    • parse_view_lineage (Optional [bool])

property created : datetime | None

Get the creation timestamp of the dataset.

  • Returns: The creation timestamp if set, None otherwise.

property custom_properties : Dict[str, str]

Get the custom properties of the dataset.

  • Returns: Dictionary of custom properties.

property description : str | None

Get the description of the dataset.

  • Returns: The description if set, None otherwise.

property display_name : str | None

Get the display name of the dataset.

  • Returns: The display name if set, None otherwise.

property external_url : str | None

Get the external URL of the dataset.

  • Returns: The external URL if set, None otherwise.

classmethod get_urn_type()

Get the URN type for datasets.

  • Return type:Type[DatasetUrn]
  • Returns: The DatasetUrn class.

property last_modified : datetime | None

Get the last modification timestamp of the dataset.

  • Returns: The last modification timestamp if set, None otherwise.

property qualified_name : str | None

Get the qualified name of the dataset.

  • Returns: The qualified name if set, None otherwise.

property schema : List[SchemaField]

Get the schema fields of the dataset.

  • Returns: List of SchemaField objects representing the dataset’s schema.

set_created(created)

Set the creation timestamp of the dataset.

  • Parameters:created (datetime) – The creation timestamp to set.
  • Return type:None

set_custom_properties(custom_properties)

Set the custom properties of the dataset.

  • Parameters:custom_properties (Dict[str, str]) – Dictionary of custom properties to set.
  • Return type:None

set_description(description)

Set the description of the dataset.

  • Parameters:description (str) – The description to set.
  • Return type:None

NOTE

If called during ingestion, this will warn if overwriting a non-ingestion description.

set_display_name(display_name)

Set the display name of the dataset.

  • Parameters:display_name (str) – The display name to set.
  • Return type:None

set_external_url(external_url)

Set the external URL of the dataset.

  • Parameters:external_url (str) – The external URL to set.
  • Return type:None

set_last_modified(last_modified)

  • Parameters:last_modified (datetime)
  • Return type:None

set_qualified_name(qualified_name)

Set the qualified name of the dataset.

  • Parameters:qualified_name (str) – The qualified name to set.
  • Return type:None

set_upstreams(upstreams)

set_view_definition(view_definition, parse=None)

Set the view definition of the dataset.

If you’re setting a view definition, subtype should typically be set to “view”.

If a string is provided, it will be treated as a SQL view definition. To set a custom language or other properties, provide a ViewPropertiesClass object.

By default (parse=None), the SQL will be automatically parsed to extract upstream lineage, unless running inside the ingestion framework (which uses SqlParsingAggregator).

  • Parameters:
    • view_definition (Union[str, ViewPropertiesClass]) – The view definition to set.
    • parse (Optional[bool]) – Whether to parse the SQL and extract upstream lineage. None (default): auto-parse in SDK mode, skip in ingestion framework. True: force parsing (even in ingestion framework). False: never parse.
  • Return type:None

property upstreams : UpstreamLineageClass | None

property urn : DatasetUrn

Get the entity’s URN.

  • Returns: The URN that uniquely identifies this entity.

property view_definition : ViewPropertiesClass | None

Get the view definition of the dataset.

Under typical usage, this will be present if the subtype is “View”.

  • Returns: The view definition if set, None otherwise.

SchemaField

class datahub.sdk.dataset.SchemaField(parent, field_path)

Bases: object

  • Parameters:
    • parent (Dataset) –
    • field_path (str)

add_tag(tag)

add_term(term)

property description : str | None

property field_path : str

property mapped_type : SchemaFieldDataTypeClass

property native_type : str

remove_tag(tag)

remove_term(term)

set_description(description)

  • Parameters:description (str)
  • Return type:None

set_tags(tags)

set_terms(terms)

property tags : List[TagAssociationClass] | None

property terms : List[GlossaryTermAssociationClass] | None

parse_cll_mapping

datahub.sdk.dataset.parse_cll_mapping(*, upstream, downstream, cll_mapping)

Container

class datahub.sdk.container.Container(container_key, *, display_name, qualified_name = None, description = None, external_url = None, extra_properties = None, created = None, last_modified = None, parent_container = Auto.token, subtype = None, owners = None, links = None, tags = None, terms = None, domain = None, structured_properties = None, extra_aspects = None)

Bases: HasPlatformInstance, HasSubtype, HasContainer, HasOwnership, HasInstitutionalMemory, HasStructuredProperties, HasTags, HasTerms, HasDomain, Entity

property created : datetime | None

property custom_properties : Dict[str, str] | None

property description : str | None

property display_name : str

property external_url : str | None

classmethod get_urn_type()

Get the URN type for this entity class.

  • Return type:Type[ContainerUrn]
  • Returns: The URN type class that corresponds to this entity type.

property last_modified : datetime | None

property qualified_name : str | None

set_created(created)

  • Parameters:created (datetime)
  • Return type:None

set_custom_properties(custom_properties)

  • Parameters:custom_properties (Dict[str, str])
  • Return type:None

set_description(description)

  • Parameters:description (str)
  • Return type:None

set_display_name(value)

  • Parameters:value (str)
  • Return type:None

set_external_url(external_url)

  • Parameters:external_url (str)
  • Return type:None

set_last_modified(last_modified)

  • Parameters:last_modified (datetime)
  • Return type:None

set_qualified_name(qualified_name)

  • Parameters:qualified_name (str)
  • Return type:None

MLModel

class datahub.sdk.mlmodel.MLModel(id, platform, version = None, aliases = None, platform_instance = None, env = 'PROD', name = None, description = None, training_metrics = None, hyper_params = None, external_url = None, custom_properties = None, created = None, last_modified = None, owners = None, links = None, tags = None, terms = None, domain = None, model_group = None, training_jobs = None, downstream_jobs = None, structured_properties = None, extra_aspects = None)

Bases: HasPlatformInstance, HasOwnership, HasInstitutionalMemory, HasTags, HasTerms, HasDomain, HasVersion, HasStructuredProperties, Entity

add_deployment(deployment)

  • Parameters:deployment (str)
  • Return type:None

add_downstream_job(downstream_job)

add_hyper_params(params)

  • Parameters:params (Union[List[MLHyperParamClass], Dict[str, Optional[str]]]) –
  • Return type:None

add_training_job(training_job)

add_training_metrics(metrics)

  • Parameters:metrics (Union[List[MLMetricClass], Dict[str, Optional[str]]]) –
  • Return type:None

property created : datetime | None

property custom_properties : Dict[str, str] | None

property deployments : List[str] | None

property description : str | None

property downstream_jobs : List[str] | None

property external_url : str | None

classmethod get_urn_type()

Get the URN type for this entity class.

  • Return type:Type[MlModelUrn]
  • Returns: The URN type class that corresponds to this entity type.

property hyper_params : List[MLHyperParamClass] | None

property last_modified : datetime | None

property model_group : str | None

property name : str | None

remove_deployment(deployment)

  • Parameters:deployment (str)
  • Return type:None

remove_downstream_job(downstream_job)

remove_training_job(training_job)

set_created(created)

  • Parameters:created (datetime)
  • Return type:None

set_custom_properties(custom_properties)

  • Parameters:custom_properties (Dict[str, str])
  • Return type:None

set_deployments(deployments)

  • Parameters:deployments (Sequence[str])
  • Return type:None

set_description(description)

  • Parameters:description (str)
  • Return type:None

set_downstream_jobs(downstream_jobs)

set_external_url(external_url)

  • Parameters:external_url (str)
  • Return type:None

set_hyper_params(params)

  • Parameters:params (Union[List[MLHyperParamClass], Dict[str, Optional[str]]]) –
  • Return type:None

set_last_modified(last_modified)

  • Parameters:last_modified (datetime)
  • Return type:None

set_model_group(group)

set_name(name)

  • Parameters:name (str)
  • Return type:None

set_training_jobs(training_jobs)

set_training_metrics(metrics)

  • Parameters:metrics (Union[List[MLMetricClass], Dict[str, Optional[str]]]) –
  • Return type:None

property training_jobs : List[str] | None

property training_metrics : List[MLMetricClass] | None

property urn : MlModelUrn

Get the entity’s URN.

  • Returns: The URN that uniquely identifies this entity.

MLModelGroup

class datahub.sdk.mlmodelgroup.MLModelGroup(id, platform, name = '', platform_instance = None, env = 'PROD', description = None, display_name = None, external_url = None, custom_properties = None, created = None, last_modified = None, owners = None, links = None, tags = None, terms = None, domain = None, training_jobs = None, downstream_jobs = None, structured_properties = None, extra_aspects = None)

Bases: HasPlatformInstance, HasOwnership, HasInstitutionalMemory, HasTags, HasTerms, HasDomain, HasStructuredProperties, Entity

add_downstream_job(downstream_job)

add_training_job(training_job)

property created : datetime | None

property custom_properties : Dict[str, str] | None

property description : str | None

property downstream_jobs : List[str] | None

property external_url : str | None

classmethod get_urn_type()

Get the URN type for this entity class.

  • Return type:Type[MlModelGroupUrn]
  • Returns: The URN type class that corresponds to this entity type.

property last_modified : datetime | None

property name : str | None

remove_downstream_job(downstream_job)

remove_training_job(training_job)

set_created(created)

  • Parameters:created (datetime)
  • Return type:None

set_custom_properties(custom_properties)

  • Parameters:custom_properties (Dict[str, str])
  • Return type:None

set_description(description)

  • Parameters:description (str)
  • Return type:None

set_downstream_jobs(downstream_jobs)

set_external_url(external_url)

  • Parameters:external_url (str)
  • Return type:None

set_last_modified(last_modified)

  • Parameters:last_modified (datetime)
  • Return type:None

set_name(display_name)

  • Parameters:display_name (str)
  • Return type:None

set_training_jobs(training_jobs)

property training_jobs : List[str] | None

property urn : MlModelGroupUrn

Get the entity’s URN.

  • Returns: The URN that uniquely identifies this entity.

Dashboard

class datahub.sdk.dashboard.Dashboard(*, name, platform, display_name = None, platform_instance = None, description = None, external_url = None, dashboard_url = None, custom_properties = None, last_modified = None, last_modified_by = None, created_at = None, created_by = None, deleted_on = None, deleted_by = None, last_refreshed = None, input_datasets = None, charts = None, dashboards = None, parent_container = Unset.token, subtype = None, owners = None, links = None, tags = None, terms = None, domain = None, extra_aspects = None)

Bases: ChangeAuditStampsMixin, HasPlatformInstance, HasSubtype, HasOwnership, HasContainer, HasInstitutionalMemory, HasTags, HasTerms, HasDomain, Entity

Represents a dashboard in DataHub.

add_chart(chart)

Add a chart to the dashboard.

  • Parameters:chart (Union[str, ChartUrn, Chart]) –
  • Return type:None

add_dashboard(dashboard)

Add a dashboard to the dashboard.

add_input_dataset(input_dataset)

Add an input dataset to the dashboard.

property charts : List[ChartUrn]

Get the charts of the dashboard.

property custom_properties : Dict[str, str]

Get the custom properties of the dashboard.

property dashboard_url : str | None

Get the dashboard URL.

property dashboards : List[DashboardUrn]

Get the dashboards of the dashboard.

property description : str | None

Get the description of the dashboard.

property display_name : str

Get the display name of the dashboard.

property external_url : str | None

Get the external URL of the dashboard.

classmethod get_urn_type()

Get the URN type for dashboards. :rtype: Type[DashboardUrn] :returns: The DashboardUrn class.

property input_datasets : List[DatasetUrn]

Get the input datasets of the dashboard.

property last_refreshed : datetime | None

Get the last refresh timestamp of the dashboard.

property name : str

Get the name of the dashboard.

remove_chart(chart)

Remove a chart from the dashboard.

  • Parameters:chart (Union[str, ChartUrn, Chart]) –
  • Return type:None

remove_input_dataset(input_dataset)

Remove an input dataset from the dashboard.

set_charts(charts)

Set the charts of the dashboard.

  • Parameters:charts (Sequence[Union[str, ChartUrn, Chart]]) –
  • Return type:None

set_custom_properties(custom_properties)

Set the custom properties of the dashboard.

  • Parameters:custom_properties (Dict[str, str])
  • Return type:None

set_dashboard_url(dashboard_url)

Set the dashboard URL.

  • Parameters:dashboard_url (str)
  • Return type:None

set_dashboards(dashboards)

Set the dashboards of the dashboard.

set_description(description)

Set the description of the dashboard.

  • Parameters:description (str)
  • Return type:None

set_display_name(display_name)

Set the display name of the dashboard.

  • Parameters:display_name (str)
  • Return type:None

set_external_url(external_url)

Set the external URL of the dashboard.

  • Parameters:external_url (str)
  • Return type:None

set_input_datasets(input_datasets)

Set the input datasets of the dashboard.

  • Parameters:input_datasets (Sequence[Union[str, DatasetUrn, Dataset]]) –
  • Return type:None

set_last_refreshed(last_refreshed)

Set the last refresh timestamp of the dashboard.

  • Parameters:last_refreshed (datetime)
  • Return type:None

set_title(title)

Set the display name of the dashboard.

Deprecated

Deprecated since version 1.2.0.7: Use set_display_name instead

  • Parameters:title (str)
  • Return type:None

property title : str

Get the display name of the dashboard.

Deprecated

Deprecated since version 1.2.0.7: Use display_name instead

property urn : DashboardUrn

Get the entity’s URN.

  • Returns: The URN that uniquely identifies this entity.

Chart

class datahub.sdk.chart.Chart(*, name, platform, display_name = None, platform_instance = None, description = '', external_url = None, chart_url = None, custom_properties = None, last_modified = None, last_modified_by = None, created_at = None, created_by = None, deleted_on = None, deleted_by = None, last_refreshed = None, chart_type = None, access = None, input_datasets = None, parent_container = Unset.token, subtype = None, owners = None, links = None, tags = None, terms = None, domain = None, extra_aspects = None)

Bases: ChangeAuditStampsMixin, HasPlatformInstance, HasSubtype, HasOwnership, HasContainer, HasInstitutionalMemory, HasTags, HasTerms, HasDomain, Entity

Represents a chart in DataHub.

property access : str | None

Get the access level of the chart as a string.

add_input_dataset(input_dataset)

Add an input to the chart.

property chart_type : str | None

Get the type of the chart as a string.

property chart_url : str | None

Get the chart URL.

property custom_properties : Dict[str, str]

Get the custom properties of the chart.

property description : str | None

Get the description of the chart.

property display_name : str

Get the display name of the chart.

property external_url : str | None

Get the external URL of the chart.

classmethod get_urn_type()

Get the URN type for charts. :rtype: Type[ChartUrn] :returns: The ChartUrn class.

property input_datasets : List[DatasetUrn]

Get the input datasets of the chart.

property last_refreshed : datetime | None

Get the last refresh timestamp of the chart.

property name : str

Get the name of the chart.

remove_input_dataset(input_dataset)

Remove an input from the chart.

set_access(access)

Set the access level of the chart.

set_chart_type(chart_type)

Set the type of the chart.

  • Parameters:chart_type (Union[str, ChartTypeClass]) –
  • Return type:None

set_chart_url(chart_url)

Set the chart URL.

  • Parameters:chart_url (str)
  • Return type:None

set_custom_properties(custom_properties)

Set the custom properties of the chart.

  • Parameters:custom_properties (Dict[str, str])
  • Return type:None

set_description(description)

Set the description of the chart.

  • Parameters:description (str)
  • Return type:None

set_display_name(display_name)

Set the display name of the chart.

  • Parameters:display_name (str)
  • Return type:None

set_external_url(external_url)

Set the external URL of the chart.

  • Parameters:external_url (str)
  • Return type:None

set_input_datasets(input_datasets)

Set the input datasets of the chart.

  • Parameters:input_datasets (Sequence[Union[str, DatasetUrn, Dataset]]) –
  • Return type:None

set_last_refreshed(last_refreshed)

Set the last refresh timestamp of the chart.

  • Parameters:last_refreshed (datetime)
  • Return type:None

set_title(title)

Set the display name of the chart.

Deprecated

Deprecated since version 1.2.0.7: Use set_display_name instead

  • Parameters:title (str)
  • Return type:None

property title : str

Get the display name of the chart.

Deprecated

Deprecated since version 1.2.0.7: Use display_name instead

property urn : ChartUrn

Get the entity’s URN.

  • Returns: The URN that uniquely identifies this entity.

DataJob

class datahub.sdk.datajob.DataJob(*, name, flow = None, flow_urn = None, platform_instance = None, display_name = None, description = None, external_url = None, custom_properties = None, created = None, last_modified = None, subtype = None, owners = None, links = None, tags = None, terms = None, domain = None, inlets = None, outlets = None, fine_grained_lineages = None, structured_properties = None, extra_aspects = None)

Bases: HasPlatformInstance, HasSubtype, HasContainer, HasOwnership, HasInstitutionalMemory, HasTags, HasTerms, HasDomain, HasStructuredProperties, Entity

Represents a data job in DataHub. A data job is an executable unit of a data pipeline, such as an Airflow task or a Spark job.

property created : datetime | None

Get the creation timestamp of the data job.

property custom_properties : Dict[str, str]

Get the custom properties of the data job.

property description : str | None

Get the description of the data job.

property display_name : str | None

Get the display name of the data job.

property env : str | None

Get the environment of the data job.

property external_url : str | None

Get the external URL of the data job.

property fine_grained_lineages : List[FineGrainedLineageClass]

property flow_urn : DataFlowUrn

Get the data flow associated with the data job.

classmethod get_urn_type()

Get the URN type for data jobs.

property inlets : List[DatasetUrn]

Get the inlets of the data job.

property last_modified : datetime | None

Get the last modification timestamp of the data job.

property name : str

Get the name of the data job.

property outlets : List[DatasetUrn]

Get the outlets of the data job.

set_created(created)

Set the creation timestamp of the data job.

  • Parameters:created (datetime)
  • Return type:None

set_custom_properties(custom_properties)

Set the custom properties of the data job.

  • Parameters:custom_properties (Dict[str, str])
  • Return type:None

set_description(description)

Set the description of the data job.

  • Parameters:description (str)
  • Return type:None

set_display_name(display_name)

Set the display name of the data job.

  • Parameters:display_name (str)
  • Return type:None

set_external_url(external_url)

Set the external URL of the data job.

  • Parameters:external_url (str)
  • Return type:None

set_fine_grained_lineages(lineages)

set_inlets(inlets)

Set the inlets of the data job.

  • Parameters:inlets (List[Union[str, DatasetUrn]]) –
  • Return type:None

set_last_modified(last_modified)

Set the last modification timestamp of the data job.

  • Parameters:last_modified (datetime)
  • Return type:None

set_outlets(outlets)

Set the outlets of the data job.

  • Parameters:outlets (List[Union[str, DatasetUrn]]) –
  • Return type:None

property urn : DataJobUrn

Get the entity’s URN.

  • Returns: The URN that uniquely identifies this entity.

DataFlow

class datahub.sdk.dataflow.DataFlow(*, name, platform, display_name = None, platform_instance = None, env = 'PROD', description = None, external_url = None, custom_properties = None, created = None, last_modified = None, subtype = None, owners = None, links = None, tags = None, terms = None, domain = None, parent_container = Unset.token, structured_properties = None, extra_aspects = None)

Bases: HasPlatformInstance, HasSubtype, HasOwnership, HasContainer, HasInstitutionalMemory, HasTags, HasTerms, HasDomain, HasStructuredProperties, Entity

Represents a dataflow in DataHub. A dataflow represents a collection of data, such as a table, view, or file. This class provides methods for managing dataflow metadata including schema, lineage, and various aspects like ownership, tags, and terms.

property created : datetime | None

Get the creation timestamp of the dataflow. :returns: The creation timestamp if set, None otherwise.

property custom_properties : Dict[str, str]

Get the custom properties of the dataflow. :returns: Dictionary of custom properties.

property description : str | None

Get the description of the dataflow. :returns: The description if set, None otherwise.

property display_name : str | None

Get the display name of the dataflow. :returns: The display name if set, None otherwise.

property env : str | FabricTypeClass | None

Get the environment of the dataflow.

property external_url : str | None

Get the external URL of the dataflow. :returns: The external URL if set, None otherwise.

classmethod get_urn_type()

Get the URN type for dataflows. :rtype: Type[DataFlowUrn] :returns: The DataflowUrn class.

property last_modified : datetime | None

Get the last modification timestamp of the dataflow. :returns: The last modification timestamp if set, None otherwise.

property name : str

Get the name of the dataflow. :returns: The name of the dataflow.

set_created(created)

Set the creation timestamp of the dataflow. :type created: datetime :param created: The creation timestamp to set.

  • Return type:None
  • Parameters:created (datetime)

set_custom_properties(custom_properties)

Set the custom properties of the dataflow. :type custom_properties: Dict[str, str] :param custom_properties: Dictionary of custom properties to set.

  • Return type:None
  • Parameters:custom_properties (Dict [str,str])

set_description(description)

Set the description of the dataflow. :type description: str :param description: The description to set. :rtype: None

NOTE

If called during ingestion, this will warn if overwriting a non-ingestion description.

  • Parameters:description (str)
  • Return type: None

set_display_name(display_name)

Set the display name of the dataflow. :type display_name: str :param display_name: The display name to set.

  • Return type:None
  • Parameters:display_name (str)

set_external_url(external_url)

Set the external URL of the dataflow. :type external_url: str :param external_url: The external URL to set.

  • Return type:None
  • Parameters:external_url (str)

set_last_modified(last_modified)

  • Parameters:last_modified (datetime)
  • Return type:None

property urn : DataFlowUrn

Get the entity’s URN.

  • Returns: The URN that uniquely identifies this entity.

AiContextInput

class datahub.sdk.semantic_model.AiContextInput(synonyms = None, instructions = None, examples = None, custom_instructions = None)

Bases: object

Input container for the first-class aiContext aspect.

The aspect is only emitted when at least one field carries content; an all-empty AiContextInput produces no aspect.

  • Parameters:
    • synonyms (Optional[List[str]])
    • instructions (Optional[str])
    • examples (Optional[List[str]])
    • custom_instructions (Optional[str])

custom_instructions : Optional[str] = None

examples : Optional[List[str]] = None

instructions : Optional[str] = None

synonyms : Optional[List[str]] = None

DialectExpressionInput

class datahub.sdk.semantic_model.DialectExpressionInput(expression, dialect = 'ANSI_SQL')

Bases: object

A single (dialect, expression) pair for a metric or field expression.

  • Parameters:

dialect : Union[str, DialectClass] = 'ANSI_SQL'

expression : str

SemanticFieldInput

class datahub.sdk.semantic_model.SemanticFieldInput(field_path, type, semantic_type, description = None, nullable = True, is_part_of_key = False, tags = None, expression = None, aggregation_function = None, is_time_dimension = False, ai_context = None)

Bases: object

A schema field plus its semantic annotation and optional AI context.

expression is required on the emitted semanticFieldAnnotation; when omitted it is auto-synthesized as f"{alias}.{field_path}" so the field references its own logical dataset by alias.

aggregation_function : Optional[str] = None

ai_context : Optional[AiContextInput] = None

description : Optional[str] = None

expression : Union[str, DialectExpressionInput, List[DialectExpressionInput], MetricExpressionClass, None] = None

field_path : str

is_part_of_key : bool = False

is_time_dimension : bool = False

nullable : bool = True

semantic_type : Union[str, SemanticFieldTypeClass]

tags : Optional[Sequence[Union[str, TagUrn, TagAssociationClass]]] = None

type : str

SemanticModel

class datahub.sdk.semantic_model.SemanticModel(*, platform, path, id, platform_instance = None, name = None, description = None, created = None, last_modified = None, native_definition = None, datasets = None, relationships = None, ai_context = None, owners = None, links = None, tags = None, terms = None, domain = None, structured_properties = None, extra_aspects = None)

Bases: HasPlatformInstance, HasOwnership, HasInstitutionalMemory, HasTags, HasTerms, HasDomain, HasStructuredProperties, Entity

A semantic model: a logical grouping of datasets with dimensional context.

The semantic model is the bridge between raw datasets and the business metrics calculated over them. Each logical dataset it exposes is its own dataset entity (subtype Semantic Model Dataset) carrying a semanticModelProperties back-reference; metrics point back at the model via metricInfo.semanticModel (the ModeledBy lineage edge).

The canonical lineage chain is:

Metric -> SemanticModel -> Logical Dataset -> Physical Dataset

expressed entirely by metricInfo.semanticModel (ModeledBy), semanticModelInfo.datasets (Contains), and each logical dataset’s own upstreamLineage. Do not populate metricUpstreams for semantic-model-backed metrics.

Server compatibility: requires a server build that includes the semanticModel/metric model (operator’s responsibility — no automatic check). See datahub.sdk.require_metrics_support() for an opt-in preflight helper.

add_dataset(dataset)

Attach a logical dataset to this model.

If dataset is a SemanticModelDataset, its semanticModelProperties.semanticModel back-reference is reconciled to this model’s URN (so the caller does not have to set it twice) and its alias is left as the source of truth for relationship join paths.

Insertion order is preserved across re-emits.

add_relationship(relationship)

property ai_context : AiContextClass | None

as_mcps(change_type='UPSERT')

Convert the entity’s aspects to MetadataChangeProposals.

property created : datetime | None

property datasets : List[str]

property description : str | None

classmethod get_urn_type()

Get the URN type for this entity class.

  • Return type:Type[SemanticModelUrn]
  • Returns: The URN type class that corresponds to this entity type.

property last_modified : datetime | None

property name : str

property native_definition : str | None

property relationships : List[SemanticModelRelationshipClass] | None

set_ai_context(ai_context)

set_created(created)

  • Parameters:created (datetime)
  • Return type:None

set_datasets(datasets)

set_description(description)

  • Parameters:description (str)
  • Return type:None

set_last_modified(last_modified)

  • Parameters:last_modified (datetime)
  • Return type:None

set_name(name)

  • Parameters:name (str)
  • Return type:None

set_native_definition(native_definition)

  • Parameters:native_definition (str)
  • Return type:None

set_relationships(relationships)

property urn : SemanticModelUrn

Get the entity’s URN.

  • Returns: The URN that uniquely identifies this entity.

SemanticModelDataset

class datahub.sdk.semantic_model.SemanticModelDataset(*, platform, name, semantic_model, alias, schema, platform_instance = None, env = 'PROD', description = None, view_definition = None, upstreams = None, owners = None, links = None, tags = None, terms = None, domain = None, structured_properties = None, extra_aspects = None)

Bases: Dataset

A logical dataset exposed by a SemanticModel.

This is a standard Dataset carrying the Semantic Model Dataset subtype and a semanticModelProperties back-reference to its owning semantic model. Per-field semantic metadata (semanticFieldAnnotation) and per-field AI hints (aiContext) are layered on each field’s schemaField URN and emitted on serialization alongside the dataset-anchored aspects.

The dataset name should encode <sm_path>.<sm_id>.<view_name> so logical datasets stay unique across semantic models.

Per-field semanticFieldAnnotation and field-level aiContext are create-only: they are field-anchored (on schemaField URNs), not part of the dataset aspect bag. A logical dataset shares the dataset entity type, so client.entities.get(...) hydrates it as a base Dataset and the annotations are not carried back on a read. To update one, rebuild a fresh SemanticModelDataset and re-attach its fields via the schema constructor kwarg rather than read-modify-writing the fetched Dataset.

Server compatibility: requires a server build that includes the semanticModel/metric model (operator’s responsibility — no automatic check). See datahub.sdk.require_metrics_support() for an opt-in preflight helper.

property alias : str

as_mcps(change_type='UPSERT')

Convert the entity’s aspects to MetadataChangeProposals.

SemanticModelRelationshipInput

class datahub.sdk.semantic_model.SemanticModelRelationshipInput(from_alias, from_columns, to_alias, to_columns, name = None, cardinality = None, ai_context = None)

Bases: object

A join path between two logical datasets in a semantic model.

from_alias/to_alias must match the alias of the corresponding logical datasets’ semanticModelProperties.

  • Parameters:
    • from_alias (str)
    • from_columns (List[str])
    • to_alias (str)
    • to_columns (List[str])
    • name (Optional[str])
    • cardinality (Optional[str])
    • ai_context (Optional[AiContextInput]) –

ai_context : Optional[AiContextInput] = None

cardinality : Optional[str] = None

from_alias : str

from_columns : List[str]

name : Optional[str] = None

to_alias : str

to_columns : List[str]

AiContextInput

class datahub.sdk.metric.AiContextInput(synonyms = None, instructions = None, examples = None, custom_instructions = None)

Bases: object

Input container for the first-class aiContext aspect.

The aspect is only emitted when at least one field carries content; an all-empty AiContextInput produces no aspect.

  • Parameters:
    • synonyms (Optional[List[str]])
    • instructions (Optional[str])
    • examples (Optional[List[str]])
    • custom_instructions (Optional[str])

custom_instructions : Optional[str] = None

examples : Optional[List[str]] = None

instructions : Optional[str] = None

synonyms : Optional[List[str]] = None

DialectExpressionInput

class datahub.sdk.metric.DialectExpressionInput(expression, dialect = 'ANSI_SQL')

Bases: object

A single (dialect, expression) pair for a metric or field expression.

  • Parameters:

dialect : Union[str, DialectClass] = 'ANSI_SQL'

expression : str

Metric

class datahub.sdk.metric.Metric(*, platform, path, id, semantic_model, platform_instance = None, name = None, description = None, created = None, last_modified = None, expression = None, derived_from = None, ai_context = None, owners = None, links = None, tags = None, terms = None, domain = None, structured_properties = None, extra_aspects = None)

Bases: HasPlatformInstance, HasOwnership, HasInstitutionalMemory, HasTags, HasTerms, HasDomain, HasStructuredProperties, Entity

A metric: a business measure calculated over a semantic model.

A semantic-model-backed metric points at its owning model via metricInfo.semanticModel (the ModeledBy lineage edge). Its lineage flows Metric -> SemanticModel -> Logical Dataset -> Physical Dataset; do not populate metricUpstreams for these metrics.

This builder emits semantic-model-backed metrics; semantic_model is required. Standalone/metricUpstreams metrics are out of scope for now.

metricRelationships is always emitted (even with empty derivedFrom) so hasParentMetric indexes as false. metricInfo.expression is optional and is omitted when not provided.

Server compatibility: requires a server build that includes the semanticModel/metric model (operator’s responsibility — no automatic check). See datahub.sdk.require_metrics_support() for an opt-in preflight helper.

add_derived_from(metric)

  • Parameters:metric (Union[str, MetricUrn]) –
  • Return type:None

property ai_context : AiContextClass | None

property created : datetime | None

property derived_from : List[DerivedMetricInputClass]

property description : str | None

property expression : MetricExpressionClass | None

classmethod get_urn_type()

Get the URN type for this entity class.

  • Return type:Type[MetricUrn]
  • Returns: The URN type class that corresponds to this entity type.

property last_modified : datetime | None

property name : str

property semantic_model : str | None

set_ai_context(ai_context)

set_created(created)

  • Parameters:created (datetime)
  • Return type:None

set_derived_from(derived_from)

  • Parameters:derived_from (Sequence[Union[str, MetricUrn]]) –
  • Return type:None

set_description(description)

  • Parameters:description (str)
  • Return type:None

set_expression(expression, *, default_dialect='ANSI_SQL')

set_last_modified(last_modified)

  • Parameters:last_modified (datetime)
  • Return type:None

set_name(name)

  • Parameters:name (str)
  • Return type:None

set_semantic_model(semantic_model)

property urn : MetricUrn

Get the entity’s URN.

  • Returns: The URN that uniquely identifies this entity.