Skip to content

Semantic Models

create_semantic_model(workspace, display_name, item_definition, *, description=None, folder=None, df=True)

Creates a new semantic model in the specified workspace.

Parameters:

Name Type Description Default
workspace str

The workspace name or ID.

required
display_name str

The display name of the semantic model.

required
item_definition Dict[str, Any]

The definition of the semantic model.

required
description Optional[str]

A description for the semantic model.

None
folder Optional[str]

The ID of the folder to create the semantic model in.

None
df Optional[bool]

If True or not provided, returns a DataFrame with flattened keys. If False, returns a list of dictionaries.

True

Returns:

Type Description
Union[DataFrame, Dict[str, Any], None]

The created semantic model details.

Examples:

create_semantic_model(
    workspace_id='123e4567-e89b-12d3-a456-426614174000',
    display_name='SalesDataModel',
    item_definition= {}, # Definition dict of the semantic model
    description='A semantic model for sales data',
    folder_id='456e7890-e12b-34d5-a678-9012345678901',
)
Source code in src/pyfabricops/items/semantic_models.py
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
@df
def create_semantic_model(
    workspace: str,
    display_name: str,
    item_definition: Dict[str, Any],
    *,
    description: Optional[str] = None,
    folder: Optional[str] = None,
    df: Optional[bool] = True,
) -> Union[DataFrame, Dict[str, Any], None]:
    """
    Creates a new semantic model in the specified workspace.

    Args:
        workspace (str): The workspace name or ID.
        display_name (str): The display name of the semantic model.
        item_definition (Dict[str, Any]): The definition of the semantic model.
        description (Optional[str]): A description for the semantic model.
        folder (Optional[str]): The ID of the folder to create the semantic model in.
        df (Optional[bool]): If True or not provided, returns a DataFrame with flattened keys.
            If False, returns a list of dictionaries.

    Returns:
        (Union[DataFrame, Dict[str, Any], None]): The created semantic model details.

    Examples:
        ```python
        create_semantic_model(
            workspace_id='123e4567-e89b-12d3-a456-426614174000',
            display_name='SalesDataModel',
            item_definition= {}, # Definition dict of the semantic model
            description='A semantic model for sales data',
            folder_id='456e7890-e12b-34d5-a678-9012345678901',
        )
        ```
    """
    workspace_id = resolve_workspace(workspace)

    payload = {'displayName': display_name, 'definition': item_definition}

    if description:
        payload['description'] = description

    if folder:
        folder_id = resolve_folder(workspace_id, folder)
        if folder_id:
            payload['folderId'] = folder_id

    return api_request(
        endpoint='/workspaces/' + workspace_id + '/semanticModels',
        method='post',
        payload=payload,
        support_lro=True,
    )

delete_semantic_model(workspace, semantic_model)

Delete a semantic model from the specified workspace.

Parameters:

Name Type Description Default
workspace str

The workspace name or ID.

required
semantic_model str

The name or ID of the semantic model to delete.

required

Returns:

Type Description
None

None

Examples:

delete_semantic_model('123e4567-e89b-12d3-a456-426614174000', '456e7890-e12b-34d5-a678-9012345678901')
Source code in src/pyfabricops/items/semantic_models.py
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
def delete_semantic_model(workspace: str, semantic_model: str) -> None:
    """
    Delete a semantic model from the specified workspace.

    Args:
        workspace (str): The workspace name or ID.
        semantic_model (str): The name or ID of the semantic model to delete.

    Returns:
        None

    Examples:
        ```python
        delete_semantic_model('123e4567-e89b-12d3-a456-426614174000', '456e7890-e12b-34d5-a678-9012345678901')
        ```
    """
    workspace_id = resolve_workspace(workspace)
    semantic_model_id = resolve_semantic_model(workspace, semantic_model)

    return api_request(
        endpoint='/workspaces/'
        + workspace_id
        + '/semanticModels/'
        + semantic_model_id,
        method='delete',
    )

get_semantic_model(workspace, semantic_model, *, df=True)

Retrieves a semantic model by its name or ID from the specified workspace.

Parameters:

Name Type Description Default
workspace_id str

The workspace ID.

required
semantic_model_id str

The ID of the semantic model.

required
df Optional[bool]

If True or not provided, returns a DataFrame with flattened keys. If False, returns a list of dictionaries.

True

Returns:

Type Description
Union[DataFrame, Dict[str, Any], None]

The semantic model details if found. If df=True, returns a DataFrame with flattened keys.

Examples:

get_semantic_model('123e4567-e89b-12d3-a456-426614174000', '123e4567-e89b-12d3-a456-426614174000')
Source code in src/pyfabricops/items/semantic_models.py
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
@df
def get_semantic_model(
    workspace: str, semantic_model: str, *, df: Optional[bool] = True
) -> Union[DataFrame, Dict[str, Any], None]:
    """
    Retrieves a semantic model by its name or ID from the specified workspace.

    Args:
        workspace_id (str): The workspace ID.
        semantic_model_id (str): The ID of the semantic model.
        df (Optional[bool]): If True or not provided, returns a DataFrame with flattened keys.
            If False, returns a list of dictionaries.

    Returns:
        (Union[DataFrame, Dict[str, Any], None]): The semantic model details if found. If `df=True`, returns a DataFrame with flattened keys.

    Examples:
        ```python
        get_semantic_model('123e4567-e89b-12d3-a456-426614174000', '123e4567-e89b-12d3-a456-426614174000')
        ```
    """
    workspace_id = resolve_workspace(workspace)
    semantic_model_id = resolve_semantic_model(workspace, semantic_model)
    return api_request(
        endpoint='/workspaces/'
        + workspace_id
        + '/semanticModels/'
        + semantic_model_id,
    )

get_semantic_model_definition(workspace, semantic_model)

Retrieves the definition of a semantic model by its name or ID from the specified workspace.

Parameters:

Name Type Description Default
workspace str

The workspace name or ID.

required
semantic_model str

The name or ID of the semantic model.

required

Returns:

Type Description
Union[Dict[str, Any], None]

The semantic model definition if found, otherwise None.

Examples:

get_semantic_model_definition(
    workspace_id='123e4567-e89b-12d3-a456-426614174000',
    semantic_model_id='456e7890-e12b-34d5-a678-9012345678901',
)
Source code in src/pyfabricops/items/semantic_models.py
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
def get_semantic_model_definition(
    workspace: str, semantic_model: str
) -> Union[Dict[str, Any], None]:
    """
    Retrieves the definition of a semantic model by its name or ID from the specified workspace.

    Args:
        workspace (str): The workspace name or ID.
        semantic_model (str): The name or ID of the semantic model.

    Returns:
        ( Union[Dict[str, Any], None]): The semantic model definition if found, otherwise None.

    Examples:
        ```python
        get_semantic_model_definition(
            workspace_id='123e4567-e89b-12d3-a456-426614174000',
            semantic_model_id='456e7890-e12b-34d5-a678-9012345678901',
        )
        ```
    """
    workspace_id = resolve_workspace(workspace)

    semantic_model_id = resolve_semantic_model(workspace, semantic_model)

    return api_request(
        endpoint='/workspaces/'
        + workspace_id
        + '/semanticModels/'
        + semantic_model_id
        + '/getDefinition',
        method='post',
        support_lro=True,
    )

get_semantic_model_id(workspace, semantic_model)

Retrieves the ID of a semantic model by its name from the specified workspace.

Parameters:

Name Type Description Default
workspace str

The workspace name or ID.

required
semantic_model str

The name of the semantic model.

required

Returns:

Type Description
Optional[str]

The ID of the semantic model if found, otherwise None.

Examples:

get_semantic_model_id('123e4567-e89b-12d3-a456-426614174000', 'SalesDataModel')
Source code in src/pyfabricops/items/semantic_models.py
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
def get_semantic_model_id(
    workspace: str, semantic_model: str
) -> Union[str, None]:
    """
    Retrieves the ID of a semantic model by its name from the specified workspace.

    Args:
        workspace (str): The workspace name or ID.
        semantic_model (str): The name of the semantic model.

    Returns:
        (Optional[str]): The ID of the semantic model if found, otherwise None.

    Examples:
        ```python
        get_semantic_model_id('123e4567-e89b-12d3-a456-426614174000', 'SalesDataModel')
        ```
    """
    workspace_id = resolve_workspace(workspace)
    if workspace_id is None:
        return None

    semantic_models = list_semantic_models(workspace_id, df=False)
    for semantic_model_ in semantic_models:
        if semantic_model_['displayName'] == semantic_model:
            return semantic_model_['id']
    return None

list_semantic_models(workspace, df=True)

Returns a list of semantic models in a specified workspace.

Parameters:

Name Type Description Default
workspace_id str

The ID of the workspace.

required
df Optional[bool]

If True or not provided, returns a DataFrame with flattened keys. If False, returns a list of dictionaries.

True

Returns:

Type Description
Union[DataFrame, List[Dict[str, Any]], None]

A list of semantic models or a DataFrame if df is True.

Source code in src/pyfabricops/items/semantic_models.py
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
@df
def list_semantic_models(
    workspace: str,
    df: Optional[bool] = True,
) -> Union[DataFrame, List[Dict[str, Any]], None]:
    """
    Returns a list of semantic models in a specified workspace.

    Args:
        workspace_id (str): The ID of the workspace.
        df (Optional[bool]): If True or not provided, returns a DataFrame with flattened keys.
            If False, returns a list of dictionaries.

    Returns:
        (Union[DataFrame, List[Dict[str, Any]], None]): A list of semantic models or a DataFrame if df is True.
    """
    return api_request(
        endpoint='/workspaces/'
        + resolve_workspace(workspace)
        + '/semanticModels',
        support_pagination=True,
    )

update_semantic_model(workspace, semantic_model, *, display_name=None, description=None, df=False)

Updates the properties of the specified semantic model.

Parameters:

Name Type Description Default
workspace str

The workspace name or ID.

required
semantic_model str

The ID of the semantic model to update.

required
display_name str

The new display name for the semantic model.

None
description str

The new description for the semantic model.

None
df Optional[bool]

If True or not provided, returns a DataFrame with flattened keys. If False, returns a list of dictionaries.

False

Returns:

Type Description
Union[DataFrame, Dict[str, Any], None]

The updated semantic model details if successful, otherwise None.

Examples:

update_semantic_model(
    workspace_id='123e4567-e89b-12d3-a456-426614174000',
    semantic_model_id='456e7890-e12b-34d5-a678-9012345678901',
    display_name='UpdatedDisplayName',
    description='Updated description'
)
Source code in src/pyfabricops/items/semantic_models.py
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
@df
def update_semantic_model(
    workspace: str,
    semantic_model: str,
    *,
    display_name: Optional[str] = None,
    description: Optional[str] = None,
    df: Optional[bool] = False,
) -> Union[DataFrame, Dict[str, Any], None]:
    """
    Updates the properties of the specified semantic model.

    Args:
        workspace (str): The workspace name or ID.
        semantic_model (str): The ID of the semantic model to update.
        display_name (str, optional): The new display name for the semantic model.
        description (str, optional): The new description for the semantic model.
        df (Optional[bool]): If True or not provided, returns a DataFrame with flattened keys.
            If False, returns a list of dictionaries.

    Returns:
        (Union[DataFrame, Dict[str, Any], None]): The updated semantic model details if successful, otherwise None.

    Examples:
        ```python
        update_semantic_model(
            workspace_id='123e4567-e89b-12d3-a456-426614174000',
            semantic_model_id='456e7890-e12b-34d5-a678-9012345678901',
            display_name='UpdatedDisplayName',
            description='Updated description'
        )
        ```
    """
    workspace_id = resolve_workspace(workspace)
    semantic_model_id = resolve_semantic_model(workspace, semantic_model)

    payload = {}

    if display_name:
        payload['displayName'] = display_name

    if description:
        payload['description'] = description

    return api_request(
        endpoint='/workspaces/'
        + workspace_id
        + '/semanticModels/'
        + semantic_model_id,
        method='patch',
        payload=payload,
    )

update_semantic_model_definition(workspace, semantic_model, item_definition, *, df=True)

Updates the definition of an existing semantic model in the specified workspace. If the semantic model does not exist, it returns None.

Parameters:

Name Type Description Default
workspace str

The workspace name or ID.

required
semantic_model str

The name or ID of the semantic model to update.

required
item_definition Dict[str, Any]

The new definition for the semantic model.

required
df Optional[bool]

If True or not provided, returns a DataFrame with flattened keys. If False, returns a list of dictionaries.

True

Returns:

Type Description
Union[Dict[str, Any], None]

The updated semantic model details if successful, otherwise None.

Examples:

update_semantic_model(
    workspace_id='123e4567-e89b-12d3-a456-426614174000',
    semantic_model_id='456e7890-e12b-34d5-a678-9012345678901',
    item_definition={...} # New definition dict of the semantic model
)
Source code in src/pyfabricops/items/semantic_models.py
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
@df
def update_semantic_model_definition(
    workspace: str,
    semantic_model: str,
    item_definition: Dict[str, Any],
    *,
    df: Optional[bool] = True,
) -> Union[Dict[str, Any], None]:
    """
    Updates the definition of an existing semantic model in the specified workspace.
    If the semantic model does not exist, it returns None.

    Args:
        workspace (str): The workspace name or ID.
        semantic_model (str): The name or ID of the semantic model to update.
        item_definition (Dict[str, Any]): The new definition for the semantic model.
        df (Optional[bool]): If True or not provided, returns a DataFrame with flattened keys.
            If False, returns a list of dictionaries.

    Returns:
        (Union[Dict[str, Any], None]): The updated semantic model details if successful, otherwise None.

    Examples:
        ```python
        update_semantic_model(
            workspace_id='123e4567-e89b-12d3-a456-426614174000',
            semantic_model_id='456e7890-e12b-34d5-a678-9012345678901',
            item_definition={...} # New definition dict of the semantic model
        )
        ```
    """
    workspace_id = resolve_workspace(workspace)
    semantic_model_id = resolve_semantic_model(workspace, semantic_model)
    params = {'updateMetadata': True}
    payload = {'definition': item_definition}
    return api_request(
        endpoint='/workspaces/'
        + workspace_id
        + '/semanticModels/'
        + semantic_model_id
        + '/updateDefinition',
        method='post',
        payload=payload,
        params=params,
        support_lro=True,
    )