temporary_view

To define a view in Python, apply the @temporary_view decorator. Like the @table decorator, you can use views in Lakeflow Declarative Pipelines for either static or streaming datasets.

Note

The older dlt module used the @view decorator to defiine a temporary view. Databricks recommends using the pyspark.pipelines module (imported as dp) and the @temporary_view decorator to define temporary views.

The following is the syntax for defining views with Python:

Syntax

from pyspark import pipelines as dp

@dp.view(
  name="<name>",
  comment="<comment>")
@dp.expect(...)
def <function-name>():
    return (<query>)

Parameters

Parameter Type Description
function function Required. A function that returns an Apache Spark DataFrame or streaming DataFrame from a user-defined query.
name str The table name. If not provided, defaults to the function name.
comment str A description for the table.