Skip to content

Expressions

Helpers that render Fabric expression language strings. Import them as expr:

from fabric_data_pipelines import expr

expr.parameter("run_date")
expr.activity_output("get_tables", "value")

fabric_data_pipelines.expressions

Helpers that render Fabric expression language strings.

Fabric pipelines use expressions such as @pipeline().parameters.x and @activity('name').output. Prefer these helpers over hard-coded strings so typos are caught early and the rendered form stays consistent.

Example::

from fabric_data_pipelines import expr

expr.parameter("run_date")
# '@pipeline().parameters.run_date'

expr.activity_output("get_tables")
# "@activity('get_tables').output"

Expr

Bases: str

A Fabric expression string that is also a plain str.

Subclassing str means an Expr can be passed anywhere a string field is accepted (SQL text, connection ids, notebook parameters, etc.).

parameter

parameter(name: str) -> Expr

Reference a pipeline parameter: @pipeline().parameters.<name>.

Example::

expr.parameter("run_date")
# '@pipeline().parameters.run_date'

variable

variable(name: str) -> Expr

Reference a pipeline variable: @variables('<name>').

Example::

expr.variable("row_count")
# "@variables('row_count')"

library_variable

library_variable(name: str) -> Expr

Reference a Variable Library value: @pipeline().libraryVariables.<name>.

Example::

expr.library_variable("Demo_ETL_Library_SourceDb")
# '@pipeline().libraryVariables.Demo_ETL_Library_SourceDb'

activity_output

activity_output(name: str, path: str = '') -> Expr

Reference an activity's output: @activity('<name>').output[.path].

Example::

expr.activity_output("get_tables")
# "@activity('get_tables').output"

expr.activity_output("lookup", "value")
# "@activity('lookup').output.value"

item

item(path: str = '') -> Expr

Reference the current ForEach item: @item()[.path].

Example::

expr.item()
# '@item()'

expr.item("name")
# '@item().name'

run_id

run_id() -> Expr

Reference the current pipeline run id: @pipeline().RunId.

pipeline_name

pipeline_name() -> Expr

Reference the current pipeline name: @pipeline().Pipeline.

interp

interp(expression: str) -> str

Wrap an expression for string interpolation inside SQL or text.

Fabric uses @{...} (without a leading @ on the outer string) when embedding expressions inside larger string literals.

Example::

f"EXEC usp_Lock @RunId = N'{expr.interp(expr.run_id())}';"
# "EXEC usp_Lock @RunId = N'@{pipeline().RunId}';"

equals

equals(left: Any, right: Any) -> Expr

Render @equals(left, right).

Example::

expr.equals(expr.parameter("full_load"), 1)
# '@equals(pipeline().parameters.full_load, 1)'

not_

not_(operand: Any) -> Expr

Render @not(operand).

Example::

expr.not_(expr.equals(expr.parameter("flag"), 0))

and_

and_(*operands: Any) -> Expr

Render @and(a, b, ...).

or_

or_(*operands: Any) -> Expr

Render @or(a, b, ...).

concat

concat(*parts: Any) -> Expr

Render @concat(a, b, ...).

bool_

bool_(value: bool) -> Expr

Render @bool(true) or @bool(false).

func

func(name: str, *args: Any) -> Expr

Render an arbitrary Fabric function: @name(arg1, arg2, ...).

Example::

expr.func("string", expr.parameter("n"))
# '@string(pipeline().parameters.n)'