Skip to content

Commit 0d6dae1

Browse files
Init
1 parent e7f6285 commit 0d6dae1

File tree

5 files changed

+425
-0
lines changed

5 files changed

+425
-0
lines changed

src/uipath/_services/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from .buckets_service import BucketsService
66
from .connections_service import ConnectionsService
77
from .context_grounding_service import ContextGroundingService
8+
from .entities_service import EntitiesService
89
from .folder_service import FolderService
910
from .jobs_service import JobsService
1011
from .llm_gateway_service import UiPathLlmChatService, UiPathOpenAIService
@@ -25,4 +26,5 @@
2526
"UiPathOpenAIService",
2627
"UiPathLlmChatService",
2728
"FolderService",
29+
"EntitiesService"
2830
]
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
from typing import List, Optional, Type, TypeVar
2+
3+
from pydantic import ValidationError, BaseModel
4+
5+
from .._config import Config
6+
from .._execution_context import ExecutionContext
7+
from ._base_service import BaseService
8+
from .._utils import infer_bindings, RequestSpec, Endpoint, header_folder
9+
from ..models.entities import EntityGetByIdResponse, EntityRecord
10+
from ..tracing import traced
11+
12+
T = TypeVar("T", bound=BaseModel)
13+
14+
class EntitiesService(BaseService):
15+
16+
def __init__(
17+
self,
18+
config: Config,
19+
execution_context: ExecutionContext
20+
) -> None:
21+
super().__init__(config=config, execution_context=execution_context)
22+
23+
@traced(name="entity_retrieve", run_type="uipath")
24+
def retrieve(
25+
self,
26+
entity_key: str) -> EntityGetByIdResponse:
27+
28+
spec = self._retrieve_spec(entity_key)
29+
response = self.request(spec.method, spec.endpoint)
30+
31+
return EntityGetByIdResponse.model_validate(response.json())
32+
33+
@traced(name="entity_retrieve", run_type="uipath")
34+
async def retrieve_async(
35+
self,
36+
entity_key: str) -> EntityGetByIdResponse:
37+
spec = self._retrieve_spec(entity_key)
38+
39+
response = await self.request_async(spec.method, spec.endpoint)
40+
41+
return EntityGetByIdResponse.model_validate(response.json())
42+
43+
@traced(name="entity_list_records", run_type="uipath")
44+
def list_records(
45+
self,
46+
entity_key: str,
47+
schema: Optional[Type[T]] = None, # Optional schema
48+
start: Optional[int] = None,
49+
limit: Optional[int] = None
50+
) -> List[EntityRecord]:
51+
52+
# Example method to generate the API request specification (mocked here)
53+
spec = self._list_records_spec(entity_key, start, limit)
54+
55+
# Make the HTTP request (assumes self.request exists)
56+
response = self.request(spec.method, spec.endpoint)
57+
58+
# Parse the response JSON and extract the "value" field
59+
records_data = response.json().get("value", [])
60+
61+
# Validate and wrap records
62+
validated_records = []
63+
for record in records_data:
64+
try:
65+
# Validate & wrap the record using EntityRecord.from_data
66+
validated_record = EntityRecord.from_data(data=record, model=schema)
67+
validated_records.append(validated_record)
68+
except ValueError as e:
69+
print(f"Failed to validate record: {record} => {e}")
70+
continue
71+
72+
return validated_records
73+
74+
def _retrieve_spec(
75+
self,
76+
entity_key: str,
77+
) -> RequestSpec:
78+
79+
return RequestSpec(
80+
method="GET",
81+
endpoint=Endpoint(f"datafabric_/api/Entity/{entity_key}"),
82+
)
83+
84+
def _list_records_spec(
85+
self,
86+
entity_key: str,
87+
start: Optional[int] = None,
88+
limit: Optional[int] = None,
89+
) -> RequestSpec:
90+
91+
return RequestSpec(
92+
method="GET",
93+
endpoint=Endpoint(f"datafabric_/api/EntityService/entity/{entity_key}/read?start={start}&limit={limit}"),
94+
)
95+
96+
def _create_spec(
97+
self,
98+
entity_key: str,
99+
) -> RequestSpec:
100+
101+
return RequestSpec(
102+
method="POST",
103+
endpoint=Endpoint(f"datafabric_/api/EntityService/entity/{entity_key}/insert-batch"),
104+
)
105+
106+
def _update_spec(
107+
self,
108+
entity_key: str,
109+
) -> RequestSpec:
110+
111+
return RequestSpec(
112+
method="PUT",
113+
endpoint=Endpoint(f"datafabric_/api/EntityService/entity/{entity_key}/update-batch"),
114+
)
115+
116+
def _delete_spec(
117+
self,
118+
entity_key: str,
119+
) -> RequestSpec:
120+
121+
return RequestSpec(
122+
method="DELETE",
123+
endpoint=Endpoint(f"datafabric_/api/EntityService/entity/{entity_key}/delete-batch"),
124+
)

src/uipath/_uipath.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
QueuesService,
2121
UiPathLlmChatService,
2222
UiPathOpenAIService,
23+
EntitiesService
2324
)
2425
from ._utils import setup_logging
2526
from ._utils.constants import (
@@ -132,3 +133,7 @@ def llm_openai(self) -> UiPathOpenAIService:
132133
@property
133134
def llm(self) -> UiPathLlmChatService:
134135
return UiPathLlmChatService(self._config, self._execution_context)
136+
137+
@property
138+
def entities(self) -> EntitiesService:
139+
return EntitiesService(self._config, self._execution_context)

0 commit comments

Comments
 (0)