Repository navigation
feat(client): Create a new entities client #583
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,7 @@ | |
| if TYPE_CHECKING: | ||
| from nemo_platform import AsyncNeMoPlatform | ||
| from nemo_platform_plugin.config import PlatformConfig | ||
| from nemo_platform_plugin.entities import EntityClient | ||
| from nemo_platform_plugin.entities import EntityClient, NemoEntityClient | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win Drop TYPE_CHECKING guard for
🔧 Proposed fix-if TYPE_CHECKING:
- from nemo_platform_plugin.entities import EntityClient, NemoEntityClient
+from nemo_platform_plugin.entities import NemoEntityClient
+
+if TYPE_CHECKING:
+ from nemo_platform_plugin.entities import EntityClient-def get_nemo_entity_client() -> "NemoEntityClient":
+def get_nemo_entity_client() -> NemoEntityClient:
...
- from nemo_platform_plugin.client_provider import get_async_nemo_client
- from nemo_platform_plugin.entities import NemoEntityClient
-
+ from nemo_platform_plugin.client_provider import get_async_nemo_client
+
return NemoEntityClient(get_async_nemo_client())As per path instructions for Also applies to: 65-85 🤖 Prompt for AI AgentsSource: Path instructions |
||
|
|
||
|
|
||
| def get_platform_config() -> "PlatformConfig": | ||
|
|
@@ -62,3 +62,24 @@ def get_entity_client() -> "EntityClient": | |
| "Ensure your Service subclass calls super().create_app() or " | ||
| "configure entity_client in the service." | ||
| ) | ||
|
|
||
|
|
||
| def get_nemo_entity_client() -> "NemoEntityClient": | ||
| """Return a NemoClient-backed :class:`NemoEntityClient`. | ||
|
|
||
| Unlike the sibling placeholders (``get_sdk_client``, ``get_entity_client``, | ||
| ``get_platform_config``), this has a real default implementation because | ||
| everything it needs lives in ``nemo_platform_plugin``: the client transport, | ||
| the env-based context/header builder (``client_provider``), and the entity | ||
| client itself — no ``nmp-core`` bits required. | ||
|
|
||
| The default builds an env-scoped client (``NMP_BASE_URL`` / ``NMP_PRINCIPAL`` | ||
| via ``client_provider.get_async_nemo_client``), which is the correct context | ||
| for task containers, background jobs, and controllers. For request handling, | ||
| ``Service`` still overrides this via ``app.dependency_overrides`` with a | ||
| request-scoped client (service-principal + on-behalf-of headers). | ||
| """ | ||
| from nemo_platform_plugin.client_provider import get_async_nemo_client | ||
| from nemo_platform_plugin.entities import NemoEntityClient | ||
|
|
||
| return NemoEntityClient(get_async_nemo_client()) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
fd client_provider.py --exec cat -n {}Repository: NVIDIA-NeMo/nemo-platform Length of output: 4649 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '\n## files\n'
git ls-files | rg '^(packages/nemo_platform_plugin/src/nemo_platform_plugin/(client|entities|dependencies)\.py|.*client_provider\.py|.*entities\.py)$'
for f in \
packages/nemo_platform_plugin/src/nemo_platform_plugin/client/client.py \
packages/nemo_platform_plugin/src/nemo_platform_plugin/entities.py \
packages/nemo_platform_plugin/src/nemo_platform_plugin/dependencies.py \
packages/nemo_platform_plugin/src/nemo_platform_plugin/client_provider.py
do
if [ -f "$f" ]; then
printf '\n## outline: %s\n' "$f"
ast-grep outline "$f" --view expanded || true
printf '\n## head: %s\n' "$f"
wc -l "$f"
fi
doneRepository: NVIDIA-NeMo/nemo-platform Length of output: 4762 🏁 Script executed: #!/bin/bash
set -euo pipefail
python3 - <<'PY'
from pathlib import Path
paths = [
Path("packages/nemo_platform_plugin/src/nemo_platform_plugin/client/client.py"),
Path("packages/nemo_platform_plugin/src/nemo_platform_plugin/entities.py"),
Path("packages/nemo_platform_plugin/src/nemo_platform_plugin/client_provider.py"),
Path("packages/nemo_platform_plugin/src/nemo_platform_plugin/dependencies.py"),
]
for p in paths:
if p.exists():
print(f"\n### {p} ({sum(1 for _ in p.open())} lines)")
for i, line in enumerate(p.open(), 1):
if any(k in line for k in ["class AsyncNemoClient", "class NemoClient", "def close", "def __aenter__", "def __aexit__", "def __init__", "class NemoEntityClient", "def get_async_nemo_client", "def get_nemo_entity_client", "async def", "httpx", "AsyncClient", "Client"]):
print(f"{i:4d}: {line.rstrip()}")
PYRepository: NVIDIA-NeMo/nemo-platform Length of output: 3559 🏁 Script executed: #!/bin/bash
set -euo pipefail
# Locate implementations and lifecycle hooks
rg -n --hidden --glob '!**/.git/**' \
-e 'class AsyncNemoClient|class NemoClient|def close|async def close|__aenter__|__aexit__|httpx\.AsyncClient|httpx\.Client|NemoEntityClient|get_async_nemo_client|get_nemo_entity_client' \
packages/nemo_platform_plugin/src/nemo_platform_pluginRepository: NVIDIA-NeMo/nemo-platform Length of output: 4751 🏁 Script executed: #!/bin/bash
set -euo pipefail
file=packages/nemo_platform_plugin/src/nemo_platform_plugin/entities/entity_client.py
wc -l "$file"
sed -n '1,240p' "$file"Repository: NVIDIA-NeMo/nemo-platform Length of output: 10511 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '\n## dependencies\n'
sed -n '1,140p' packages/nemo_platform_plugin/src/nemo_platform_plugin/dependencies.py
printf '\n## client ctor/close\n'
sed -n '433,490p' packages/nemo_platform_plugin/src/nemo_platform_plugin/client/client.pyRepository: NVIDIA-NeMo/nemo-platform Length of output: 5459 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '\n## entity client\n'
sed -n '1,240p' packages/nemo_platform_plugin/src/nemo_platform_plugin/entities/entity_client.py
printf '\n## dependencies\n'
sed -n '1,140p' packages/nemo_platform_plugin/src/nemo_platform_plugin/dependencies.py
printf '\n## async client lifecycle\n'
sed -n '433,490p' packages/nemo_platform_plugin/src/nemo_platform_plugin/client/client.pyRepository: NVIDIA-NeMo/nemo-platform Length of output: 15745 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '\n## call sites\n'
rg -n --hidden --glob '!**/.git/**' \
-e 'get_nemo_entity_client\(' \
-e 'NemoEntityClient\(' \
-e '\.close\(\)' \
packages/nemo_platform_plugin/src plugins services sdk e2e
printf '\n## dependency overrides / app wiring\n'
rg -n --hidden --glob '!**/.git/**' \
-e 'dependency_overrides' \
-e 'get_nemo_entity_client' \
-e 'yield .*NemoEntityClient|async def .*close' \
packages/nemo_platform_plugin/src plugins services sdk
printf '\n## nearby service lifecycle code\n'
fd -a 'service*.py' packages/nemo_platform_plugin/src services plugins sdk | head -n 50Repository: NVIDIA-NeMo/nemo-platform Length of output: 48877 Scope or close the async entity client 🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """Entity Store client package. | ||
|
|
||
| Re-exports the legacy Stainless-backed :class:`EntityClient` and shared entity | ||
| types (``entities.legacy``) so existing ``from nemo_platform_plugin.entities | ||
| import ...`` imports keep working, alongside the new NemoClient-backed | ||
| :class:`NemoEntityClient` (``entities.entity_client``). | ||
| """ | ||
|
|
||
| from nemo_platform_plugin.entities.entity_client import NemoEntityClient as NemoEntityClient | ||
| from nemo_platform_plugin.entities.legacy import EntityBase as EntityBase | ||
| from nemo_platform_plugin.entities.legacy import EntityClient as EntityClient | ||
| from nemo_platform_plugin.entities.legacy import EntityClientProtocol as EntityClientProtocol | ||
| from nemo_platform_plugin.entities.legacy import EntityConflictError as EntityConflictError | ||
| from nemo_platform_plugin.entities.legacy import EntityNotFoundError as EntityNotFoundError | ||
| from nemo_platform_plugin.entities.legacy import EntityStoreError as EntityStoreError | ||
| from nemo_platform_plugin.entities.legacy import EntityT as EntityT | ||
| from nemo_platform_plugin.entities.legacy import EntityToken as EntityToken | ||
| from nemo_platform_plugin.entities.legacy import EntityTypeDefault as EntityTypeDefault | ||
| from nemo_platform_plugin.entities.legacy import EntityTypeLike as EntityTypeLike | ||
| from nemo_platform_plugin.entities.legacy import EntityValidationError as EntityValidationError | ||
| from nemo_platform_plugin.entities.legacy import ListResponse as ListResponse | ||
| from nemo_platform_plugin.entities.legacy import PaginationInfo as PaginationInfo | ||
| from nemo_platform_plugin.entities.legacy import _convert_filter_obj_to_filter_str as _convert_filter_obj_to_filter_str | ||
| from nemo_platform_plugin.entities.legacy import _convert_sort_to_api_sort as _convert_sort_to_api_sort | ||
| from nemo_platform_plugin.entities.legacy import _get_entity_type as _get_entity_type | ||
| from nemo_platform_plugin.entities.legacy import parse_qualified_name as parse_qualified_name |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """Low-level typed HTTP clients for the Entity Store service. | ||
|
|
||
| Wraps the endpoint functions from ``entities.endpoints`` as direct methods via | ||
| the ``method()`` descriptor, following the files-service pattern. These are the | ||
| transport layer; the ergonomic, entity-model-aware client is | ||
| ``NemoEntityClient`` in ``entities.entity_client``. | ||
| """ | ||
|
|
||
| from nemo_platform_plugin.client.client import AsyncNemoClient, NemoClient | ||
| from nemo_platform_plugin.client.method import method | ||
| from nemo_platform_plugin.entities import endpoints | ||
|
|
||
|
|
||
| class _EntitiesMethods: | ||
| create_entity = method(endpoints.create_entity) | ||
| list_entities = method(endpoints.list_entities) | ||
| get_entity_by_name = method(endpoints.get_entity_by_name) | ||
| get_entity_by_id = method(endpoints.get_entity_by_id) | ||
| update_entity_by_name = method(endpoints.update_entity_by_name) | ||
| delete_entity_by_name = method(endpoints.delete_entity_by_name) | ||
|
|
||
|
|
||
| class EntitiesEndpointClient(_EntitiesMethods, NemoClient): | ||
| """Sync low-level client for the Entity Store API.""" | ||
|
|
||
|
|
||
| class AsyncEntitiesEndpointClient(_EntitiesMethods, AsyncNemoClient): | ||
| """Async low-level client for the Entity Store API.""" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """Typed endpoint definitions for the Entity Store service (generic routes). | ||
|
|
||
| Single source of truth for the HTTP contract of the generic entity routes. | ||
| Projects and workspaces routers are out of scope — the entity client only | ||
| uses the generic ``/entities`` routes. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from abc import abstractmethod | ||
|
|
||
| from nemo_platform_plugin.client.endpoint import delete, get, post, put | ||
| from nemo_platform_plugin.client.types import Paginated | ||
| from nemo_platform_plugin.entities.types import ( | ||
| DeleteResponse, | ||
| EntityCreateInput, | ||
| EntityResponse, | ||
| EntityUpdate, | ||
| ListEntitiesQueryParams, | ||
| ParentQueryParams, | ||
| ) | ||
|
|
||
|
|
||
| @post("/apis/entities/v2/workspaces/{workspace}/entities/{entity_type}") | ||
| @abstractmethod | ||
| def create_entity(*, workspace: str | None = None, entity_type: str, body: EntityCreateInput) -> EntityResponse: ... | ||
|
|
||
|
|
||
| @get("/apis/entities/v2/workspaces/{workspace}/entities/{entity_type}") | ||
| @abstractmethod | ||
| def list_entities( | ||
| *, workspace: str | None = None, entity_type: str, query_params: ListEntitiesQueryParams | None = None | ||
| ) -> Paginated[EntityResponse]: ... | ||
|
|
||
|
|
||
| @get("/apis/entities/v2/workspaces/{workspace}/entities/{entity_type}/{name}") | ||
| @abstractmethod | ||
| def get_entity_by_name( | ||
| *, workspace: str | None = None, entity_type: str, name: str, query_params: ParentQueryParams | None = None | ||
| ) -> EntityResponse: ... | ||
|
|
||
|
|
||
| @get("/apis/entities/v2/entities/{id}") | ||
| @abstractmethod | ||
| def get_entity_by_id(*, id: str) -> EntityResponse: ... | ||
|
|
||
|
|
||
| @put("/apis/entities/v2/workspaces/{workspace}/entities/{entity_type}/{name}") | ||
| @abstractmethod | ||
| def update_entity_by_name( | ||
| *, | ||
| workspace: str | None = None, | ||
| entity_type: str, | ||
| name: str, | ||
| body: EntityUpdate, | ||
| query_params: ParentQueryParams | None = None, | ||
| ) -> EntityResponse: ... | ||
|
|
||
|
|
||
| @delete("/apis/entities/v2/workspaces/{workspace}/entities/{entity_type}/{name}") | ||
| @abstractmethod | ||
| def delete_entity_by_name( | ||
| *, workspace: str | None = None, entity_type: str, name: str, query_params: ParentQueryParams | None = None | ||
| ) -> DeleteResponse: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
Don’t default-retry write requests without an idempotency guard.
This policy is now the default, and the retry loop replays request bodies. 502/503/504/429 can occur after backend processing, so POST/PATCH/PUT may be duplicated or surface false conflicts. Gate default retries to safe/idempotent methods, or require an
Idempotency-Keybefore retrying writes.🤖 Prompt for AI Agents