Skip to content

Commit c209c76

Browse files
authored
feat: add choiceset support to entities service (#1564)
1 parent a4a6cb9 commit c209c76

7 files changed

Lines changed: 387 additions & 4 deletions

File tree

packages/uipath-platform/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "uipath-platform"
3-
version = "0.1.26"
3+
version = "0.1.27"
44
description = "HTTP client library for programmatic access to UiPath Platform"
55
readme = { file = "README.md", content-type = "text/markdown" }
66
requires-python = ">=3.11"

packages/uipath-platform/src/uipath/platform/entities/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from ._entities_service import EntitiesService
77
from .entities import (
8+
ChoiceSetValue,
89
DataFabricEntityItem,
910
Entity,
1011
EntityField,
@@ -24,6 +25,7 @@
2425
)
2526

2627
__all__ = [
28+
"ChoiceSetValue",
2729
"DataFabricEntityItem",
2830
"EntitiesService",
2931
"Entity",

packages/uipath-platform/src/uipath/platform/entities/_entities_service.py

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json as json_module
12
import logging
23
from typing import Any, Dict, List, Optional, Type
34

@@ -24,6 +25,7 @@
2425
fetch_resolved_entities_async,
2526
)
2627
from .entities import (
28+
ChoiceSetValue,
2729
DataFabricEntityItem,
2830
Entity,
2931
EntityRecord,
@@ -282,6 +284,99 @@ async def list_entities_async(self) -> List[Entity]:
282284
entities_data = response.json()
283285
return [Entity.model_validate(entity) for entity in entities_data]
284286

287+
@traced(name="list_choicesets", run_type="uipath")
288+
def list_choicesets(self) -> List[Entity]:
289+
"""List all choice sets in Data Service.
290+
291+
Returns:
292+
List[Entity]: A list of all choice set entities.
293+
294+
Examples:
295+
List all choice sets::
296+
297+
choicesets = entities_service.list_choicesets()
298+
for cs in choicesets:
299+
print(f"{cs.display_name} ({cs.id})")
300+
"""
301+
spec = self._list_choicesets_spec()
302+
response = self.request(spec.method, spec.endpoint)
303+
return [Entity.model_validate(item) for item in response.json()]
304+
305+
@traced(name="list_choicesets", run_type="uipath")
306+
async def list_choicesets_async(self) -> List[Entity]:
307+
"""Asynchronously list all choice sets in Data Service.
308+
309+
Returns:
310+
List[Entity]: A list of all choice set entities.
311+
"""
312+
spec = self._list_choicesets_spec()
313+
response = await self.request_async(spec.method, spec.endpoint)
314+
return [Entity.model_validate(item) for item in response.json()]
315+
316+
@traced(name="get_choiceset_values", run_type="uipath")
317+
def get_choiceset_values(
318+
self,
319+
choiceset_id: str,
320+
start: int | None = None,
321+
limit: int | None = None,
322+
) -> List[ChoiceSetValue]:
323+
"""Get the values of a choice set by its ID.
324+
325+
Args:
326+
choiceset_id: The unique identifier of the choice set.
327+
start: Optional offset for pagination.
328+
limit: Optional page size for pagination.
329+
330+
Returns:
331+
List[ChoiceSetValue]: The values in the choice set, each containing
332+
id, name, display_name, and number_id.
333+
334+
Examples:
335+
Get all values in a choice set::
336+
337+
values = entities_service.get_choiceset_values("choiceset-id")
338+
for v in values:
339+
print(f"{v.number_id}: {v.display_name}")
340+
"""
341+
spec = self._get_choiceset_values_spec(choiceset_id, start=start, limit=limit)
342+
response = self.request(
343+
spec.method, spec.endpoint, params=spec.params, json=spec.json
344+
)
345+
data = response.json()
346+
raw_values = data.get("jsonValue", "[]")
347+
items = (
348+
json_module.loads(raw_values) if isinstance(raw_values, str) else raw_values
349+
)
350+
return [ChoiceSetValue.model_validate(item) for item in items]
351+
352+
@traced(name="get_choiceset_values", run_type="uipath")
353+
async def get_choiceset_values_async(
354+
self,
355+
choiceset_id: str,
356+
start: int | None = None,
357+
limit: int | None = None,
358+
) -> List[ChoiceSetValue]:
359+
"""Asynchronously get the values of a choice set by its ID.
360+
361+
Args:
362+
choiceset_id: The unique identifier of the choice set.
363+
start: Optional offset for pagination.
364+
limit: Optional page size for pagination.
365+
366+
Returns:
367+
List[ChoiceSetValue]: The values in the choice set.
368+
"""
369+
spec = self._get_choiceset_values_spec(choiceset_id, start=start, limit=limit)
370+
response = await self.request_async(
371+
spec.method, spec.endpoint, params=spec.params, json=spec.json
372+
)
373+
data = response.json()
374+
raw_values = data.get("jsonValue", "[]")
375+
items = (
376+
json_module.loads(raw_values) if isinstance(raw_values, str) else raw_values
377+
)
378+
return [ChoiceSetValue.model_validate(item) for item in items]
379+
285380
@traced(name="entity_list_records", run_type="uipath")
286381
def list_records(
287382
self,
@@ -1173,6 +1268,32 @@ def _delete_batch_spec(self, entity_key: str, record_ids: List[str]) -> RequestS
11731268
json=record_ids,
11741269
)
11751270

1271+
def _list_choicesets_spec(self) -> RequestSpec:
1272+
return RequestSpec(
1273+
method="GET",
1274+
endpoint=Endpoint("datafabric_/api/Entity/choiceset"),
1275+
)
1276+
1277+
def _get_choiceset_values_spec(
1278+
self,
1279+
choiceset_id: str,
1280+
start: int | None = None,
1281+
limit: int | None = None,
1282+
) -> RequestSpec:
1283+
params: dict[str, Any] = {}
1284+
if start is not None:
1285+
params["start"] = start
1286+
if limit is not None:
1287+
params["limit"] = limit
1288+
return RequestSpec(
1289+
method="POST",
1290+
endpoint=Endpoint(
1291+
f"datafabric_/api/EntityService/entity/{choiceset_id}/query_expansion"
1292+
),
1293+
params=params,
1294+
json={},
1295+
)
1296+
11761297
def _validate_sql_query(self, sql_query: str) -> None:
11771298
query = sql_query.strip().rstrip(";").strip()
11781299
if not query:

packages/uipath-platform/src/uipath/platform/entities/entities.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,25 @@ class SourceJoinCriteria(BaseModel):
222222
related_source_field_name: str = Field(alias="relatedSourceFieldName")
223223

224224

225+
class ChoiceSetValue(BaseModel):
226+
"""Model representing a single value within a choice set."""
227+
228+
model_config = ConfigDict(
229+
validate_by_name=True,
230+
validate_by_alias=True,
231+
)
232+
233+
id: str = Field(alias="Id")
234+
name: str = Field(alias="Name")
235+
display_name: str = Field(alias="DisplayName")
236+
number_id: int = Field(alias="NumberId")
237+
created_time: str | None = Field(default=None, alias="CreateTime")
238+
updated_time: str | None = Field(default=None, alias="UpdateTime")
239+
created_by: str | None = Field(default=None, alias="CreatedBy")
240+
updated_by: str | None = Field(default=None, alias="UpdatedBy")
241+
record_owner: str | None = Field(default=None, alias="RecordOwner")
242+
243+
225244
class EntityRecord(BaseModel):
226245
"""Model representing a record within an entity."""
227246

0 commit comments

Comments
 (0)