MCPcopy Create free account
hub / github.com/microsoft/data-formulator / get_workspace

Function get_workspace

py-src/data_formulator/workspace_factory.py:129–163  ·  view source on GitHub ↗

Return the active :class:`Workspace` for *identity_id*. For local/Azure: uses WorkspaceManager with lazy creation. For ephemeral: creates a scratch workspace and materializes table data from ``_workspace_tables`` in the request body. The frontend (IndexedDB) owns all data and

(identity_id: str)

Source from the content-addressed store, hash-verified

127
128
129def get_workspace(identity_id: str) -> Workspace:
130 """
131 Return the active :class:`Workspace` for *identity_id*.
132
133 For local/Azure: uses WorkspaceManager with lazy creation.
134 For ephemeral: creates a scratch workspace and materializes table data
135 from ``_workspace_tables`` in the request body. The frontend (IndexedDB)
136 owns all data and sends it with every request; the backend writes it to
137 temp parquet files so agents/DuckDB can read normally.
138 """
139 ws_id = get_active_workspace_id()
140 if not ws_id:
141 raise ValueError("No active workspace. X-Workspace-Id header is required.")
142
143 backend = _get_backend()
144
145 if backend == "ephemeral":
146 from data_formulator.datalake.ephemeral_workspace import construct_scratch_workspace
147
148 # Extract workspace tables from the request body
149 workspace_tables = []
150 from flask import request
151 if request.is_json:
152 data = request.get_json(silent=True) or {}
153 workspace_tables = data.get("_workspace_tables") or []
154
155 return construct_scratch_workspace(identity_id, ws_id, workspace_tables)
156
157 mgr = get_workspace_manager(identity_id)
158
159 # Lazy creation: frontend generates the ID, backend creates on first use
160 if not mgr.workspace_exists(ws_id):
161 mgr.create_workspace(ws_id)
162
163 return mgr.open_workspace(ws_id, identity_id)

Callers 15

connector_import_dataFunction · 0.90
connector_refresh_dataFunction · 0.90
connector_import_groupFunction · 0.90
derive_dataFunction · 0.90
data_agent_streamingFunction · 0.90
refine_dataFunction · 0.90
request_code_explFunction · 0.90
request_chart_insightFunction · 0.90
generate_report_chatFunction · 0.90
refresh_derived_dataFunction · 0.90

Calls 8

get_active_workspace_idFunction · 0.85
_get_backendFunction · 0.85
get_workspace_managerFunction · 0.85
getMethod · 0.80
workspace_existsMethod · 0.45
create_workspaceMethod · 0.45
open_workspaceMethod · 0.45

Tested by

no test coverage detected