Skip to content

build_runtime_context

Public callable

Build a standard runtime context dictionary for Fabric notebooks.

Parameters:

Name Type Description Default
dataset_name str

Logical dataset name (for example orders).

required
environment str

Deployment environment label (for example Sandbox).

required
source_table str

Source object name used in the run.

required
target_table str

Target object name used in the run.

required
notebook_name str | None

Notebook name if available.

None
run_id str | None

Pre-generated run id. When omitted, :func:generate_run_id is used.

None

Returns:

Type Description
dict

Notebook runtime context with run metadata.

Examples:

>>> from fabricops_kit.runtime import build_runtime_context
>>> build_runtime_context(
...     dataset_name="orders",
...     environment="Sandbox",
...     source_table="raw_orders",
...     target_table="clean_orders",
...     notebook_name="03_pc_orders_source_to_product",
... )
{'dataset_name': 'orders', ...}
Source code in src/fabricops_kit/runtime.py
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
def build_runtime_context(
    dataset_name: str,
    environment: str,
    source_table: str,
    target_table: str,
    notebook_name: str | None = None,
    run_id: str | None = None,
) -> dict:
    """Build a standard runtime context dictionary for Fabric notebooks.

    Parameters
    ----------
    dataset_name : str
        Logical dataset name (for example ``orders``).
    environment : str
        Deployment environment label (for example ``Sandbox``).
    source_table : str
        Source object name used in the run.
    target_table : str
        Target object name used in the run.
    notebook_name : str | None, optional
        Notebook name if available.
    run_id : str | None, optional
        Pre-generated run id. When omitted, :func:`generate_run_id` is used.

    Returns
    -------
    dict
        Notebook runtime context with run metadata.

    Examples
    --------
    >>> from fabricops_kit.runtime import build_runtime_context
    >>> build_runtime_context(
    ...     dataset_name="orders",
    ...     environment="Sandbox",
    ...     source_table="raw_orders",
    ...     target_table="clean_orders",
    ...     notebook_name="03_pc_orders_source_to_product",
    ... )  # doctest: +SKIP
    {'dataset_name': 'orders', ...}
    """
    resolved_notebook_name = notebook_name or _infer_notebook_name_from_runtime()
    return {
        "dataset_name": str(dataset_name),
        "environment": str(environment),
        "source_table": str(source_table),
        "target_table": str(target_table),
        "notebook_name": None if resolved_notebook_name is None else str(resolved_notebook_name),
        "run_id": str(run_id) if run_id else generate_run_id(str(dataset_name)),
        "started_at_utc": get_current_timestamp_utc(),
    }