Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/uipath-platform/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "uipath-platform"
version = "0.2.41"
version = "0.2.42"
description = "HTTP client library for programmatic access to UiPath Platform"
readme = { file = "README.md", content-type = "text/markdown" }
requires-python = ">=3.11"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,12 +323,26 @@ def list_entities(self) -> List[Entity]:
return self._schema.list_entities()

@traced(name="list_entities_v3", run_type="uipath")
def list_entities_v3(self) -> List[Entity]:
def list_entities_v3(self, include_fields: bool = True) -> List[Entity]:
"""List all entities via the v3 API.

Experimental v3 surface (serves Federated entities); see
`list_entities()` for parameter and return details.
`list_entities()` for return details.

Args:
include_fields (bool): When `False`, list the same entities without
their field schemas, which keeps the response and the traced span
small on tenants with many entities. `Entity.fields`,
`record_count` and the storage sizes are then `None`.

Examples:
Resolve an entity id by name::

entities = entities_service.list_entities_v3(include_fields=False)
ids = {entity.name: entity.id for entity in entities}
"""
if not include_fields:
return self._schema.list_entities_without_fields()
return self._schema.list_entities(use_v3=True)

@deprecated(
Expand Down Expand Up @@ -374,8 +388,10 @@ async def list_entities_async(self) -> List[Entity]:
return await self._schema.list_entities_async()

@traced(name="list_entities_v3", run_type="uipath")
async def list_entities_v3_async(self) -> List[Entity]:
async def list_entities_v3_async(self, include_fields: bool = True) -> List[Entity]:
"""Async variant of `list_entities_v3()`."""
if not include_fields:
return await self._schema.list_entities_without_fields_async()
return await self._schema.list_entities_async(use_v3=True)

@traced(name="list_choicesets", run_type="uipath")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,38 @@ async def list_entities_async(self, use_v3: bool = False) -> List[Entity]:
entities_data = response.json()
return [Entity.model_validate(entity) for entity in entities_data]

def list_entities_without_fields(self) -> List[Entity]:
"""Internal implementation; see `EntitiesService.list_entities_v3()`."""
entities: List[Entity] = []
skip = 0
top = 200

while True:
spec = self._list_entities_page_spec(skip=skip, top=top)
response = self.request(spec.method, spec.endpoint, params=spec.params)
page = response.json()["results"]
entities.extend(Entity.model_validate(entity) for entity in page)
if len(page) < top:
return entities
skip += top

async def list_entities_without_fields_async(self) -> List[Entity]:
"""Async variant of `list_entities_without_fields()`."""
entities: List[Entity] = []
skip = 0
top = 200

while True:
spec = self._list_entities_page_spec(skip=skip, top=top)
response = await self.request_async(
spec.method, spec.endpoint, params=spec.params
)
page = response.json()["results"]
entities.extend(Entity.model_validate(entity) for entity in page)
if len(page) < top:
return entities
skip += top

def list_choicesets(self) -> List[Entity]:
"""Internal implementation; see `EntitiesService.list_choicesets()`."""
spec = self._list_choicesets_spec()
Expand Down Expand Up @@ -235,6 +267,19 @@ def _list_entities_spec(use_v3: bool = False) -> RequestSpec:
endpoint=Endpoint(_schema_base(use_v3)),
)

@staticmethod
def _list_entities_page_spec(skip: int, top: int) -> RequestSpec:
"""Build the GET spec for one page of entities without their fields.

The v3 `paginated` route lists the same entities as `GET /v3/entities`
but never loads the field schemas. It accepts at most 200 per page.
"""
return RequestSpec(
method="GET",
endpoint=Endpoint(f"{_V3_ENTITIES}/paginated"),
params={"skip": skip, "top": top},
)

@staticmethod
def _list_choicesets_spec() -> RequestSpec:
"""Build the GET spec for listing all choice sets."""
Expand Down
84 changes: 84 additions & 0 deletions packages/uipath-platform/tests/services/test_entities_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2724,6 +2724,90 @@ async def test_list_entities_async(
entities = await service.list_entities_async()
assert len(entities) == 1

def test_list_entities_v3_includes_fields_by_default(
self,
httpx_mock: HTTPXMock,
service: EntitiesService,
base_url: str,
org: str,
tenant: str,
version: str,
) -> None:
httpx_mock.add_response(
url=f"{base_url}{org}{tenant}/datafabric_/api/v3/entities",
status_code=200,
json=[
{
"name": "Customers",
"displayName": "Customers",
"entityType": "Entity",
"fields": [],
"isRbacEnabled": False,
"id": "ent-1",
}
],
)
entities = service.list_entities_v3()
assert entities[0].fields == []

def test_list_entities_v3_without_fields_reads_every_page(
self,
httpx_mock: HTTPXMock,
service: EntitiesService,
base_url: str,
org: str,
tenant: str,
version: str,
) -> None:
rows = [
{
"name": f"Entity{i}",
"displayName": f"Entity{i}",
"entityType": "Entity",
"isRbacEnabled": False,
"id": f"ent-{i}",
}
for i in range(201)
]
for skip, page in [(0, rows[:200]), (200, rows[200:])]:
httpx_mock.add_response(
url=f"{base_url}{org}{tenant}/datafabric_/api/v3/entities/paginated?skip={skip}&top=200",
status_code=200,
json={"totalCount": 201, "results": page},
)
entities = service.list_entities_v3(include_fields=False)
assert [e.id for e in entities] == [row["id"] for row in rows]
assert all(e.fields is None for e in entities)

async def test_list_entities_v3_without_fields_async(
self,
httpx_mock: HTTPXMock,
service: EntitiesService,
base_url: str,
org: str,
tenant: str,
version: str,
) -> None:
httpx_mock.add_response(
url=f"{base_url}{org}{tenant}/datafabric_/api/v3/entities/paginated?skip=0&top=200",
status_code=200,
json={
"totalCount": 1,
"results": [
{
"name": "Customers",
"displayName": "Customers",
"entityType": "Entity",
"isRbacEnabled": False,
"id": "ent-1",
}
],
},
)
entities = await service.list_entities_v3_async(include_fields=False)
assert [e.name for e in entities] == ["Customers"]
assert entities[0].fields is None

async def test_list_records_async(
self,
httpx_mock: HTTPXMock,
Expand Down
2 changes: 1 addition & 1 deletion packages/uipath-platform/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/uipath/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading