From 448a2a93270681e349dac8a539a69f7f4ab5e336 Mon Sep 17 00:00:00 2001 From: svc-excavator-bot Date: Sun, 26 Jan 2025 09:06:10 +0000 Subject: [PATCH] Excavator: Upgrade API Version --- README.md | 64 +- .../v1/ontologies/models/SearchOrderByType.md | 11 + .../v2/ontologies/models/SearchOrderByType.md | 11 + .../ontologies/models/SearchOrderByV2Dict.md | 3 +- foundry/__init__.py | 35 +- foundry/_core/__init__.py | 3 + foundry/_core/api_client.py | 280 +++- foundry/_core/confidential_client_auth.py | 4 +- foundry/_core/public_client_auth.py | 4 +- foundry/_core/utils.py | 4 + foundry/_errors/__init__.py | 15 + foundry/_errors/connection_error.py | 28 + foundry/_errors/environment_not_configured.py | 5 +- foundry/_errors/not_authenticated.py | 5 +- foundry/_errors/palantir_exception.py | 17 + foundry/_errors/palantir_rpc_exception.py | 45 +- foundry/_errors/sdk_internal_error.py | 12 +- foundry/_errors/stream_error.py | 20 + foundry/_errors/timeout_error.py | 29 + foundry/_versions.py | 2 +- foundry/v1/client.py | 2 +- foundry/v1/datasets/branch.py | 545 ++++++- foundry/v1/datasets/client.py | 2 +- foundry/v1/datasets/dataset.py | 684 ++++++++- foundry/v1/datasets/file.py | 1015 ++++++++++++- foundry/v1/datasets/transaction.py | 430 +++++- foundry/v1/ontologies/action.py | 418 +++++- foundry/v1/ontologies/action_type.py | 357 ++++- foundry/v1/ontologies/client.py | 2 +- foundry/v1/ontologies/errors/__init__.py | 18 +- .../ontologies/errors/_invalid_order_type.py | 44 + ...type_does_not_support_nearest_neighbors.py | 40 + .../errors/_property_type_not_found.py | 47 + .../_search_vector_dimensions_differ.py | 40 + .../_too_many_nearest_neighbors_requested.py | 40 + foundry/v1/ontologies/models/__init__.py | 2 + .../models/_search_order_by_type.py | 21 + foundry/v1/ontologies/object_type.py | 694 ++++++++- foundry/v1/ontologies/ontology.py | 196 ++- foundry/v1/ontologies/ontology_object.py | 1278 ++++++++++++++++- foundry/v1/ontologies/query.py | 154 +- foundry/v1/ontologies/query_type.py | 357 ++++- foundry/v2/admin/client.py | 2 +- foundry/v2/admin/enrollment.py | 206 ++- foundry/v2/admin/group.py | 687 ++++++++- foundry/v2/admin/group_member.py | 489 ++++++- foundry/v2/admin/group_membership.py | 289 +++- foundry/v2/admin/host.py | 267 +++- foundry/v2/admin/marking.py | 421 +++++- foundry/v2/admin/marking_category.py | 327 ++++- foundry/v2/admin/marking_member.py | 497 ++++++- foundry/v2/admin/marking_role_assignment.py | 477 +++++- foundry/v2/admin/user.py | 811 ++++++++++- foundry/v2/aip_agents/agent.py | 341 ++++- foundry/v2/aip_agents/agent_version.py | 361 ++++- foundry/v2/aip_agents/client.py | 2 +- foundry/v2/aip_agents/content.py | 136 +- foundry/v2/aip_agents/session.py | 1065 +++++++++++++- foundry/v2/client.py | 2 +- foundry/v2/connectivity/client.py | 2 +- foundry/v2/connectivity/connection.py | 400 +++++- foundry/v2/connectivity/file_import.py | 879 +++++++++++- foundry/v2/connectivity/table_import.py | 713 ++++++++- foundry/v2/datasets/branch.py | 525 ++++++- foundry/v2/datasets/client.py | 2 +- foundry/v2/datasets/dataset.py | 364 ++++- foundry/v2/datasets/file.py | 925 +++++++++++- foundry/v2/datasets/transaction.py | 414 +++++- foundry/v2/filesystem/client.py | 2 +- foundry/v2/filesystem/folder.py | 469 +++++- foundry/v2/filesystem/project.py | 713 ++++++++- foundry/v2/filesystem/resource.py | 997 ++++++++++++- foundry/v2/filesystem/resource_role.py | 491 ++++++- foundry/v2/functions/client.py | 2 +- foundry/v2/functions/query.py | 344 ++++- foundry/v2/functions/value_type.py | 130 +- foundry/v2/functions/version_id.py | 138 +- foundry/v2/ontologies/action.py | 348 ++++- foundry/v2/ontologies/action_type.py | 357 ++++- foundry/v2/ontologies/attachment.py | 340 ++++- foundry/v2/ontologies/attachment_property.py | 595 +++++++- foundry/v2/ontologies/client.py | 2 +- foundry/v2/ontologies/linked_object.py | 583 +++++++- .../models/_search_order_by_type.py | 21 + .../models/_search_order_by_v2_dict.py | 6 +- foundry/v2/ontologies/object_type.py | 694 ++++++++- foundry/v2/ontologies/ontology.py | 202 ++- foundry/v2/ontologies/ontology_interface.py | 587 +++++++- foundry/v2/ontologies/ontology_object.py | 1025 ++++++++++++- foundry/v2/ontologies/ontology_object_set.py | 574 +++++++- foundry/v2/ontologies/query.py | 178 ++- foundry/v2/ontologies/query_type.py | 357 ++++- .../v2/ontologies/time_series_property_v2.py | 458 +++++- foundry/v2/orchestration/build.py | 600 +++++++- foundry/v2/orchestration/client.py | 2 +- foundry/v2/orchestration/schedule.py | 967 ++++++++++++- foundry/v2/orchestration/schedule_version.py | 216 ++- foundry/v2/streams/client.py | 2 +- foundry/v2/streams/dataset.py | 206 ++- foundry/v2/streams/stream.py | 816 ++++++++++- foundry/v2/third_party_applications/client.py | 2 +- .../third_party_application.py | 130 +- .../v2/third_party_applications/version.py | 621 +++++++- .../v2/third_party_applications/website.py | 292 +++- tests/auth/test_confidential_client.py | 15 + tests/auth/test_public_client.py | 12 + tests/conftest.py | 36 + tests/server.py | 56 + tests/test_api_client.py | 193 ++- tests/test_exception.py | 56 +- tests/test_utils.py | 8 + 111 files changed, 31020 insertions(+), 410 deletions(-) create mode 100644 docs/v1/ontologies/models/SearchOrderByType.md create mode 100644 docs/v2/ontologies/models/SearchOrderByType.md create mode 100644 foundry/_errors/connection_error.py create mode 100644 foundry/_errors/palantir_exception.py create mode 100644 foundry/_errors/stream_error.py create mode 100644 foundry/_errors/timeout_error.py create mode 100644 foundry/v1/ontologies/errors/_invalid_order_type.py create mode 100644 foundry/v1/ontologies/errors/_property_type_does_not_support_nearest_neighbors.py create mode 100644 foundry/v1/ontologies/errors/_property_type_not_found.py create mode 100644 foundry/v1/ontologies/errors/_search_vector_dimensions_differ.py create mode 100644 foundry/v1/ontologies/errors/_too_many_nearest_neighbors_requested.py create mode 100644 foundry/v1/ontologies/models/_search_order_by_type.py create mode 100644 foundry/v2/ontologies/models/_search_order_by_type.py create mode 100644 tests/conftest.py create mode 100644 tests/server.py diff --git a/README.md b/README.md index 9b251ebd..979d4d99 100644 --- a/README.md +++ b/README.md @@ -202,20 +202,40 @@ the [Pydantic error documentation](https://docs.pydantic.dev/latest/errors/error experience. See [Static Type Analysis](#static-types) below for more information. ### HTTP exceptions -When an HTTP error status is returned, a `PalantirRPCException` is thrown. +When an HTTP error status is returned, a `PalantirRPCException` is thrown. There are several +subclasses that be caught for more specific conditions, all of which inherit from +`PalantirRPCException`. + + +| Status Code | Error Class | +| ----------- | -------------------------- | +| 400 | `BadRequestError` | +| 401 | `UnauthorizedError` | +| 403 | `PermissionDeniedError` | +| 404 | `NotFoundError` | +| 422 | `UnprocessableEntityError` | +| 429 | `RateLimitError` | +| >=500,<600 | `InternalServerError` | +| Other | `PalantirRPCException` | ```python from foundry import PalantirRPCException +from foundry import NotFoundError +from foundry import RateLimitError try: api_response = foundry_client.datasets.Transaction.abort(dataset_rid, transaction_rid) ... +except NotFoundError as e: + print("Dataset or Transaction not found", e) +except RateLimitError as e: + print("We are aborting too many Transactions", e) except PalantirRPCException as e: - print("Another HTTP exception occurred: " + str(e)) + print("Another HTTP exception occurred", e) ``` -This exception will have the following properties. See the [Foundry API docs](https://www.palantir.com/docs/foundry/api/general/overview/errors) for details about the Foundry error information. +All HTTP exceptions will have the following properties. See the [Foundry API docs](https://www.palantir.com/docs/foundry/api/general/overview/errors) for details about the Foundry error information. | Property | Type | Description | | ----------------- | -----------------------| ------------------------------------------------------------------------------------------------------------------------------ | @@ -223,6 +243,20 @@ This exception will have the following properties. See the [Foundry API docs](ht | error_instance_id | str | The Palantir error instance ID. See the [Foundry API docs](https://www.palantir.com/docs/foundry/api/general/overview/errors). | | parameters | Dict[str, Any] | The Palantir error parameters. See the [Foundry API docs](https://www.palantir.com/docs/foundry/api/general/overview/errors). | +### Other exceptions +There are a handful of other exception classes that could be thrown when instantiating or using a client. + +| ErrorClass | Thrown Directly | Description | +| ------------------------ | --------------- | --------------------------------------------------------------------------------------------------------------------------------- | +| NotAuthenticated | Yes | You used either `ConfidentialClientAuth` or `PublicClientAuth` to make an API call without going through the OAuth process first. | +| ConnectionError | Yes | An issue occurred when connecting to the server. This also catches both `ProxyError` and `SSLError`. | +| ProxyError | Yes | An issue occurred when connecting to or authenticating with a proxy server. | +| SSLError | Yes | An SSL error occurred when connecting to the server. | +| TimeoutError | No | The request timed out. This catches both `ConnectTimeout` and `ReadTimeout`. | +| ConnectTimeout | Yes | The request timed out when attempting to connect to the server. | +| ReadTimeout | Yes | The server did not send any data in the allotted amount of time. | +| StreamConsumedError | Yes | The content of the given stream has already been consumed. | +| SDKInternalError | Yes | An unexpected issue occurred and should be reported. | ## Pagination @@ -251,26 +285,20 @@ while page.next_page_token: ## Streaming -This SDK supports optionally streaming binary data using a flag in the method definition. +This SDK supports streaming binary data using a separate streaming client accessible under +`with_streaming_response` on each Resource. To ensure the stream is closed, you need to use a context +manager when making a request with this client. ```python # Non-streaming response -with open("profile_picture.png", "rb") as f: +with open("profile_picture.png", "wb") as f: f.write(foundry_client.admin.User.profile_picture(user_id)) # Streaming response -with open("profile_picture.png", "rb") as f: - for chunk in foundry_client.admin.User.profile_picture(user_id, stream=True): - f.write(chunk) -``` - -This flag is available on all endpoints which return binary data. Additionally, you can set a desired `chunk_size` to read into memory before -the next chunk is given to you. By default, this value is set to None and chunks will be returned to you as they are received from the host. - -```python -with open("profile_picture.png", "rb") as f: - for chunk in foundry_client.admin.User.profile_picture(user_id, stream=True, chunk_size=1024): - f.write(chunk) +with open("profile_picture.png", "wb") as f: + with foundry_client.admin.User.with_streaming_response.profile_picture(user_id) as response: + for chunk in response.iter_bytes(): + f.write(chunk) ``` @@ -1401,6 +1429,7 @@ Namespace | Resource | Operation | HTTP request | - [SearchJsonQueryV2Dict](docs/v2/models/SearchJsonQueryV2Dict.md) - [SearchObjectsResponseV2](docs/v2/models/SearchObjectsResponseV2.md) - [SearchObjectsResponseV2Dict](docs/v2/models/SearchObjectsResponseV2Dict.md) +- [SearchOrderByType](docs/v2/models/SearchOrderByType.md) - [SearchOrderByV2Dict](docs/v2/models/SearchOrderByV2Dict.md) - [SearchOrderingV2Dict](docs/v2/models/SearchOrderingV2Dict.md) - [SelectedPropertyApiName](docs/v2/models/SelectedPropertyApiName.md) @@ -1811,6 +1840,7 @@ Namespace | Resource | Operation | HTTP request | - [SearchObjectsResponse](docs/v1/models/SearchObjectsResponse.md) - [SearchObjectsResponseDict](docs/v1/models/SearchObjectsResponseDict.md) - [SearchOrderByDict](docs/v1/models/SearchOrderByDict.md) +- [SearchOrderByType](docs/v1/models/SearchOrderByType.md) - [SearchOrderingDict](docs/v1/models/SearchOrderingDict.md) - [SelectedPropertyApiName](docs/v1/models/SelectedPropertyApiName.md) - [SharedPropertyTypeApiName](docs/v1/models/SharedPropertyTypeApiName.md) diff --git a/docs/v1/ontologies/models/SearchOrderByType.md b/docs/v1/ontologies/models/SearchOrderByType.md new file mode 100644 index 00000000..1facca80 --- /dev/null +++ b/docs/v1/ontologies/models/SearchOrderByType.md @@ -0,0 +1,11 @@ +# SearchOrderByType + +SearchOrderByType + +| **Value** | +| --------- | +| `"fields"` | +| `"relevance"` | + + +[[Back to Model list]](../../../../README.md#models-v1-link) [[Back to API list]](../../../../README.md#apis-v1-link) [[Back to README]](../../../../README.md) diff --git a/docs/v2/ontologies/models/SearchOrderByType.md b/docs/v2/ontologies/models/SearchOrderByType.md new file mode 100644 index 00000000..1fd953ef --- /dev/null +++ b/docs/v2/ontologies/models/SearchOrderByType.md @@ -0,0 +1,11 @@ +# SearchOrderByType + +SearchOrderByType + +| **Value** | +| --------- | +| `"fields"` | +| `"relevance"` | + + +[[Back to Model list]](../../../../README.md#models-v2-link) [[Back to API list]](../../../../README.md#apis-v2-link) [[Back to README]](../../../../README.md) diff --git a/docs/v2/ontologies/models/SearchOrderByV2Dict.md b/docs/v2/ontologies/models/SearchOrderByV2Dict.md index 7d2d5518..8b5942c7 100644 --- a/docs/v2/ontologies/models/SearchOrderByV2Dict.md +++ b/docs/v2/ontologies/models/SearchOrderByV2Dict.md @@ -1,10 +1,11 @@ # SearchOrderByV2Dict -Specifies the ordering of search results by a field and an ordering direction. +Specifies the ordering of search results by a field and an ordering direction or by relevance if scores are required in a nearestNeighbors query. By default `orderType` is set to `fields`. ## Properties | Name | Type | Required | Description | | ------------ | ------------- | ------------- | ------------- | +**orderType** | NotRequired[SearchOrderByType] | No | | **fields** | List[SearchOrderingV2Dict] | Yes | | diff --git a/foundry/__init__.py b/foundry/__init__.py index 640d095a..511e1635 100644 --- a/foundry/__init__.py +++ b/foundry/__init__.py @@ -13,12 +13,32 @@ # limitations under the License. +from foundry._core import ApiResponse from foundry._core import ConfidentialClientAuth from foundry._core import Config +from foundry._core import ResourceIterator +from foundry._core import StreamedApiResponse +from foundry._core import StreamingContextManager from foundry._core import UserTokenAuth +from foundry._errors import BadRequestError +from foundry._errors import ConnectionError +from foundry._errors import ConnectTimeout from foundry._errors import EnvironmentNotConfigured +from foundry._errors import InternalServerError from foundry._errors import NotAuthenticated +from foundry._errors import NotFoundError +from foundry._errors import PalantirException from foundry._errors import PalantirRPCException +from foundry._errors import PermissionDeniedError +from foundry._errors import ProxyError +from foundry._errors import RateLimitError +from foundry._errors import ReadTimeout +from foundry._errors import SDKInternalError +from foundry._errors import SSLError +from foundry._errors import StreamConsumedError +from foundry._errors import TimeoutError +from foundry._errors import UnauthorizedError +from foundry._errors import UnprocessableEntityError # The OpenAPI document version from the spec information # See https://swagger.io/specification/#info-object @@ -36,7 +56,20 @@ "ConfidentialClientAuth", "UserTokenAuth", "Config", - "NotAuthenticated", + "PalantirException", "EnvironmentNotConfigured", + "NotAuthenticated", + "ConnectionError", + "ProxyError", + "SSLError", "PalantirRPCException", + "BadRequestError", + "UnauthorizedError", + "PermissionDeniedError", + "NotFoundError", + "UnprocessableEntityError", + "RateLimitError", + "InternalServerError", + "SDKInternalError", + "StreamConsumedError", ] diff --git a/foundry/_core/__init__.py b/foundry/_core/__init__.py index 80855998..37fc9296 100644 --- a/foundry/_core/__init__.py +++ b/foundry/_core/__init__.py @@ -14,7 +14,10 @@ from foundry._core.api_client import ApiClient +from foundry._core.api_client import ApiResponse from foundry._core.api_client import RequestInfo +from foundry._core.api_client import StreamedApiResponse +from foundry._core.api_client import StreamingContextManager from foundry._core.auth_utils import Auth from foundry._core.binary_stream import BinaryStream from foundry._core.confidential_client_auth import ConfidentialClientAuth diff --git a/foundry/_core/api_client.py b/foundry/_core/api_client.py index 149169db..38161e43 100644 --- a/foundry/_core/api_client.py +++ b/foundry/_core/api_client.py @@ -13,17 +13,22 @@ # limitations under the License. +import functools import json import re import sys +from contextlib import contextmanager from dataclasses import dataclass from inspect import isclass from typing import Any from typing import Dict +from typing import Generic +from typing import Iterator from typing import List from typing import Optional from typing import Tuple from typing import Type +from typing import TypeVar from typing import Union from typing import cast from urllib.parse import quote @@ -31,15 +36,29 @@ import pydantic import requests import requests.adapters +from requests import Response from typing_extensions import deprecated from foundry._core.auth_utils import Auth from foundry._core.binary_stream import BinaryStream from foundry._core.config import Config from foundry._core.resource_iterator import ResourceIterator -from foundry._core.utils import remove_prefixes -from foundry._errors.palantir_rpc_exception import PalantirRPCException -from foundry._errors.sdk_internal_error import SDKInternalError +from foundry._core.utils import clean_hostname +from foundry._errors import BadRequestError +from foundry._errors import ConnectionError +from foundry._errors import ConnectTimeout +from foundry._errors import InternalServerError +from foundry._errors import NotFoundError +from foundry._errors import PalantirRPCException +from foundry._errors import PermissionDeniedError +from foundry._errors import ProxyError +from foundry._errors import RateLimitError +from foundry._errors import ReadTimeout +from foundry._errors import SDKInternalError +from foundry._errors import SSLError +from foundry._errors import StreamConsumedError +from foundry._errors import UnauthorizedError +from foundry._errors import UnprocessableEntityError from foundry._versions import __version__ _GLOBAL_ADAPTER = requests.adapters.HTTPAdapter() @@ -48,7 +67,22 @@ QueryParameters = Dict[str, Union[Any, List[Any]]] -_TYPE_ADAPTERS: Dict[Any, Any] = {} +@functools.cache +def _get_type_adapter(_type: Any) -> pydantic.TypeAdapter: + """Create a type adapter that can be used to serialize the given data to JSON. For example, + if the user provided a BaseModel class instance, call the "model_dump_json" method. Otherwise, + if the user provided a non-BaseModel type (e.g. a TypedDict) create a TypeAdapter from the + the type and serialize the data to JSON using dump_json(). + """ + + if isclass(_type) and issubclass(_type, pydantic.BaseModel): + # Return a "TypeAdapter" shim for a BaseModel since the API is not the same for dumping + # to JSON + return _BaseModelTypeAdapter(_type) # type: ignore + else: + # Create an instance of a type adapter. This has a non-trivial overhead according + # to the documentation so we do this once the first time we encounter this type + return pydantic.TypeAdapter(_type) @dataclass(frozen=True) @@ -62,6 +96,8 @@ class RequestInfo: body: Any body_type: Any request_timeout: Optional[int] + + # DEPRECATED: Remove the streaming details stream: bool = False chunk_size: Optional[int] = None @@ -125,12 +161,108 @@ def dump_json(self, data: Any, **kwargs: Dict[str, Any]): return self._type.model_dump_json(data, **kwargs).encode() # type: ignore +T = TypeVar("T") + + +class ApiResponse(Generic[T]): + def __init__(self, request_info: RequestInfo, response: Response): + self._response = response + self._request_info = request_info + + @property + def status_code(self) -> int: + return self._response.status_code + + def json(self): + content_type = self._response.headers.get("content-type") + if content_type is not None: + match = re.search(r"charset=([a-zA-Z\-\d]+)[\s;]?", content_type) + else: + match = None + + encoding = match.group(1) if match else "utf-8" + response_text = self._response.content.decode(encoding) + return json.loads(response_text) + + def decode(self) -> T: + if self._request_info.response_type is bytes: + # DEPRECATED + if self._request_info.stream: + return cast( + T, + BinaryStream( + self._response.iter_content(chunk_size=self._request_info.chunk_size) + ), + ) + else: + return cast(T, self._response.content) + elif self._request_info.response_type is None: + return cast(T, None) + + data = self.json() + + if self._request_info.response_type is Any: + return data + + type_adapter = _get_type_adapter(self._request_info.response_type) + return type_adapter.validate_python(data) + + +class StreamedApiResponse(Generic[T], ApiResponse[T]): + def __init__(self, request_info: RequestInfo, response: Response): + super().__init__(request_info, response) + + def iter_bytes(self, chunk_size: Optional[int] = None) -> Iterator[bytes]: + """ + :param chunk_size: The number of bytes that should be read into memory for each chunk. If set to None, the data will become available as it arrives in whatever size is sent from the host. + :type chunk_size: Optional[int] + """ + try: + return self._response.iter_content(chunk_size=chunk_size) + except requests.exceptions.StreamConsumedError as e: + raise StreamConsumedError(str(e)) from e + + +class StreamingContextManager(Generic[T]): + def __init__(self, request_info: RequestInfo, response: Response): + self._request_info = request_info + self._response = response + + def __enter__(self) -> StreamedApiResponse[T]: + return StreamedApiResponse[T](self._request_info, self._response) + + def __exit__( + self, + exc_type: Optional[Type[BaseException]], + exc_value: Optional[BaseException], + traceback: Optional[Any], + ) -> None: + self._response.close() + + +@contextmanager +def error_wrapping(): + """Use this to wrap errors from requests with our own errors.""" + try: + yield + except requests.exceptions.ProxyError as e: + raise ProxyError(str(e)) from e + except requests.exceptions.SSLError as e: + raise SSLError(str(e)) from e + except requests.exceptions.ConnectTimeout as e: + raise ConnectTimeout(str(e)) from e + except requests.exceptions.ConnectionError as e: + raise ConnectionError(str(e)) from e + except requests.exceptions.ReadTimeout as e: + raise ReadTimeout(str(e)) from e + + class ApiClient: """ The API client. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -142,7 +274,7 @@ def __init__( ): self._config = config = config or Config() self._auth = auth - self._hostname = remove_prefixes(hostname, ["https://", "http://"]) + self._hostname = clean_hostname(hostname) self._session = requests.Session() self._session.mount("http://", _GLOBAL_ADAPTER) @@ -186,41 +318,44 @@ def fetch_page( # pageSize will already be present in the query params dictionary query_params={"pageToken": next_page_token}, ), - ) + ).decode() return result.next_page_token, result.data or [] return ResourceIterator(paged_func=fetch_page) - def call_api(self, request_info: RequestInfo) -> Any: + def call_api(self, request_info: RequestInfo) -> ApiResponse[Any]: """Makes the HTTP request (synchronous)""" - res = self._session.request( - method=request_info.method, - url=self._create_url(request_info), - params=self._process_query_parameters(request_info.query_params), - data=self._serialize(request_info.body, request_info.body_type), - headers={ - "Authorization": "Bearer " + self._auth.get_token().access_token, - **request_info.header_params, - }, - stream=request_info.stream, - timeout=( - request_info.request_timeout - if request_info.request_timeout is not None - else self._config.timeout - ), - ) - - if res.status_code == 401: - res.raise_for_status() + with error_wrapping(): + res = self._session.request( + method=request_info.method, + url=self._create_url(request_info), + params=self._process_query_parameters(request_info.query_params), + data=self._serialize(request_info.body, request_info.body_type), + headers=self._create_headers(request_info), + # DEPRECATED + stream=request_info.stream, + timeout=self._get_timeout(request_info), + ) - if not 200 <= res.status_code <= 299: - try: - raise PalantirRPCException(res.json()) - except json.JSONDecodeError: - raise SDKInternalError("Unable to decode JSON error response: " + res.text) + self._check_for_errors(res) + return ApiResponse(request_info, res) + + def stream_api(self, request_info: RequestInfo) -> StreamingContextManager[Any]: + """Makes the HTTP request (synchronous) and returns a streamed result""" + with error_wrapping(): + res = self._session.request( + method=request_info.method, + url=self._create_url(request_info), + params=self._process_query_parameters(request_info.query_params), + data=self._serialize(request_info.body, request_info.body_type), + headers=self._create_headers(request_info), + stream=True, + timeout=self._get_timeout(request_info), + ) - return self._deserialize(res, request_info) + self._check_for_errors(res) + return StreamingContextManager(request_info, res) def _process_query_parameters(self, query_params: QueryParameters): result: List[Tuple[str, Any]] = [] @@ -236,6 +371,13 @@ def _process_query_parameters(self, query_params: QueryParameters): return result + def _get_timeout(self, request_info: RequestInfo) -> Union[int, float, None]: + return ( + request_info.request_timeout + if request_info.request_timeout is not None + else self._config.timeout + ) + def _create_url(self, request_info: RequestInfo) -> str: resource_path = request_info.resource_path path_params = request_info.path_params @@ -247,6 +389,38 @@ def _create_url(self, request_info: RequestInfo) -> str: return f"{self._config.scheme}://{self._hostname}/api{resource_path}" + def _create_headers(self, request_info: RequestInfo) -> Dict[str, Any]: + return { + "Authorization": "Bearer " + self._auth.get_token().access_token, + **request_info.header_params, + } + + def _check_for_errors(self, res: Response): + if 200 <= res.status_code <= 299: + return + + try: + error_json = res.json() + except json.JSONDecodeError: + raise SDKInternalError("Unable to decode JSON error response: " + res.text) + + if res.status_code == 400: + raise BadRequestError(error_json) + elif res.status_code == 401: + raise UnauthorizedError(error_json) + elif res.status_code == 403: + raise PermissionDeniedError(error_json) + elif res.status_code == 404: + raise NotFoundError(error_json) + elif res.status_code == 422: + raise UnprocessableEntityError(error_json) + elif res.status_code == 429: + raise RateLimitError(error_json) + elif 500 <= res.status_code <= 599: + raise InternalServerError(error_json) + else: + raise PalantirRPCException(error_json) + def _serialize(self, value: Any, value_type: Any) -> Optional[bytes]: """ Serialize the data passed in to JSON bytes. @@ -260,48 +434,10 @@ def _serialize(self, value: Any, value_type: Any) -> Optional[bytes]: if value_type is Any: json_bytes = json.dumps(value).encode() else: - type_adapter = self._get_type_adapter(value_type) + type_adapter = _get_type_adapter(value_type) # Use "exclude_unset" to remove optional inputs that weren't explicitely set # Use "by_alias" to use the expected field name rather than the class property name json_bytes = type_adapter.dump_json(value, exclude_unset=True, by_alias=True) return json_bytes - - def _deserialize(self, res: requests.Response, request_info: RequestInfo) -> Any: - if request_info.response_type is bytes: - if request_info.stream: - return BinaryStream(res.iter_content(chunk_size=request_info.chunk_size)) - else: - return res.content - elif request_info.response_type is None: - return None - - content_type = res.headers.get("content-type") - if content_type is not None: - match = re.search(r"charset=([a-zA-Z\-\d]+)[\s;]?", content_type) - else: - match = None - - encoding = match.group(1) if match else "utf-8" - response_text = res.content.decode(encoding) - - data = json.loads(response_text) - - if request_info.response_type is Any: - return data - - type_adapter = self._get_type_adapter(request_info.response_type) - return type_adapter.validate_python(data) - - @staticmethod - def _get_type_adapter(_type: Any): - if _type not in _TYPE_ADAPTERS: - if isclass(_type) and issubclass(_type, pydantic.BaseModel): - _TYPE_ADAPTERS[_type] = _BaseModelTypeAdapter(_type) # type: ignore - else: - # Create an instance of a type adapter. This has a non-trivial overhead according - # to the documentation so we do this once the first time we encounter this type - _TYPE_ADAPTERS[_type] = pydantic.TypeAdapter(_type) - - return _TYPE_ADAPTERS[_type] diff --git a/foundry/_core/confidential_client_auth.py b/foundry/_core/confidential_client_auth.py index 07148030..172c4830 100644 --- a/foundry/_core/confidential_client_auth.py +++ b/foundry/_core/confidential_client_auth.py @@ -26,7 +26,7 @@ from foundry._core.oauth import SignOutResponse from foundry._core.oauth_utils import ConfidentialClientOAuthFlowProvider from foundry._core.oauth_utils import OAuthToken -from foundry._core.utils import remove_prefixes +from foundry._core.utils import clean_hostname from foundry._errors.not_authenticated import NotAuthenticated @@ -104,7 +104,7 @@ def _run_with_attempted_refresh( @property def url(self) -> str: - return remove_prefixes(self._hostname, ["https://", "http://"]) + return clean_hostname(self._hostname) def _refresh_token(self) -> None: self._token = self._server_oauth_flow_provider.get_token() diff --git a/foundry/_core/public_client_auth.py b/foundry/_core/public_client_auth.py index be6cdb9e..b2530b74 100644 --- a/foundry/_core/public_client_auth.py +++ b/foundry/_core/public_client_auth.py @@ -27,7 +27,7 @@ from foundry._core.oauth_utils import AuthorizeRequest from foundry._core.oauth_utils import OAuthToken from foundry._core.oauth_utils import PublicClientOAuthFlowProvider -from foundry._core.utils import remove_prefixes +from foundry._core.utils import clean_hostname from foundry._errors.not_authenticated import NotAuthenticated from foundry._errors.sdk_internal_error import SDKInternalError @@ -110,7 +110,7 @@ def _run_with_attempted_refresh( @property def url(self) -> str: - return remove_prefixes(self._hostname, ["https://", "http://"]) + return clean_hostname(self._hostname) def sign_in(self) -> str: self._auth_request = self._server_oauth_flow_provider.generate_auth_request() diff --git a/foundry/_core/utils.py b/foundry/_core/utils.py index 658005db..9be4ab9a 100644 --- a/foundry/_core/utils.py +++ b/foundry/_core/utils.py @@ -58,6 +58,10 @@ def remove_prefixes(text: str, prefixes: List[str]): return text +def clean_hostname(hostname: str) -> str: + return remove_prefixes(hostname.strip("/"), ["https://", "http://"]) + + AnyCallableT = TypeVar("AnyCallableT", bound=Callable[..., Any]) diff --git a/foundry/_errors/__init__.py b/foundry/_errors/__init__.py index 43247eb5..8d4d6ec8 100644 --- a/foundry/_errors/__init__.py +++ b/foundry/_errors/__init__.py @@ -13,8 +13,23 @@ # limitations under the License. +from foundry._errors.connection_error import ConnectionError +from foundry._errors.connection_error import ProxyError +from foundry._errors.connection_error import SSLError from foundry._errors.environment_not_configured import EnvironmentNotConfigured from foundry._errors.not_authenticated import NotAuthenticated +from foundry._errors.palantir_exception import PalantirException +from foundry._errors.palantir_rpc_exception import BadRequestError +from foundry._errors.palantir_rpc_exception import InternalServerError +from foundry._errors.palantir_rpc_exception import NotFoundError from foundry._errors.palantir_rpc_exception import PalantirRPCException +from foundry._errors.palantir_rpc_exception import PermissionDeniedError +from foundry._errors.palantir_rpc_exception import RateLimitError +from foundry._errors.palantir_rpc_exception import UnauthorizedError +from foundry._errors.palantir_rpc_exception import UnprocessableEntityError from foundry._errors.sdk_internal_error import SDKInternalError from foundry._errors.sdk_internal_error import handle_unexpected +from foundry._errors.stream_error import StreamConsumedError +from foundry._errors.timeout_error import ConnectTimeout +from foundry._errors.timeout_error import ReadTimeout +from foundry._errors.timeout_error import TimeoutError diff --git a/foundry/_errors/connection_error.py b/foundry/_errors/connection_error.py new file mode 100644 index 00000000..ed3aa2c7 --- /dev/null +++ b/foundry/_errors/connection_error.py @@ -0,0 +1,28 @@ +# Copyright 2024 Palantir Technologies, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +from foundry._errors.palantir_exception import PalantirException + + +class ConnectionError(PalantirException): + """An issue occurred when connecting to the server. This catches both ProxyError and SSLError.""" + + +class ProxyError(ConnectionError): + """An issue occurred when connecting to or authenticating with a proxy server.""" + + +class SSLError(ConnectionError): + """An SSL error occurred when connecting to the server.""" diff --git a/foundry/_errors/environment_not_configured.py b/foundry/_errors/environment_not_configured.py index dc77143b..ca914708 100644 --- a/foundry/_errors/environment_not_configured.py +++ b/foundry/_errors/environment_not_configured.py @@ -13,6 +13,9 @@ # limitations under the License. -class EnvironmentNotConfigured(Exception): +from foundry._errors.palantir_exception import PalantirException + + +class EnvironmentNotConfigured(PalantirException): def __init__(self, message: str) -> None: super().__init__(message) diff --git a/foundry/_errors/not_authenticated.py b/foundry/_errors/not_authenticated.py index 188674d4..64d09679 100644 --- a/foundry/_errors/not_authenticated.py +++ b/foundry/_errors/not_authenticated.py @@ -13,5 +13,8 @@ # limitations under the License. -class NotAuthenticated(Exception): +from foundry._errors.palantir_exception import PalantirException + + +class NotAuthenticated(PalantirException): pass diff --git a/foundry/_errors/palantir_exception.py b/foundry/_errors/palantir_exception.py new file mode 100644 index 00000000..795fc101 --- /dev/null +++ b/foundry/_errors/palantir_exception.py @@ -0,0 +1,17 @@ +# Copyright 2024 Palantir Technologies, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +class PalantirException(Exception): + """The root exception class all others inherit from.""" diff --git a/foundry/_errors/palantir_rpc_exception.py b/foundry/_errors/palantir_rpc_exception.py index a57ad075..b423da75 100644 --- a/foundry/_errors/palantir_rpc_exception.py +++ b/foundry/_errors/palantir_rpc_exception.py @@ -17,14 +17,57 @@ from typing import Any from typing import Dict +from foundry._errors.palantir_exception import PalantirException + def format_error_message(fields: Dict[str, Any]) -> str: return json.dumps(fields, sort_keys=True, indent=4, default=str) -class PalantirRPCException(Exception): +class PalantirRPCException(PalantirException): def __init__(self, error_metadata: Dict[str, Any]): super().__init__(format_error_message(error_metadata)) self.name = error_metadata.get("errorName") self.parameters = error_metadata.get("parameters") self.error_instance_id = error_metadata.get("errorInstanceId") + + +class BadRequestError(PalantirRPCException): + """ + There was an issue with the request. This error is thrown if a 400 status code is returned. + """ + + +class UnauthorizedError(PalantirRPCException): + """ + The authorization header is missing or invalid. This error is thrown if a 401 status code is returned. + """ + + +class PermissionDeniedError(PalantirRPCException): + """ + You are missing the necessary permissions to complete your request. This error is thrown if a + 403 status code is returned. + """ + + +class NotFoundError(PalantirRPCException): + """A Resource was not found. This error is thrown if a 404 status code is returned.""" + + +class UnprocessableEntityError(PalantirRPCException): + """ + One or more of the request's arguments are invalid. This error is thrown if a 422 status code + is returned. + """ + + +class RateLimitError(PalantirRPCException): + """ + The service is experiencing too many requests. Retry your request shortly and reduce your + request rate. This error is thrown if a 429 status code is returned. + """ + + +class InternalServerError(PalantirRPCException): + """An error occurred within the service. This error is thrown if a 5XX status code is returned.""" diff --git a/foundry/_errors/sdk_internal_error.py b/foundry/_errors/sdk_internal_error.py index 3305c75c..7ad098dd 100644 --- a/foundry/_errors/sdk_internal_error.py +++ b/foundry/_errors/sdk_internal_error.py @@ -23,10 +23,8 @@ from pydantic import __version__ as __pydantic__version__ from pydantic_core import __version__ as __pydantic_core_version__ from requests import __version__ as __requests_version__ -from requests.exceptions import ConnectionError -from requests.exceptions import HTTPError -from foundry._errors.palantir_rpc_exception import PalantirRPCException +from foundry._errors.palantir_exception import PalantirException from foundry._versions import __openapi_document_version__ from foundry._versions import __version__ @@ -39,12 +37,8 @@ def validate(*args, **kwargs): try: return __func(*args, **kwargs) except ( - PalantirRPCException, - SDKInternalError, + PalantirException, pydantic.ValidationError, - ConnectionError, - # We throw an HTTPError if there is a 401 status code response - HTTPError, ) as e: # pass through these exceptions raise e @@ -54,7 +48,7 @@ def validate(*args, **kwargs): return validate # type: ignore -class SDKInternalError(Exception): +class SDKInternalError(PalantirException): def __init__(self, msg: str) -> None: self.msg = msg diff --git a/foundry/_errors/stream_error.py b/foundry/_errors/stream_error.py new file mode 100644 index 00000000..a2496bbe --- /dev/null +++ b/foundry/_errors/stream_error.py @@ -0,0 +1,20 @@ +# Copyright 2024 Palantir Technologies, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +from foundry._errors.palantir_exception import PalantirException + + +class StreamConsumedError(PalantirException): + """The content of the given stream has already been consumed.""" diff --git a/foundry/_errors/timeout_error.py b/foundry/_errors/timeout_error.py new file mode 100644 index 00000000..9ad344f9 --- /dev/null +++ b/foundry/_errors/timeout_error.py @@ -0,0 +1,29 @@ +# Copyright 2024 Palantir Technologies, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +from foundry._errors.connection_error import ConnectionError +from foundry._errors.palantir_exception import PalantirException + + +class TimeoutError(PalantirException): + """The request timed out. This error will catch both ConnectTimeout and ReadTimeout.""" + + +class ConnectTimeout(ConnectionError, TimeoutError): + """The request timed out when attempting to connect to the server.""" + + +class ReadTimeout(TimeoutError): + """The server did not send any data in the allotted amount of time.""" diff --git a/foundry/_versions.py b/foundry/_versions.py index 2c0fdac6..3cc0ea81 100644 --- a/foundry/_versions.py +++ b/foundry/_versions.py @@ -17,4 +17,4 @@ # using the autorelease bot __version__ = "0.0.0" -__openapi_document_version__ = "1.1044.0" +__openapi_document_version__ = "1.1045.0" diff --git a/foundry/v1/client.py b/foundry/v1/client.py index 530d8ed9..63643e74 100644 --- a/foundry/v1/client.py +++ b/foundry/v1/client.py @@ -24,7 +24,7 @@ class FoundryClient: The Foundry V1 API client. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ diff --git a/foundry/v1/datasets/branch.py b/foundry/v1/datasets/branch.py index 58099820..dd6d1a5a 100644 --- a/foundry/v1/datasets/branch.py +++ b/foundry/v1/datasets/branch.py @@ -25,10 +25,12 @@ from typing_extensions import TypedDict from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo from foundry._core import ResourceIterator +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v1.core.models._page_size import PageSize @@ -45,7 +47,7 @@ class BranchClient: The API client for the Branch Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -56,6 +58,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _BranchClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _BranchClientRaw(auth=auth, hostname=hostname, config=config) @maybe_ignore_preview @pydantic.validate_call @@ -111,7 +117,7 @@ def create( response_type=Branch, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -153,7 +159,7 @@ def delete( response_type=None, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -197,7 +203,7 @@ def get( response_type=Branch, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -277,8 +283,273 @@ def page( """ warnings.warn( - "The BranchClient.page(...) method has been deprecated. Please use BranchClient.list(...) instead.", + "The client.datasets.Branch.page(...) method has been deprecated. Please use client.datasets.Branch.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v1/datasets/{datasetRid}/branches", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={ + "datasetRid": dataset_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListBranchesResponse, + request_timeout=request_timeout, + ), + ).decode() + + +class _BranchClientRaw: + """ + The API client for the Branch Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def create( + self, + dataset_rid: DatasetRid, + *, + branch_id: BranchId, + transaction_rid: Optional[TransactionRid] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Branch]: + """ + Creates a branch on an existing dataset. A branch may optionally point to a (committed) transaction. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:datasets-write`. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param branch_id: + :type branch_id: BranchId + :param transaction_rid: + :type transaction_rid: Optional[TransactionRid] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Branch] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v1/datasets/{datasetRid}/branches", + query_params={}, + path_params={ + "datasetRid": dataset_rid, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "branchId": branch_id, + "transactionRid": transaction_rid, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "branchId": BranchId, + "transactionRid": Optional[TransactionRid], + }, + ), + response_type=Branch, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def delete( + self, + dataset_rid: DatasetRid, + branch_id: BranchId, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[None]: + """ + Deletes the Branch with the given BranchId. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:datasets-write`. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param branch_id: branchId + :type branch_id: BranchId + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[None] + """ + + return self._api_client.call_api( + RequestInfo( + method="DELETE", + resource_path="/v1/datasets/{datasetRid}/branches/{branchId}", + query_params={}, + path_params={ + "datasetRid": dataset_rid, + "branchId": branch_id, + }, + header_params={}, + body=None, + body_type=None, + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + dataset_rid: DatasetRid, + branch_id: BranchId, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Branch]: + """ + Get a Branch of a Dataset. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:datasets-read`. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param branch_id: branchId + :type branch_id: BranchId + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Branch] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v1/datasets/{datasetRid}/branches/{branchId}", + query_params={}, + path_params={ + "datasetRid": dataset_rid, + "branchId": branch_id, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Branch, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + dataset_rid: DatasetRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListBranchesResponse]: + """ + Lists the Branches of a Dataset. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:datasets-read`. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListBranchesResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v1/datasets/{datasetRid}/branches", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={ + "datasetRid": dataset_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListBranchesResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + dataset_rid: DatasetRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListBranchesResponse]: + """ + Lists the Branches of a Dataset. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:datasets-read`. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListBranchesResponse] + """ + + warnings.warn( + "The client.datasets.Branch.page(...) method has been deprecated. Please use client.datasets.Branch.list(...) instead.", DeprecationWarning, + stacklevel=2, ) return self._api_client.call_api( @@ -301,3 +572,267 @@ def page( request_timeout=request_timeout, ), ) + + +class _BranchClientStreaming: + """ + The API client for the Branch Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def create( + self, + dataset_rid: DatasetRid, + *, + branch_id: BranchId, + transaction_rid: Optional[TransactionRid] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Branch]: + """ + Creates a branch on an existing dataset. A branch may optionally point to a (committed) transaction. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:datasets-write`. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param branch_id: + :type branch_id: BranchId + :param transaction_rid: + :type transaction_rid: Optional[TransactionRid] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Branch] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v1/datasets/{datasetRid}/branches", + query_params={}, + path_params={ + "datasetRid": dataset_rid, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "branchId": branch_id, + "transactionRid": transaction_rid, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "branchId": BranchId, + "transactionRid": Optional[TransactionRid], + }, + ), + response_type=Branch, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def delete( + self, + dataset_rid: DatasetRid, + branch_id: BranchId, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[None]: + """ + Deletes the Branch with the given BranchId. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:datasets-write`. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param branch_id: branchId + :type branch_id: BranchId + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[None] + """ + + return self._api_client.stream_api( + RequestInfo( + method="DELETE", + resource_path="/v1/datasets/{datasetRid}/branches/{branchId}", + query_params={}, + path_params={ + "datasetRid": dataset_rid, + "branchId": branch_id, + }, + header_params={}, + body=None, + body_type=None, + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + dataset_rid: DatasetRid, + branch_id: BranchId, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Branch]: + """ + Get a Branch of a Dataset. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:datasets-read`. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param branch_id: branchId + :type branch_id: BranchId + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Branch] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v1/datasets/{datasetRid}/branches/{branchId}", + query_params={}, + path_params={ + "datasetRid": dataset_rid, + "branchId": branch_id, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Branch, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + dataset_rid: DatasetRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListBranchesResponse]: + """ + Lists the Branches of a Dataset. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:datasets-read`. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListBranchesResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v1/datasets/{datasetRid}/branches", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={ + "datasetRid": dataset_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListBranchesResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + dataset_rid: DatasetRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListBranchesResponse]: + """ + Lists the Branches of a Dataset. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:datasets-read`. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListBranchesResponse] + """ + + warnings.warn( + "The client.datasets.Branch.page(...) method has been deprecated. Please use client.datasets.Branch.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v1/datasets/{datasetRid}/branches", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={ + "datasetRid": dataset_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListBranchesResponse, + request_timeout=request_timeout, + ), + ) diff --git a/foundry/v1/datasets/client.py b/foundry/v1/datasets/client.py index 144bd0d1..177bf6be 100644 --- a/foundry/v1/datasets/client.py +++ b/foundry/v1/datasets/client.py @@ -27,7 +27,7 @@ class DatasetsClient: The API client for the Datasets Namespace. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ diff --git a/foundry/v1/datasets/dataset.py b/foundry/v1/datasets/dataset.py index df408349..f7c8697b 100644 --- a/foundry/v1/datasets/dataset.py +++ b/foundry/v1/datasets/dataset.py @@ -25,13 +25,16 @@ import pydantic from typing_extensions import Annotated from typing_extensions import TypedDict +from typing_extensions import deprecated from typing_extensions import overload from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import BinaryStream from foundry._core import Config from foundry._core import RequestInfo +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v1.core.models._folder_rid import FolderRid @@ -52,7 +55,7 @@ class DatasetClient: The API client for the Dataset Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -63,6 +66,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _DatasetClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _DatasetClientRaw(auth=auth, hostname=hostname, config=config) self.Branch = BranchClient(auth=auth, hostname=hostname, config=config) self.File = FileClient(auth=auth, hostname=hostname, config=config) self.Transaction = TransactionClient(auth=auth, hostname=hostname, config=config) @@ -116,7 +123,7 @@ def create( response_type=Dataset, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -165,7 +172,7 @@ def delete_schema( response_type=None, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -205,7 +212,7 @@ def get( response_type=Dataset, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -256,9 +263,12 @@ def get_schema( response_type=Any, request_timeout=request_timeout, ), - ) + ).decode() @overload + @deprecated( + "Using the `stream` parameter is deprecated. Please use the `with_streaming_response` instead." + ) def read( self, dataset_rid: DatasetRid, @@ -350,6 +360,9 @@ def read( ... @overload + @deprecated( + "Using the `stream` parameter is deprecated. Please use the `with_streaming_response` instead." + ) def read( self, dataset_rid: DatasetRid, @@ -444,6 +457,13 @@ def read( :rtype: Union[bytes, BinaryStream] """ + if stream: + warnings.warn( + f"client.datasets.Dataset.read(..., stream=True, chunk_size={chunk_size}) is deprecated. Please use:\n\nwith client.datasets.Dataset.with_streaming_response.read(...) as response:\n response.iter_bytes(chunk_size={chunk_size})\n", + DeprecationWarning, + stacklevel=2, + ) + return self._api_client.call_api( RequestInfo( method="GET", @@ -469,7 +489,7 @@ def read( chunk_size=chunk_size, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -519,4 +539,656 @@ def replace_schema( response_type=None, request_timeout=request_timeout, ), + ).decode() + + +class _DatasetClientRaw: + """ + The API client for the Dataset Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def create( + self, + *, + name: DatasetName, + parent_folder_rid: FolderRid, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Dataset]: + """ + Creates a new Dataset. A default branch - `master` for most enrollments - will be created on the Dataset. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:datasets-write`. + + :param name: + :type name: DatasetName + :param parent_folder_rid: + :type parent_folder_rid: FolderRid + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Dataset] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v1/datasets", + query_params={}, + path_params={}, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "name": name, + "parentFolderRid": parent_folder_rid, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "name": DatasetName, + "parentFolderRid": FolderRid, + }, + ), + response_type=Dataset, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def delete_schema( + self, + dataset_rid: DatasetRid, + *, + branch_id: Optional[BranchId] = None, + preview: Optional[PreviewMode] = None, + transaction_rid: Optional[TransactionRid] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[None]: + """ + Deletes the Schema from a Dataset and Branch. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param branch_id: branchId + :type branch_id: Optional[BranchId] + :param preview: preview + :type preview: Optional[PreviewMode] + :param transaction_rid: transactionRid + :type transaction_rid: Optional[TransactionRid] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[None] + """ + + return self._api_client.call_api( + RequestInfo( + method="DELETE", + resource_path="/v1/datasets/{datasetRid}/schema", + query_params={ + "branchId": branch_id, + "preview": preview, + "transactionRid": transaction_rid, + }, + path_params={ + "datasetRid": dataset_rid, + }, + header_params={}, + body=None, + body_type=None, + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + dataset_rid: DatasetRid, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Dataset]: + """ + Gets the Dataset with the given DatasetRid. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:datasets-read`. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Dataset] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v1/datasets/{datasetRid}", + query_params={}, + path_params={ + "datasetRid": dataset_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Dataset, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get_schema( + self, + dataset_rid: DatasetRid, + *, + branch_id: Optional[BranchId] = None, + preview: Optional[PreviewMode] = None, + transaction_rid: Optional[TransactionRid] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Any]: + """ + Retrieves the Schema for a Dataset and Branch, if it exists. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param branch_id: branchId + :type branch_id: Optional[BranchId] + :param preview: preview + :type preview: Optional[PreviewMode] + :param transaction_rid: transactionRid + :type transaction_rid: Optional[TransactionRid] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Any] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v1/datasets/{datasetRid}/schema", + query_params={ + "branchId": branch_id, + "preview": preview, + "transactionRid": transaction_rid, + }, + path_params={ + "datasetRid": dataset_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Any, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def read( + self, + dataset_rid: DatasetRid, + *, + format: TableExportFormat, + branch_id: Optional[BranchId] = None, + columns: Optional[List[str]] = None, + end_transaction_rid: Optional[TransactionRid] = None, + row_limit: Optional[int] = None, + start_transaction_rid: Optional[TransactionRid] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[bytes]: + """ + Gets the content of a dataset as a table in the specified format. + + This endpoint currently does not support views (Virtual datasets composed of other datasets). + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:datasets-read`. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param format: format + :type format: TableExportFormat + :param branch_id: branchId + :type branch_id: Optional[BranchId] + :param columns: columns + :type columns: Optional[List[str]] + :param end_transaction_rid: endTransactionRid + :type end_transaction_rid: Optional[TransactionRid] + :param row_limit: rowLimit + :type row_limit: Optional[int] + :param start_transaction_rid: startTransactionRid + :type start_transaction_rid: Optional[TransactionRid] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[bytes] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v1/datasets/{datasetRid}/readTable", + query_params={ + "format": format, + "branchId": branch_id, + "columns": columns, + "endTransactionRid": end_transaction_rid, + "rowLimit": row_limit, + "startTransactionRid": start_transaction_rid, + }, + path_params={ + "datasetRid": dataset_rid, + }, + header_params={ + "Accept": "*/*", + }, + body=None, + body_type=None, + response_type=bytes, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def replace_schema( + self, + dataset_rid: DatasetRid, + body: Any, + *, + branch_id: Optional[BranchId] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[None]: + """ + Puts a Schema on an existing Dataset and Branch. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param body: Body of the request + :type body: Any + :param branch_id: branchId + :type branch_id: Optional[BranchId] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[None] + """ + + return self._api_client.call_api( + RequestInfo( + method="PUT", + resource_path="/v1/datasets/{datasetRid}/schema", + query_params={ + "branchId": branch_id, + "preview": preview, + }, + path_params={ + "datasetRid": dataset_rid, + }, + header_params={ + "Content-Type": "application/json", + }, + body=body, + body_type=Any, + response_type=None, + request_timeout=request_timeout, + ), + ) + + +class _DatasetClientStreaming: + """ + The API client for the Dataset Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def create( + self, + *, + name: DatasetName, + parent_folder_rid: FolderRid, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Dataset]: + """ + Creates a new Dataset. A default branch - `master` for most enrollments - will be created on the Dataset. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:datasets-write`. + + :param name: + :type name: DatasetName + :param parent_folder_rid: + :type parent_folder_rid: FolderRid + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Dataset] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v1/datasets", + query_params={}, + path_params={}, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "name": name, + "parentFolderRid": parent_folder_rid, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "name": DatasetName, + "parentFolderRid": FolderRid, + }, + ), + response_type=Dataset, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def delete_schema( + self, + dataset_rid: DatasetRid, + *, + branch_id: Optional[BranchId] = None, + preview: Optional[PreviewMode] = None, + transaction_rid: Optional[TransactionRid] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[None]: + """ + Deletes the Schema from a Dataset and Branch. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param branch_id: branchId + :type branch_id: Optional[BranchId] + :param preview: preview + :type preview: Optional[PreviewMode] + :param transaction_rid: transactionRid + :type transaction_rid: Optional[TransactionRid] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[None] + """ + + return self._api_client.stream_api( + RequestInfo( + method="DELETE", + resource_path="/v1/datasets/{datasetRid}/schema", + query_params={ + "branchId": branch_id, + "preview": preview, + "transactionRid": transaction_rid, + }, + path_params={ + "datasetRid": dataset_rid, + }, + header_params={}, + body=None, + body_type=None, + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + dataset_rid: DatasetRid, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Dataset]: + """ + Gets the Dataset with the given DatasetRid. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:datasets-read`. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Dataset] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v1/datasets/{datasetRid}", + query_params={}, + path_params={ + "datasetRid": dataset_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Dataset, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get_schema( + self, + dataset_rid: DatasetRid, + *, + branch_id: Optional[BranchId] = None, + preview: Optional[PreviewMode] = None, + transaction_rid: Optional[TransactionRid] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Any]: + """ + Retrieves the Schema for a Dataset and Branch, if it exists. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param branch_id: branchId + :type branch_id: Optional[BranchId] + :param preview: preview + :type preview: Optional[PreviewMode] + :param transaction_rid: transactionRid + :type transaction_rid: Optional[TransactionRid] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Any] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v1/datasets/{datasetRid}/schema", + query_params={ + "branchId": branch_id, + "preview": preview, + "transactionRid": transaction_rid, + }, + path_params={ + "datasetRid": dataset_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Any, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def read( + self, + dataset_rid: DatasetRid, + *, + format: TableExportFormat, + branch_id: Optional[BranchId] = None, + columns: Optional[List[str]] = None, + end_transaction_rid: Optional[TransactionRid] = None, + row_limit: Optional[int] = None, + start_transaction_rid: Optional[TransactionRid] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[bytes]: + """ + Gets the content of a dataset as a table in the specified format. + + This endpoint currently does not support views (Virtual datasets composed of other datasets). + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:datasets-read`. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param format: format + :type format: TableExportFormat + :param branch_id: branchId + :type branch_id: Optional[BranchId] + :param columns: columns + :type columns: Optional[List[str]] + :param end_transaction_rid: endTransactionRid + :type end_transaction_rid: Optional[TransactionRid] + :param row_limit: rowLimit + :type row_limit: Optional[int] + :param start_transaction_rid: startTransactionRid + :type start_transaction_rid: Optional[TransactionRid] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[bytes] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v1/datasets/{datasetRid}/readTable", + query_params={ + "format": format, + "branchId": branch_id, + "columns": columns, + "endTransactionRid": end_transaction_rid, + "rowLimit": row_limit, + "startTransactionRid": start_transaction_rid, + }, + path_params={ + "datasetRid": dataset_rid, + }, + header_params={ + "Accept": "*/*", + }, + body=None, + body_type=None, + response_type=bytes, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def replace_schema( + self, + dataset_rid: DatasetRid, + body: Any, + *, + branch_id: Optional[BranchId] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[None]: + """ + Puts a Schema on an existing Dataset and Branch. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param body: Body of the request + :type body: Any + :param branch_id: branchId + :type branch_id: Optional[BranchId] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[None] + """ + + return self._api_client.stream_api( + RequestInfo( + method="PUT", + resource_path="/v1/datasets/{datasetRid}/schema", + query_params={ + "branchId": branch_id, + "preview": preview, + }, + path_params={ + "datasetRid": dataset_rid, + }, + header_params={ + "Content-Type": "application/json", + }, + body=body, + body_type=Any, + response_type=None, + request_timeout=request_timeout, + ), ) diff --git a/foundry/v1/datasets/file.py b/foundry/v1/datasets/file.py index f3fef2ea..b95c9152 100644 --- a/foundry/v1/datasets/file.py +++ b/foundry/v1/datasets/file.py @@ -24,14 +24,17 @@ import pydantic from typing_extensions import Annotated +from typing_extensions import deprecated from typing_extensions import overload from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import BinaryStream from foundry._core import Config from foundry._core import RequestInfo from foundry._core import ResourceIterator +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v1.core.models._file_path import FilePath @@ -50,7 +53,7 @@ class FileClient: The API client for the File Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -61,6 +64,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _FileClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _FileClientRaw(auth=auth, hostname=hostname, config=config) @maybe_ignore_preview @pydantic.validate_call @@ -124,7 +131,7 @@ def delete( response_type=None, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -202,7 +209,7 @@ def get( response_type=File, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -349,8 +356,9 @@ def page( """ warnings.warn( - "The FileClient.page(...) method has been deprecated. Please use FileClient.list(...) instead.", + "The client.datasets.File.page(...) method has been deprecated. Please use client.datasets.File.list(...) instead.", DeprecationWarning, + stacklevel=2, ) return self._api_client.call_api( @@ -375,9 +383,12 @@ def page( response_type=ListFilesResponse, request_timeout=request_timeout, ), - ) + ).decode() @overload + @deprecated( + "Using the `stream` parameter is deprecated. Please use the `with_streaming_response` instead." + ) def read( self, dataset_rid: DatasetRid, @@ -497,6 +508,9 @@ def read( ... @overload + @deprecated( + "Using the `stream` parameter is deprecated. Please use the `with_streaming_response` instead." + ) def read( self, dataset_rid: DatasetRid, @@ -619,6 +633,13 @@ def read( :rtype: Union[bytes, BinaryStream] """ + if stream: + warnings.warn( + f"client.datasets.Dataset.File.read(..., stream=True, chunk_size={chunk_size}) is deprecated. Please use:\n\nwith client.datasets.Dataset.File.with_streaming_response.read(...) as response:\n response.iter_bytes(chunk_size={chunk_size})\n", + DeprecationWarning, + stacklevel=2, + ) + return self._api_client.call_api( RequestInfo( method="GET", @@ -642,7 +663,7 @@ def read( chunk_size=chunk_size, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -720,4 +741,986 @@ def upload( response_type=File, request_timeout=request_timeout, ), + ).decode() + + +class _FileClientRaw: + """ + The API client for the File Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def delete( + self, + dataset_rid: DatasetRid, + file_path: FilePath, + *, + branch_id: Optional[BranchId] = None, + transaction_rid: Optional[TransactionRid] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[None]: + """ + Deletes a File from a Dataset. By default the file is deleted in a new transaction on the default + branch - `master` for most enrollments. The file will still be visible on historical views. + + #### Advanced Usage + + See [Datasets Core Concepts](/docs/foundry/data-integration/datasets/) for details on using branches and transactions. + + To **delete a File from a specific Branch** specify the Branch's identifier as `branchId`. A new delete Transaction + will be created and committed on this branch. + + To **delete a File using a manually opened Transaction**, specify the Transaction's resource identifier + as `transactionRid`. The transaction must be of type `DELETE`. This is useful for deleting multiple files in a + single transaction. See [createTransaction](/docs/foundry/api/datasets-resources/transactions/create-transaction/) to + open a transaction. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:datasets-write`. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param file_path: filePath + :type file_path: FilePath + :param branch_id: branchId + :type branch_id: Optional[BranchId] + :param transaction_rid: transactionRid + :type transaction_rid: Optional[TransactionRid] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[None] + """ + + return self._api_client.call_api( + RequestInfo( + method="DELETE", + resource_path="/v1/datasets/{datasetRid}/files/{filePath}", + query_params={ + "branchId": branch_id, + "transactionRid": transaction_rid, + }, + path_params={ + "datasetRid": dataset_rid, + "filePath": file_path, + }, + header_params={}, + body=None, + body_type=None, + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + dataset_rid: DatasetRid, + file_path: FilePath, + *, + branch_id: Optional[BranchId] = None, + end_transaction_rid: Optional[TransactionRid] = None, + start_transaction_rid: Optional[TransactionRid] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[File]: + """ + Gets metadata about a File contained in a Dataset. By default this retrieves the file's metadata from the latest + view of the default branch - `master` for most enrollments. + + #### Advanced Usage + + See [Datasets Core Concepts](/docs/foundry/data-integration/datasets/) for details on using branches and transactions. + + To **get a file's metadata from a specific Branch** specify the Branch's identifier as `branchId`. This will + retrieve metadata for the most recent version of the file since the latest snapshot transaction, or the earliest + ancestor transaction of the branch if there are no snapshot transactions. + + To **get a file's metadata from the resolved view of a transaction** specify the Transaction's resource identifier + as `endTransactionRid`. This will retrieve metadata for the most recent version of the file since the latest snapshot + transaction, or the earliest ancestor transaction if there are no snapshot transactions. + + To **get a file's metadata from the resolved view of a range of transactions** specify the the start transaction's + resource identifier as `startTransactionRid` and the end transaction's resource identifier as `endTransactionRid`. + This will retrieve metadata for the most recent version of the file since the `startTransactionRid` up to the + `endTransactionRid`. Behavior is undefined when the start and end transactions do not belong to the same root-to-leaf path. + + To **get a file's metadata from a specific transaction** specify the Transaction's resource identifier as both the + `startTransactionRid` and `endTransactionRid`. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:datasets-read`. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param file_path: filePath + :type file_path: FilePath + :param branch_id: branchId + :type branch_id: Optional[BranchId] + :param end_transaction_rid: endTransactionRid + :type end_transaction_rid: Optional[TransactionRid] + :param start_transaction_rid: startTransactionRid + :type start_transaction_rid: Optional[TransactionRid] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[File] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v1/datasets/{datasetRid}/files/{filePath}", + query_params={ + "branchId": branch_id, + "endTransactionRid": end_transaction_rid, + "startTransactionRid": start_transaction_rid, + }, + path_params={ + "datasetRid": dataset_rid, + "filePath": file_path, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=File, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + dataset_rid: DatasetRid, + *, + branch_id: Optional[BranchId] = None, + end_transaction_rid: Optional[TransactionRid] = None, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + start_transaction_rid: Optional[TransactionRid] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListFilesResponse]: + """ + Lists Files contained in a Dataset. By default files are listed on the latest view of the default + branch - `master` for most enrollments. + + #### Advanced Usage + + See [Datasets Core Concepts](/docs/foundry/data-integration/datasets/) for details on using branches and transactions. + + To **list files on a specific Branch** specify the Branch's identifier as `branchId`. This will include the most + recent version of all files since the latest snapshot transaction, or the earliest ancestor transaction of the + branch if there are no snapshot transactions. + + To **list files on the resolved view of a transaction** specify the Transaction's resource identifier + as `endTransactionRid`. This will include the most recent version of all files since the latest snapshot + transaction, or the earliest ancestor transaction if there are no snapshot transactions. + + To **list files on the resolved view of a range of transactions** specify the the start transaction's resource + identifier as `startTransactionRid` and the end transaction's resource identifier as `endTransactionRid`. This + will include the most recent version of all files since the `startTransactionRid` up to the `endTransactionRid`. + Note that an intermediate snapshot transaction will remove all files from the view. Behavior is undefined when + the start and end transactions do not belong to the same root-to-leaf path. + + To **list files on a specific transaction** specify the Transaction's resource identifier as both the + `startTransactionRid` and `endTransactionRid`. This will include only files that were modified as part of that + Transaction. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:datasets-read`. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param branch_id: branchId + :type branch_id: Optional[BranchId] + :param end_transaction_rid: endTransactionRid + :type end_transaction_rid: Optional[TransactionRid] + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param start_transaction_rid: startTransactionRid + :type start_transaction_rid: Optional[TransactionRid] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListFilesResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v1/datasets/{datasetRid}/files", + query_params={ + "branchId": branch_id, + "endTransactionRid": end_transaction_rid, + "pageSize": page_size, + "pageToken": page_token, + "startTransactionRid": start_transaction_rid, + }, + path_params={ + "datasetRid": dataset_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListFilesResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + dataset_rid: DatasetRid, + *, + branch_id: Optional[BranchId] = None, + end_transaction_rid: Optional[TransactionRid] = None, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + start_transaction_rid: Optional[TransactionRid] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListFilesResponse]: + """ + Lists Files contained in a Dataset. By default files are listed on the latest view of the default + branch - `master` for most enrollments. + + #### Advanced Usage + + See [Datasets Core Concepts](/docs/foundry/data-integration/datasets/) for details on using branches and transactions. + + To **list files on a specific Branch** specify the Branch's identifier as `branchId`. This will include the most + recent version of all files since the latest snapshot transaction, or the earliest ancestor transaction of the + branch if there are no snapshot transactions. + + To **list files on the resolved view of a transaction** specify the Transaction's resource identifier + as `endTransactionRid`. This will include the most recent version of all files since the latest snapshot + transaction, or the earliest ancestor transaction if there are no snapshot transactions. + + To **list files on the resolved view of a range of transactions** specify the the start transaction's resource + identifier as `startTransactionRid` and the end transaction's resource identifier as `endTransactionRid`. This + will include the most recent version of all files since the `startTransactionRid` up to the `endTransactionRid`. + Note that an intermediate snapshot transaction will remove all files from the view. Behavior is undefined when + the start and end transactions do not belong to the same root-to-leaf path. + + To **list files on a specific transaction** specify the Transaction's resource identifier as both the + `startTransactionRid` and `endTransactionRid`. This will include only files that were modified as part of that + Transaction. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:datasets-read`. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param branch_id: branchId + :type branch_id: Optional[BranchId] + :param end_transaction_rid: endTransactionRid + :type end_transaction_rid: Optional[TransactionRid] + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param start_transaction_rid: startTransactionRid + :type start_transaction_rid: Optional[TransactionRid] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListFilesResponse] + """ + + warnings.warn( + "The client.datasets.File.page(...) method has been deprecated. Please use client.datasets.File.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v1/datasets/{datasetRid}/files", + query_params={ + "branchId": branch_id, + "endTransactionRid": end_transaction_rid, + "pageSize": page_size, + "pageToken": page_token, + "startTransactionRid": start_transaction_rid, + }, + path_params={ + "datasetRid": dataset_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListFilesResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def read( + self, + dataset_rid: DatasetRid, + file_path: FilePath, + *, + branch_id: Optional[BranchId] = None, + end_transaction_rid: Optional[TransactionRid] = None, + start_transaction_rid: Optional[TransactionRid] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[bytes]: + """ + Gets the content of a File contained in a Dataset. By default this retrieves the file's content from the latest + view of the default branch - `master` for most enrollments. + + #### Advanced Usage + + See [Datasets Core Concepts](/docs/foundry/data-integration/datasets/) for details on using branches and transactions. + + To **get a file's content from a specific Branch** specify the Branch's identifier as `branchId`. This will + retrieve the content for the most recent version of the file since the latest snapshot transaction, or the + earliest ancestor transaction of the branch if there are no snapshot transactions. + + To **get a file's content from the resolved view of a transaction** specify the Transaction's resource identifier + as `endTransactionRid`. This will retrieve the content for the most recent version of the file since the latest + snapshot transaction, or the earliest ancestor transaction if there are no snapshot transactions. + + To **get a file's content from the resolved view of a range of transactions** specify the the start transaction's + resource identifier as `startTransactionRid` and the end transaction's resource identifier as `endTransactionRid`. + This will retrieve the content for the most recent version of the file since the `startTransactionRid` up to the + `endTransactionRid`. Note that an intermediate snapshot transaction will remove all files from the view. Behavior + is undefined when the start and end transactions do not belong to the same root-to-leaf path. + + To **get a file's content from a specific transaction** specify the Transaction's resource identifier as both the + `startTransactionRid` and `endTransactionRid`. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:datasets-read`. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param file_path: filePath + :type file_path: FilePath + :param branch_id: branchId + :type branch_id: Optional[BranchId] + :param end_transaction_rid: endTransactionRid + :type end_transaction_rid: Optional[TransactionRid] + :param start_transaction_rid: startTransactionRid + :type start_transaction_rid: Optional[TransactionRid] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[bytes] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v1/datasets/{datasetRid}/files/{filePath}/content", + query_params={ + "branchId": branch_id, + "endTransactionRid": end_transaction_rid, + "startTransactionRid": start_transaction_rid, + }, + path_params={ + "datasetRid": dataset_rid, + "filePath": file_path, + }, + header_params={ + "Accept": "*/*", + }, + body=None, + body_type=None, + response_type=bytes, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def upload( + self, + dataset_rid: DatasetRid, + body: bytes, + *, + file_path: FilePath, + branch_id: Optional[BranchId] = None, + transaction_rid: Optional[TransactionRid] = None, + transaction_type: Optional[TransactionType] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[File]: + """ + Uploads a File to an existing Dataset. + The body of the request must contain the binary content of the file and the `Content-Type` header must be `application/octet-stream`. + + By default the file is uploaded to a new transaction on the default branch - `master` for most enrollments. + If the file already exists only the most recent version will be visible in the updated view. + + #### Advanced Usage + + See [Datasets Core Concepts](/docs/foundry/data-integration/datasets/) for details on using branches and transactions. + + To **upload a file to a specific Branch** specify the Branch's identifier as `branchId`. A new transaction will + be created and committed on this branch. By default the TransactionType will be `UPDATE`, to override this + default specify `transactionType` in addition to `branchId`. + See [createBranch](/docs/foundry/api/datasets-resources/branches/create-branch/) to create a custom branch. + + To **upload a file on a manually opened transaction** specify the Transaction's resource identifier as + `transactionRid`. This is useful for uploading multiple files in a single transaction. + See [createTransaction](/docs/foundry/api/datasets-resources/transactions/create-transaction/) to open a transaction. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:datasets-write`. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param body: Body of the request + :type body: bytes + :param file_path: filePath + :type file_path: FilePath + :param branch_id: branchId + :type branch_id: Optional[BranchId] + :param transaction_rid: transactionRid + :type transaction_rid: Optional[TransactionRid] + :param transaction_type: transactionType + :type transaction_type: Optional[TransactionType] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[File] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v1/datasets/{datasetRid}/files:upload", + query_params={ + "filePath": file_path, + "branchId": branch_id, + "transactionRid": transaction_rid, + "transactionType": transaction_type, + }, + path_params={ + "datasetRid": dataset_rid, + }, + header_params={ + "Content-Type": "*/*", + "Accept": "application/json", + }, + body=body, + body_type=bytes, + response_type=File, + request_timeout=request_timeout, + ), + ) + + +class _FileClientStreaming: + """ + The API client for the File Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def delete( + self, + dataset_rid: DatasetRid, + file_path: FilePath, + *, + branch_id: Optional[BranchId] = None, + transaction_rid: Optional[TransactionRid] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[None]: + """ + Deletes a File from a Dataset. By default the file is deleted in a new transaction on the default + branch - `master` for most enrollments. The file will still be visible on historical views. + + #### Advanced Usage + + See [Datasets Core Concepts](/docs/foundry/data-integration/datasets/) for details on using branches and transactions. + + To **delete a File from a specific Branch** specify the Branch's identifier as `branchId`. A new delete Transaction + will be created and committed on this branch. + + To **delete a File using a manually opened Transaction**, specify the Transaction's resource identifier + as `transactionRid`. The transaction must be of type `DELETE`. This is useful for deleting multiple files in a + single transaction. See [createTransaction](/docs/foundry/api/datasets-resources/transactions/create-transaction/) to + open a transaction. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:datasets-write`. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param file_path: filePath + :type file_path: FilePath + :param branch_id: branchId + :type branch_id: Optional[BranchId] + :param transaction_rid: transactionRid + :type transaction_rid: Optional[TransactionRid] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[None] + """ + + return self._api_client.stream_api( + RequestInfo( + method="DELETE", + resource_path="/v1/datasets/{datasetRid}/files/{filePath}", + query_params={ + "branchId": branch_id, + "transactionRid": transaction_rid, + }, + path_params={ + "datasetRid": dataset_rid, + "filePath": file_path, + }, + header_params={}, + body=None, + body_type=None, + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + dataset_rid: DatasetRid, + file_path: FilePath, + *, + branch_id: Optional[BranchId] = None, + end_transaction_rid: Optional[TransactionRid] = None, + start_transaction_rid: Optional[TransactionRid] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[File]: + """ + Gets metadata about a File contained in a Dataset. By default this retrieves the file's metadata from the latest + view of the default branch - `master` for most enrollments. + + #### Advanced Usage + + See [Datasets Core Concepts](/docs/foundry/data-integration/datasets/) for details on using branches and transactions. + + To **get a file's metadata from a specific Branch** specify the Branch's identifier as `branchId`. This will + retrieve metadata for the most recent version of the file since the latest snapshot transaction, or the earliest + ancestor transaction of the branch if there are no snapshot transactions. + + To **get a file's metadata from the resolved view of a transaction** specify the Transaction's resource identifier + as `endTransactionRid`. This will retrieve metadata for the most recent version of the file since the latest snapshot + transaction, or the earliest ancestor transaction if there are no snapshot transactions. + + To **get a file's metadata from the resolved view of a range of transactions** specify the the start transaction's + resource identifier as `startTransactionRid` and the end transaction's resource identifier as `endTransactionRid`. + This will retrieve metadata for the most recent version of the file since the `startTransactionRid` up to the + `endTransactionRid`. Behavior is undefined when the start and end transactions do not belong to the same root-to-leaf path. + + To **get a file's metadata from a specific transaction** specify the Transaction's resource identifier as both the + `startTransactionRid` and `endTransactionRid`. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:datasets-read`. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param file_path: filePath + :type file_path: FilePath + :param branch_id: branchId + :type branch_id: Optional[BranchId] + :param end_transaction_rid: endTransactionRid + :type end_transaction_rid: Optional[TransactionRid] + :param start_transaction_rid: startTransactionRid + :type start_transaction_rid: Optional[TransactionRid] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[File] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v1/datasets/{datasetRid}/files/{filePath}", + query_params={ + "branchId": branch_id, + "endTransactionRid": end_transaction_rid, + "startTransactionRid": start_transaction_rid, + }, + path_params={ + "datasetRid": dataset_rid, + "filePath": file_path, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=File, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + dataset_rid: DatasetRid, + *, + branch_id: Optional[BranchId] = None, + end_transaction_rid: Optional[TransactionRid] = None, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + start_transaction_rid: Optional[TransactionRid] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListFilesResponse]: + """ + Lists Files contained in a Dataset. By default files are listed on the latest view of the default + branch - `master` for most enrollments. + + #### Advanced Usage + + See [Datasets Core Concepts](/docs/foundry/data-integration/datasets/) for details on using branches and transactions. + + To **list files on a specific Branch** specify the Branch's identifier as `branchId`. This will include the most + recent version of all files since the latest snapshot transaction, or the earliest ancestor transaction of the + branch if there are no snapshot transactions. + + To **list files on the resolved view of a transaction** specify the Transaction's resource identifier + as `endTransactionRid`. This will include the most recent version of all files since the latest snapshot + transaction, or the earliest ancestor transaction if there are no snapshot transactions. + + To **list files on the resolved view of a range of transactions** specify the the start transaction's resource + identifier as `startTransactionRid` and the end transaction's resource identifier as `endTransactionRid`. This + will include the most recent version of all files since the `startTransactionRid` up to the `endTransactionRid`. + Note that an intermediate snapshot transaction will remove all files from the view. Behavior is undefined when + the start and end transactions do not belong to the same root-to-leaf path. + + To **list files on a specific transaction** specify the Transaction's resource identifier as both the + `startTransactionRid` and `endTransactionRid`. This will include only files that were modified as part of that + Transaction. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:datasets-read`. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param branch_id: branchId + :type branch_id: Optional[BranchId] + :param end_transaction_rid: endTransactionRid + :type end_transaction_rid: Optional[TransactionRid] + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param start_transaction_rid: startTransactionRid + :type start_transaction_rid: Optional[TransactionRid] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListFilesResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v1/datasets/{datasetRid}/files", + query_params={ + "branchId": branch_id, + "endTransactionRid": end_transaction_rid, + "pageSize": page_size, + "pageToken": page_token, + "startTransactionRid": start_transaction_rid, + }, + path_params={ + "datasetRid": dataset_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListFilesResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + dataset_rid: DatasetRid, + *, + branch_id: Optional[BranchId] = None, + end_transaction_rid: Optional[TransactionRid] = None, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + start_transaction_rid: Optional[TransactionRid] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListFilesResponse]: + """ + Lists Files contained in a Dataset. By default files are listed on the latest view of the default + branch - `master` for most enrollments. + + #### Advanced Usage + + See [Datasets Core Concepts](/docs/foundry/data-integration/datasets/) for details on using branches and transactions. + + To **list files on a specific Branch** specify the Branch's identifier as `branchId`. This will include the most + recent version of all files since the latest snapshot transaction, or the earliest ancestor transaction of the + branch if there are no snapshot transactions. + + To **list files on the resolved view of a transaction** specify the Transaction's resource identifier + as `endTransactionRid`. This will include the most recent version of all files since the latest snapshot + transaction, or the earliest ancestor transaction if there are no snapshot transactions. + + To **list files on the resolved view of a range of transactions** specify the the start transaction's resource + identifier as `startTransactionRid` and the end transaction's resource identifier as `endTransactionRid`. This + will include the most recent version of all files since the `startTransactionRid` up to the `endTransactionRid`. + Note that an intermediate snapshot transaction will remove all files from the view. Behavior is undefined when + the start and end transactions do not belong to the same root-to-leaf path. + + To **list files on a specific transaction** specify the Transaction's resource identifier as both the + `startTransactionRid` and `endTransactionRid`. This will include only files that were modified as part of that + Transaction. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:datasets-read`. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param branch_id: branchId + :type branch_id: Optional[BranchId] + :param end_transaction_rid: endTransactionRid + :type end_transaction_rid: Optional[TransactionRid] + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param start_transaction_rid: startTransactionRid + :type start_transaction_rid: Optional[TransactionRid] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListFilesResponse] + """ + + warnings.warn( + "The client.datasets.File.page(...) method has been deprecated. Please use client.datasets.File.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v1/datasets/{datasetRid}/files", + query_params={ + "branchId": branch_id, + "endTransactionRid": end_transaction_rid, + "pageSize": page_size, + "pageToken": page_token, + "startTransactionRid": start_transaction_rid, + }, + path_params={ + "datasetRid": dataset_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListFilesResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def read( + self, + dataset_rid: DatasetRid, + file_path: FilePath, + *, + branch_id: Optional[BranchId] = None, + end_transaction_rid: Optional[TransactionRid] = None, + start_transaction_rid: Optional[TransactionRid] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[bytes]: + """ + Gets the content of a File contained in a Dataset. By default this retrieves the file's content from the latest + view of the default branch - `master` for most enrollments. + + #### Advanced Usage + + See [Datasets Core Concepts](/docs/foundry/data-integration/datasets/) for details on using branches and transactions. + + To **get a file's content from a specific Branch** specify the Branch's identifier as `branchId`. This will + retrieve the content for the most recent version of the file since the latest snapshot transaction, or the + earliest ancestor transaction of the branch if there are no snapshot transactions. + + To **get a file's content from the resolved view of a transaction** specify the Transaction's resource identifier + as `endTransactionRid`. This will retrieve the content for the most recent version of the file since the latest + snapshot transaction, or the earliest ancestor transaction if there are no snapshot transactions. + + To **get a file's content from the resolved view of a range of transactions** specify the the start transaction's + resource identifier as `startTransactionRid` and the end transaction's resource identifier as `endTransactionRid`. + This will retrieve the content for the most recent version of the file since the `startTransactionRid` up to the + `endTransactionRid`. Note that an intermediate snapshot transaction will remove all files from the view. Behavior + is undefined when the start and end transactions do not belong to the same root-to-leaf path. + + To **get a file's content from a specific transaction** specify the Transaction's resource identifier as both the + `startTransactionRid` and `endTransactionRid`. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:datasets-read`. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param file_path: filePath + :type file_path: FilePath + :param branch_id: branchId + :type branch_id: Optional[BranchId] + :param end_transaction_rid: endTransactionRid + :type end_transaction_rid: Optional[TransactionRid] + :param start_transaction_rid: startTransactionRid + :type start_transaction_rid: Optional[TransactionRid] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[bytes] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v1/datasets/{datasetRid}/files/{filePath}/content", + query_params={ + "branchId": branch_id, + "endTransactionRid": end_transaction_rid, + "startTransactionRid": start_transaction_rid, + }, + path_params={ + "datasetRid": dataset_rid, + "filePath": file_path, + }, + header_params={ + "Accept": "*/*", + }, + body=None, + body_type=None, + response_type=bytes, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def upload( + self, + dataset_rid: DatasetRid, + body: bytes, + *, + file_path: FilePath, + branch_id: Optional[BranchId] = None, + transaction_rid: Optional[TransactionRid] = None, + transaction_type: Optional[TransactionType] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[File]: + """ + Uploads a File to an existing Dataset. + The body of the request must contain the binary content of the file and the `Content-Type` header must be `application/octet-stream`. + + By default the file is uploaded to a new transaction on the default branch - `master` for most enrollments. + If the file already exists only the most recent version will be visible in the updated view. + + #### Advanced Usage + + See [Datasets Core Concepts](/docs/foundry/data-integration/datasets/) for details on using branches and transactions. + + To **upload a file to a specific Branch** specify the Branch's identifier as `branchId`. A new transaction will + be created and committed on this branch. By default the TransactionType will be `UPDATE`, to override this + default specify `transactionType` in addition to `branchId`. + See [createBranch](/docs/foundry/api/datasets-resources/branches/create-branch/) to create a custom branch. + + To **upload a file on a manually opened transaction** specify the Transaction's resource identifier as + `transactionRid`. This is useful for uploading multiple files in a single transaction. + See [createTransaction](/docs/foundry/api/datasets-resources/transactions/create-transaction/) to open a transaction. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:datasets-write`. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param body: Body of the request + :type body: bytes + :param file_path: filePath + :type file_path: FilePath + :param branch_id: branchId + :type branch_id: Optional[BranchId] + :param transaction_rid: transactionRid + :type transaction_rid: Optional[TransactionRid] + :param transaction_type: transactionType + :type transaction_type: Optional[TransactionType] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[File] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v1/datasets/{datasetRid}/files:upload", + query_params={ + "filePath": file_path, + "branchId": branch_id, + "transactionRid": transaction_rid, + "transactionType": transaction_type, + }, + path_params={ + "datasetRid": dataset_rid, + }, + header_params={ + "Content-Type": "*/*", + "Accept": "application/json", + }, + body=body, + body_type=bytes, + response_type=File, + request_timeout=request_timeout, + ), ) diff --git a/foundry/v1/datasets/transaction.py b/foundry/v1/datasets/transaction.py index 12bec4b6..155108cd 100644 --- a/foundry/v1/datasets/transaction.py +++ b/foundry/v1/datasets/transaction.py @@ -24,9 +24,11 @@ from typing_extensions import TypedDict from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v1.datasets.models._branch_id import BranchId @@ -41,7 +43,7 @@ class TransactionClient: The API client for the Transaction Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -52,6 +54,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _TransactionClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _TransactionClientRaw(auth=auth, hostname=hostname, config=config) @maybe_ignore_preview @pydantic.validate_call @@ -96,7 +102,7 @@ def abort( response_type=Transaction, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -141,7 +147,7 @@ def commit( response_type=Transaction, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -197,7 +203,7 @@ def create( response_type=Transaction, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -241,4 +247,420 @@ def get( response_type=Transaction, request_timeout=request_timeout, ), + ).decode() + + +class _TransactionClientRaw: + """ + The API client for the Transaction Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def abort( + self, + dataset_rid: DatasetRid, + transaction_rid: TransactionRid, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Transaction]: + """ + Aborts an open Transaction. File modifications made on this Transaction are not preserved and the Branch is + not updated. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:datasets-write`. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param transaction_rid: transactionRid + :type transaction_rid: TransactionRid + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Transaction] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v1/datasets/{datasetRid}/transactions/{transactionRid}/abort", + query_params={}, + path_params={ + "datasetRid": dataset_rid, + "transactionRid": transaction_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Transaction, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def commit( + self, + dataset_rid: DatasetRid, + transaction_rid: TransactionRid, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Transaction]: + """ + Commits an open Transaction. File modifications made on this Transaction are preserved and the Branch is + updated to point to the Transaction. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:datasets-write`. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param transaction_rid: transactionRid + :type transaction_rid: TransactionRid + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Transaction] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v1/datasets/{datasetRid}/transactions/{transactionRid}/commit", + query_params={}, + path_params={ + "datasetRid": dataset_rid, + "transactionRid": transaction_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Transaction, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def create( + self, + dataset_rid: DatasetRid, + *, + branch_id: Optional[BranchId] = None, + transaction_type: Optional[TransactionType] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Transaction]: + """ + Creates a Transaction on a Branch of a Dataset. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:datasets-write`. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param branch_id: branchId + :type branch_id: Optional[BranchId] + :param transaction_type: + :type transaction_type: Optional[TransactionType] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Transaction] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v1/datasets/{datasetRid}/transactions", + query_params={ + "branchId": branch_id, + }, + path_params={ + "datasetRid": dataset_rid, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "transactionType": transaction_type, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "transactionType": Optional[TransactionType], + }, + ), + response_type=Transaction, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + dataset_rid: DatasetRid, + transaction_rid: TransactionRid, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Transaction]: + """ + Gets a Transaction of a Dataset. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:datasets-read`. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param transaction_rid: transactionRid + :type transaction_rid: TransactionRid + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Transaction] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v1/datasets/{datasetRid}/transactions/{transactionRid}", + query_params={}, + path_params={ + "datasetRid": dataset_rid, + "transactionRid": transaction_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Transaction, + request_timeout=request_timeout, + ), + ) + + +class _TransactionClientStreaming: + """ + The API client for the Transaction Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def abort( + self, + dataset_rid: DatasetRid, + transaction_rid: TransactionRid, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Transaction]: + """ + Aborts an open Transaction. File modifications made on this Transaction are not preserved and the Branch is + not updated. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:datasets-write`. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param transaction_rid: transactionRid + :type transaction_rid: TransactionRid + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Transaction] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v1/datasets/{datasetRid}/transactions/{transactionRid}/abort", + query_params={}, + path_params={ + "datasetRid": dataset_rid, + "transactionRid": transaction_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Transaction, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def commit( + self, + dataset_rid: DatasetRid, + transaction_rid: TransactionRid, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Transaction]: + """ + Commits an open Transaction. File modifications made on this Transaction are preserved and the Branch is + updated to point to the Transaction. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:datasets-write`. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param transaction_rid: transactionRid + :type transaction_rid: TransactionRid + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Transaction] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v1/datasets/{datasetRid}/transactions/{transactionRid}/commit", + query_params={}, + path_params={ + "datasetRid": dataset_rid, + "transactionRid": transaction_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Transaction, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def create( + self, + dataset_rid: DatasetRid, + *, + branch_id: Optional[BranchId] = None, + transaction_type: Optional[TransactionType] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Transaction]: + """ + Creates a Transaction on a Branch of a Dataset. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:datasets-write`. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param branch_id: branchId + :type branch_id: Optional[BranchId] + :param transaction_type: + :type transaction_type: Optional[TransactionType] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Transaction] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v1/datasets/{datasetRid}/transactions", + query_params={ + "branchId": branch_id, + }, + path_params={ + "datasetRid": dataset_rid, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "transactionType": transaction_type, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "transactionType": Optional[TransactionType], + }, + ), + response_type=Transaction, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + dataset_rid: DatasetRid, + transaction_rid: TransactionRid, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Transaction]: + """ + Gets a Transaction of a Dataset. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:datasets-read`. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param transaction_rid: transactionRid + :type transaction_rid: TransactionRid + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Transaction] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v1/datasets/{datasetRid}/transactions/{transactionRid}", + query_params={}, + path_params={ + "datasetRid": dataset_rid, + "transactionRid": transaction_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Transaction, + request_timeout=request_timeout, + ), ) diff --git a/foundry/v1/ontologies/action.py b/foundry/v1/ontologies/action.py index bd017250..fdd50f63 100644 --- a/foundry/v1/ontologies/action.py +++ b/foundry/v1/ontologies/action.py @@ -25,9 +25,11 @@ from typing_extensions import TypedDict from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v1.ontologies.models._action_type_api_name import ActionTypeApiName @@ -47,7 +49,7 @@ class ActionClient: The API client for the Action Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -58,6 +60,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _ActionClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _ActionClientRaw(auth=auth, hostname=hostname, config=config) @maybe_ignore_preview @pydantic.validate_call @@ -117,7 +123,7 @@ def apply( response_type=ApplyActionResponse, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -180,7 +186,7 @@ def apply_batch( response_type=BatchApplyActionResponse, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -242,4 +248,410 @@ def validate( response_type=ValidateActionResponse, request_timeout=request_timeout, ), + ).decode() + + +class _ActionClientRaw: + """ + The API client for the Action Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def apply( + self, + ontology_rid: OntologyRid, + action_type: ActionTypeApiName, + *, + parameters: Dict[ParameterId, Optional[DataValue]], + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ApplyActionResponse]: + """ + Applies an action using the given parameters. Changes to the Ontology are eventually consistent and may take + some time to be visible. + + Note that [parameter default values](/docs/foundry/action-types/parameters-default-value/) are not currently supported by + this endpoint. + + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-read api:ontologies-write`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param action_type: actionType + :type action_type: ActionTypeApiName + :param parameters: + :type parameters: Dict[ParameterId, Optional[DataValue]] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ApplyActionResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v1/ontologies/{ontologyRid}/actions/{actionType}/apply", + query_params={}, + path_params={ + "ontologyRid": ontology_rid, + "actionType": action_type, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "parameters": parameters, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "parameters": Dict[ParameterId, Optional[DataValue]], + }, + ), + response_type=ApplyActionResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def apply_batch( + self, + ontology_rid: OntologyRid, + action_type: ActionTypeApiName, + *, + requests: List[ApplyActionRequestDict], + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[BatchApplyActionResponse]: + """ + Applies multiple actions (of the same Action Type) using the given parameters. + Changes to the Ontology are eventually consistent and may take some time to be visible. + + Up to 20 actions may be applied in one call. Actions that only modify objects in Object Storage v2 and do not + call Functions may receive a higher limit. + + Note that [parameter default values](/docs/foundry/action-types/parameters-default-value/) and + [notifications](/docs/foundry/action-types/notifications/) are not currently supported by this endpoint. + + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-read api:ontologies-write`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param action_type: actionType + :type action_type: ActionTypeApiName + :param requests: + :type requests: List[ApplyActionRequestDict] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[BatchApplyActionResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v1/ontologies/{ontologyRid}/actions/{actionType}/applyBatch", + query_params={}, + path_params={ + "ontologyRid": ontology_rid, + "actionType": action_type, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "requests": requests, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "requests": List[ApplyActionRequestDict], + }, + ), + response_type=BatchApplyActionResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def validate( + self, + ontology_rid: OntologyRid, + action_type: ActionTypeApiName, + *, + parameters: Dict[ParameterId, Optional[DataValue]], + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ValidateActionResponse]: + """ + Validates if an action can be run with the given set of parameters. + The response contains the evaluation of parameters and **submission criteria** + that determine if the request is `VALID` or `INVALID`. + For performance reasons, validations will not consider existing objects or other data in Foundry. + For example, the uniqueness of a primary key or the existence of a user ID will not be checked. + Note that [parameter default values](/docs/foundry/action-types/parameters-default-value/) are not currently supported by + this endpoint. Unspecified parameters will be given a default value of `null`. + + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-read`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param action_type: actionType + :type action_type: ActionTypeApiName + :param parameters: + :type parameters: Dict[ParameterId, Optional[DataValue]] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ValidateActionResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v1/ontologies/{ontologyRid}/actions/{actionType}/validate", + query_params={}, + path_params={ + "ontologyRid": ontology_rid, + "actionType": action_type, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "parameters": parameters, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "parameters": Dict[ParameterId, Optional[DataValue]], + }, + ), + response_type=ValidateActionResponse, + request_timeout=request_timeout, + ), + ) + + +class _ActionClientStreaming: + """ + The API client for the Action Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def apply( + self, + ontology_rid: OntologyRid, + action_type: ActionTypeApiName, + *, + parameters: Dict[ParameterId, Optional[DataValue]], + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ApplyActionResponse]: + """ + Applies an action using the given parameters. Changes to the Ontology are eventually consistent and may take + some time to be visible. + + Note that [parameter default values](/docs/foundry/action-types/parameters-default-value/) are not currently supported by + this endpoint. + + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-read api:ontologies-write`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param action_type: actionType + :type action_type: ActionTypeApiName + :param parameters: + :type parameters: Dict[ParameterId, Optional[DataValue]] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ApplyActionResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v1/ontologies/{ontologyRid}/actions/{actionType}/apply", + query_params={}, + path_params={ + "ontologyRid": ontology_rid, + "actionType": action_type, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "parameters": parameters, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "parameters": Dict[ParameterId, Optional[DataValue]], + }, + ), + response_type=ApplyActionResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def apply_batch( + self, + ontology_rid: OntologyRid, + action_type: ActionTypeApiName, + *, + requests: List[ApplyActionRequestDict], + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[BatchApplyActionResponse]: + """ + Applies multiple actions (of the same Action Type) using the given parameters. + Changes to the Ontology are eventually consistent and may take some time to be visible. + + Up to 20 actions may be applied in one call. Actions that only modify objects in Object Storage v2 and do not + call Functions may receive a higher limit. + + Note that [parameter default values](/docs/foundry/action-types/parameters-default-value/) and + [notifications](/docs/foundry/action-types/notifications/) are not currently supported by this endpoint. + + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-read api:ontologies-write`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param action_type: actionType + :type action_type: ActionTypeApiName + :param requests: + :type requests: List[ApplyActionRequestDict] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[BatchApplyActionResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v1/ontologies/{ontologyRid}/actions/{actionType}/applyBatch", + query_params={}, + path_params={ + "ontologyRid": ontology_rid, + "actionType": action_type, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "requests": requests, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "requests": List[ApplyActionRequestDict], + }, + ), + response_type=BatchApplyActionResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def validate( + self, + ontology_rid: OntologyRid, + action_type: ActionTypeApiName, + *, + parameters: Dict[ParameterId, Optional[DataValue]], + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ValidateActionResponse]: + """ + Validates if an action can be run with the given set of parameters. + The response contains the evaluation of parameters and **submission criteria** + that determine if the request is `VALID` or `INVALID`. + For performance reasons, validations will not consider existing objects or other data in Foundry. + For example, the uniqueness of a primary key or the existence of a user ID will not be checked. + Note that [parameter default values](/docs/foundry/action-types/parameters-default-value/) are not currently supported by + this endpoint. Unspecified parameters will be given a default value of `null`. + + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-read`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param action_type: actionType + :type action_type: ActionTypeApiName + :param parameters: + :type parameters: Dict[ParameterId, Optional[DataValue]] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ValidateActionResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v1/ontologies/{ontologyRid}/actions/{actionType}/validate", + query_params={}, + path_params={ + "ontologyRid": ontology_rid, + "actionType": action_type, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "parameters": parameters, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "parameters": Dict[ParameterId, Optional[DataValue]], + }, + ), + response_type=ValidateActionResponse, + request_timeout=request_timeout, + ), ) diff --git a/foundry/v1/ontologies/action_type.py b/foundry/v1/ontologies/action_type.py index 435b970d..81004954 100644 --- a/foundry/v1/ontologies/action_type.py +++ b/foundry/v1/ontologies/action_type.py @@ -24,10 +24,12 @@ from typing_extensions import Annotated from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo from foundry._core import ResourceIterator +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v1.core.models._page_size import PageSize @@ -43,7 +45,7 @@ class ActionTypeClient: The API client for the ActionType Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -54,6 +56,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _ActionTypeClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _ActionTypeClientRaw(auth=auth, hostname=hostname, config=config) @maybe_ignore_preview @pydantic.validate_call @@ -97,7 +103,7 @@ def get( response_type=ActionType, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -183,8 +189,181 @@ def page( """ warnings.warn( - "The ActionTypeClient.page(...) method has been deprecated. Please use ActionTypeClient.list(...) instead.", + "The client.ontologies.ActionType.page(...) method has been deprecated. Please use client.ontologies.ActionType.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v1/ontologies/{ontologyRid}/actionTypes", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={ + "ontologyRid": ontology_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListActionTypesResponse, + request_timeout=request_timeout, + ), + ).decode() + + +class _ActionTypeClientRaw: + """ + The API client for the ActionType Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + ontology_rid: OntologyRid, + action_type_api_name: ActionTypeApiName, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ActionType]: + """ + Gets a specific action type with the given API name. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param action_type_api_name: actionTypeApiName + :type action_type_api_name: ActionTypeApiName + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ActionType] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v1/ontologies/{ontologyRid}/actionTypes/{actionTypeApiName}", + query_params={}, + path_params={ + "ontologyRid": ontology_rid, + "actionTypeApiName": action_type_api_name, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ActionType, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + ontology_rid: OntologyRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListActionTypesResponse]: + """ + Lists the action types for the given Ontology. + + Each page may be smaller than the requested page size. However, it is guaranteed that if there are more + results available, at least one result will be present in the response. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListActionTypesResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v1/ontologies/{ontologyRid}/actionTypes", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={ + "ontologyRid": ontology_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListActionTypesResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + ontology_rid: OntologyRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListActionTypesResponse]: + """ + Lists the action types for the given Ontology. + + Each page may be smaller than the requested page size. However, it is guaranteed that if there are more + results available, at least one result will be present in the response. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListActionTypesResponse] + """ + + warnings.warn( + "The client.ontologies.ActionType.page(...) method has been deprecated. Please use client.ontologies.ActionType.list(...) instead.", DeprecationWarning, + stacklevel=2, ) return self._api_client.call_api( @@ -207,3 +386,175 @@ def page( request_timeout=request_timeout, ), ) + + +class _ActionTypeClientStreaming: + """ + The API client for the ActionType Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + ontology_rid: OntologyRid, + action_type_api_name: ActionTypeApiName, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ActionType]: + """ + Gets a specific action type with the given API name. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param action_type_api_name: actionTypeApiName + :type action_type_api_name: ActionTypeApiName + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ActionType] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v1/ontologies/{ontologyRid}/actionTypes/{actionTypeApiName}", + query_params={}, + path_params={ + "ontologyRid": ontology_rid, + "actionTypeApiName": action_type_api_name, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ActionType, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + ontology_rid: OntologyRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListActionTypesResponse]: + """ + Lists the action types for the given Ontology. + + Each page may be smaller than the requested page size. However, it is guaranteed that if there are more + results available, at least one result will be present in the response. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListActionTypesResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v1/ontologies/{ontologyRid}/actionTypes", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={ + "ontologyRid": ontology_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListActionTypesResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + ontology_rid: OntologyRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListActionTypesResponse]: + """ + Lists the action types for the given Ontology. + + Each page may be smaller than the requested page size. However, it is guaranteed that if there are more + results available, at least one result will be present in the response. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListActionTypesResponse] + """ + + warnings.warn( + "The client.ontologies.ActionType.page(...) method has been deprecated. Please use client.ontologies.ActionType.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v1/ontologies/{ontologyRid}/actionTypes", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={ + "ontologyRid": ontology_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListActionTypesResponse, + request_timeout=request_timeout, + ), + ) diff --git a/foundry/v1/ontologies/client.py b/foundry/v1/ontologies/client.py index 78f0fe06..37828b1a 100644 --- a/foundry/v1/ontologies/client.py +++ b/foundry/v1/ontologies/client.py @@ -30,7 +30,7 @@ class OntologiesClient: The API client for the Ontologies Namespace. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ diff --git a/foundry/v1/ontologies/errors/__init__.py b/foundry/v1/ontologies/errors/__init__.py index ac39fcf5..dde992e7 100644 --- a/foundry/v1/ontologies/errors/__init__.py +++ b/foundry/v1/ontologies/errors/__init__.py @@ -91,6 +91,7 @@ ) # NOQA from foundry.v1.ontologies.errors._invalid_fields import InvalidFields from foundry.v1.ontologies.errors._invalid_group_id import InvalidGroupId +from foundry.v1.ontologies.errors._invalid_order_type import InvalidOrderType from foundry.v1.ontologies.errors._invalid_parameter_value import InvalidParameterValue from foundry.v1.ontologies.errors._invalid_property_filter_value import ( InvalidPropertyFilterValue, @@ -182,6 +183,10 @@ PropertyFiltersNotSupported, ) # NOQA from foundry.v1.ontologies.errors._property_not_found import PropertyNotFound +from foundry.v1.ontologies.errors._property_type_does_not_support_nearest_neighbors import ( + PropertyTypeDoesNotSupportNearestNeighbors, +) # NOQA +from foundry.v1.ontologies.errors._property_type_not_found import PropertyTypeNotFound from foundry.v1.ontologies.errors._property_types_search_not_supported import ( PropertyTypesSearchNotSupported, ) # NOQA @@ -194,12 +199,18 @@ from foundry.v1.ontologies.errors._query_not_found import QueryNotFound from foundry.v1.ontologies.errors._query_runtime_error import QueryRuntimeError from foundry.v1.ontologies.errors._query_time_exceeded_limit import QueryTimeExceededLimit # NOQA +from foundry.v1.ontologies.errors._search_vector_dimensions_differ import ( + SearchVectorDimensionsDiffer, +) # NOQA from foundry.v1.ontologies.errors._shared_properties_not_found import ( SharedPropertiesNotFound, ) # NOQA from foundry.v1.ontologies.errors._shared_property_type_not_found import ( SharedPropertyTypeNotFound, ) # NOQA +from foundry.v1.ontologies.errors._too_many_nearest_neighbors_requested import ( + TooManyNearestNeighborsRequested, +) # NOQA from foundry.v1.ontologies.errors._unknown_parameter import UnknownParameter from foundry.v1.ontologies.errors._unsupported_object_set import UnsupportedObjectSet from foundry.v1.ontologies.errors._view_object_permission_denied import ( @@ -248,6 +259,7 @@ "InvalidApplyActionOptionCombination", "InterfaceTypesNotFound", "MarketplaceActionMappingNotFound", + "PropertyTypeDoesNotSupportNearestNeighbors", "InvalidFields", "InvalidQueryParameterValue", "ActionTypeNotFound", @@ -275,8 +287,9 @@ "EditObjectPermissionDenied", "PropertiesHaveDifferentIds", "OntologyNotFound", - "InvalidPropertyType", + "PropertyTypeNotFound", "MarketplaceInstallationNotFound", + "InvalidPropertyType", "ActionParameterObjectTypeNotFound", "UnknownParameter", "FunctionExecutionFailed", @@ -298,8 +311,11 @@ "SharedPropertiesNotFound", "InterfaceTypeNotFound", "AttachmentSizeExceededLimit", + "SearchVectorDimensionsDiffer", "ObjectNotFound", + "InvalidOrderType", "PropertyApiNameNotFound", + "TooManyNearestNeighborsRequested", "ParameterTypeNotSupported", "InvalidAggregationRangePropertyType", "MissingParameter", diff --git a/foundry/v1/ontologies/errors/_invalid_order_type.py b/foundry/v1/ontologies/errors/_invalid_order_type.py new file mode 100644 index 00000000..4300be19 --- /dev/null +++ b/foundry/v1/ontologies/errors/_invalid_order_type.py @@ -0,0 +1,44 @@ +# Copyright 2024 Palantir Technologies, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +from __future__ import annotations + +from dataclasses import dataclass +from typing import Literal + +import pydantic +from typing_extensions import NotRequired +from typing_extensions import TypedDict + +from foundry._errors import PalantirRPCException +from foundry.v1.ontologies.models._search_order_by_type import SearchOrderByType + + +class InvalidOrderTypeParameters(TypedDict): + """This query type does not support the provided order type""" + + __pydantic_config__ = {"extra": "allow"} # type: ignore + + orderType: NotRequired[SearchOrderByType] + + +@dataclass +class InvalidOrderType(PalantirRPCException): + name: Literal["InvalidOrderType"] + parameters: InvalidOrderTypeParameters + error_instance_id: str + + +__all__ = ["InvalidOrderType"] diff --git a/foundry/v1/ontologies/errors/_property_type_does_not_support_nearest_neighbors.py b/foundry/v1/ontologies/errors/_property_type_does_not_support_nearest_neighbors.py new file mode 100644 index 00000000..ca93f6ae --- /dev/null +++ b/foundry/v1/ontologies/errors/_property_type_does_not_support_nearest_neighbors.py @@ -0,0 +1,40 @@ +# Copyright 2024 Palantir Technologies, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +from __future__ import annotations + +from dataclasses import dataclass +from typing import Literal + +import pydantic +from typing_extensions import TypedDict + +from foundry._errors import PalantirRPCException + + +class PropertyTypeDoesNotSupportNearestNeighborsParameters(TypedDict): + """The provided propertyIdentifier is not configured with an embedding model in the ontology.""" + + __pydantic_config__ = {"extra": "allow"} # type: ignore + + +@dataclass +class PropertyTypeDoesNotSupportNearestNeighbors(PalantirRPCException): + name: Literal["PropertyTypeDoesNotSupportNearestNeighbors"] + parameters: PropertyTypeDoesNotSupportNearestNeighborsParameters + error_instance_id: str + + +__all__ = ["PropertyTypeDoesNotSupportNearestNeighbors"] diff --git a/foundry/v1/ontologies/errors/_property_type_not_found.py b/foundry/v1/ontologies/errors/_property_type_not_found.py new file mode 100644 index 00000000..3e3baa78 --- /dev/null +++ b/foundry/v1/ontologies/errors/_property_type_not_found.py @@ -0,0 +1,47 @@ +# Copyright 2024 Palantir Technologies, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +from __future__ import annotations + +from dataclasses import dataclass +from typing import Literal + +import pydantic +from typing_extensions import NotRequired +from typing_extensions import TypedDict + +from foundry._errors import PalantirRPCException +from foundry.v1.ontologies.models._object_type_api_name import ObjectTypeApiName +from foundry.v1.ontologies.models._property_api_name import PropertyApiName + + +class PropertyTypeNotFoundParameters(TypedDict): + """The requested property type is not found, or the client token does not have access to it.""" + + __pydantic_config__ = {"extra": "allow"} # type: ignore + + objectTypeApiName: NotRequired[ObjectTypeApiName] + + propertyApiName: NotRequired[PropertyApiName] + + +@dataclass +class PropertyTypeNotFound(PalantirRPCException): + name: Literal["PropertyTypeNotFound"] + parameters: PropertyTypeNotFoundParameters + error_instance_id: str + + +__all__ = ["PropertyTypeNotFound"] diff --git a/foundry/v1/ontologies/errors/_search_vector_dimensions_differ.py b/foundry/v1/ontologies/errors/_search_vector_dimensions_differ.py new file mode 100644 index 00000000..5c83e754 --- /dev/null +++ b/foundry/v1/ontologies/errors/_search_vector_dimensions_differ.py @@ -0,0 +1,40 @@ +# Copyright 2024 Palantir Technologies, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +from __future__ import annotations + +from dataclasses import dataclass +from typing import Literal + +import pydantic +from typing_extensions import TypedDict + +from foundry._errors import PalantirRPCException + + +class SearchVectorDimensionsDifferParameters(TypedDict): + """The dimensions of the provided vector don't match the dimensions of the embedding model being queried.""" + + __pydantic_config__ = {"extra": "allow"} # type: ignore + + +@dataclass +class SearchVectorDimensionsDiffer(PalantirRPCException): + name: Literal["SearchVectorDimensionsDiffer"] + parameters: SearchVectorDimensionsDifferParameters + error_instance_id: str + + +__all__ = ["SearchVectorDimensionsDiffer"] diff --git a/foundry/v1/ontologies/errors/_too_many_nearest_neighbors_requested.py b/foundry/v1/ontologies/errors/_too_many_nearest_neighbors_requested.py new file mode 100644 index 00000000..711d6996 --- /dev/null +++ b/foundry/v1/ontologies/errors/_too_many_nearest_neighbors_requested.py @@ -0,0 +1,40 @@ +# Copyright 2024 Palantir Technologies, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +from __future__ import annotations + +from dataclasses import dataclass +from typing import Literal + +import pydantic +from typing_extensions import TypedDict + +from foundry._errors import PalantirRPCException + + +class TooManyNearestNeighborsRequestedParameters(TypedDict): + """The value of numNeighbors must be in the range 1 <= numNeighbors <= 500.""" + + __pydantic_config__ = {"extra": "allow"} # type: ignore + + +@dataclass +class TooManyNearestNeighborsRequested(PalantirRPCException): + name: Literal["TooManyNearestNeighborsRequested"] + parameters: TooManyNearestNeighborsRequestedParameters + error_instance_id: str + + +__all__ = ["TooManyNearestNeighborsRequested"] diff --git a/foundry/v1/ontologies/models/__init__.py b/foundry/v1/ontologies/models/__init__.py index 2b72a368..a6984e0d 100644 --- a/foundry/v1/ontologies/models/__init__.py +++ b/foundry/v1/ontologies/models/__init__.py @@ -281,6 +281,7 @@ SearchObjectsResponseDict, ) # NOQA from foundry.v1.ontologies.models._search_order_by_dict import SearchOrderByDict +from foundry.v1.ontologies.models._search_order_by_type import SearchOrderByType from foundry.v1.ontologies.models._search_ordering_dict import SearchOrderingDict from foundry.v1.ontologies.models._selected_property_api_name import SelectedPropertyApiName # NOQA from foundry.v1.ontologies.models._shared_property_type_api_name import ( @@ -498,6 +499,7 @@ "SearchObjectsResponse", "SearchObjectsResponseDict", "SearchOrderByDict", + "SearchOrderByType", "SearchOrderingDict", "SelectedPropertyApiName", "SharedPropertyTypeApiName", diff --git a/foundry/v1/ontologies/models/_search_order_by_type.py b/foundry/v1/ontologies/models/_search_order_by_type.py new file mode 100644 index 00000000..fe5f854c --- /dev/null +++ b/foundry/v1/ontologies/models/_search_order_by_type.py @@ -0,0 +1,21 @@ +# Copyright 2024 Palantir Technologies, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +from __future__ import annotations + +from typing import Literal + +SearchOrderByType = Literal["fields", "relevance"] +"""SearchOrderByType""" diff --git a/foundry/v1/ontologies/object_type.py b/foundry/v1/ontologies/object_type.py index 012060c9..fb150110 100644 --- a/foundry/v1/ontologies/object_type.py +++ b/foundry/v1/ontologies/object_type.py @@ -24,10 +24,12 @@ from typing_extensions import Annotated from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo from foundry._core import ResourceIterator +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v1.core.models._page_size import PageSize @@ -48,7 +50,7 @@ class ObjectTypeClient: The API client for the ObjectType Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -59,6 +61,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _ObjectTypeClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _ObjectTypeClientRaw(auth=auth, hostname=hostname, config=config) @maybe_ignore_preview @pydantic.validate_call @@ -102,7 +108,7 @@ def get( response_type=ObjectType, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -151,7 +157,7 @@ def get_outgoing_link_type( response_type=LinkTypeSide, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -293,8 +299,9 @@ def page( """ warnings.warn( - "The ObjectTypeClient.page(...) method has been deprecated. Please use ObjectTypeClient.list(...) instead.", + "The client.ontologies.ObjectType.page(...) method has been deprecated. Please use client.ontologies.ObjectType.list(...) instead.", DeprecationWarning, + stacklevel=2, ) return self._api_client.call_api( @@ -316,7 +323,7 @@ def page( response_type=ListObjectTypesResponse, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -351,10 +358,229 @@ def page_outgoing_link_types( """ warnings.warn( - "The ObjectTypeClient.pageOutgoingLinkTypes(...) method has been deprecated. Please use ObjectTypeClient.listOutgoingLinkTypes(...) instead.", + "The client.ontologies.ObjectType.page_outgoing_link_types(...) method has been deprecated. Please use client.ontologies.ObjectType.list_outgoing_link_types(...) instead.", DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v1/ontologies/{ontologyRid}/objectTypes/{objectType}/outgoingLinkTypes", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={ + "ontologyRid": ontology_rid, + "objectType": object_type, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListOutgoingLinkTypesResponse, + request_timeout=request_timeout, + ), + ).decode() + + +class _ObjectTypeClientRaw: + """ + The API client for the ObjectType Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + ontology_rid: OntologyRid, + object_type: ObjectTypeApiName, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ObjectType]: + """ + Gets a specific object type with the given API name. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ObjectType] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v1/ontologies/{ontologyRid}/objectTypes/{objectType}", + query_params={}, + path_params={ + "ontologyRid": ontology_rid, + "objectType": object_type, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ObjectType, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get_outgoing_link_type( + self, + ontology_rid: OntologyRid, + object_type: ObjectTypeApiName, + link_type: LinkTypeApiName, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[LinkTypeSide]: + """ + Get an outgoing link for an object type. + + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-read`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param link_type: linkType + :type link_type: LinkTypeApiName + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[LinkTypeSide] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v1/ontologies/{ontologyRid}/objectTypes/{objectType}/outgoingLinkTypes/{linkType}", + query_params={}, + path_params={ + "ontologyRid": ontology_rid, + "objectType": object_type, + "linkType": link_type, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=LinkTypeSide, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + ontology_rid: OntologyRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListObjectTypesResponse]: + """ + Lists the object types for the given Ontology. + + Each page may be smaller or larger than the requested page size. However, it is guaranteed that if there are + more results available, at least one result will be present in the + response. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListObjectTypesResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v1/ontologies/{ontologyRid}/objectTypes", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={ + "ontologyRid": ontology_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListObjectTypesResponse, + request_timeout=request_timeout, + ), ) + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list_outgoing_link_types( + self, + ontology_rid: OntologyRid, + object_type: ObjectTypeApiName, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListOutgoingLinkTypesResponse]: + """ + List the outgoing links for an object type. + + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-read`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListOutgoingLinkTypesResponse] + """ + return self._api_client.call_api( RequestInfo( method="GET", @@ -376,3 +602,459 @@ def page_outgoing_link_types( request_timeout=request_timeout, ), ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + ontology_rid: OntologyRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListObjectTypesResponse]: + """ + Lists the object types for the given Ontology. + + Each page may be smaller or larger than the requested page size. However, it is guaranteed that if there are + more results available, at least one result will be present in the + response. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListObjectTypesResponse] + """ + + warnings.warn( + "The client.ontologies.ObjectType.page(...) method has been deprecated. Please use client.ontologies.ObjectType.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v1/ontologies/{ontologyRid}/objectTypes", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={ + "ontologyRid": ontology_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListObjectTypesResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page_outgoing_link_types( + self, + ontology_rid: OntologyRid, + object_type: ObjectTypeApiName, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListOutgoingLinkTypesResponse]: + """ + List the outgoing links for an object type. + + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-read`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListOutgoingLinkTypesResponse] + """ + + warnings.warn( + "The client.ontologies.ObjectType.page_outgoing_link_types(...) method has been deprecated. Please use client.ontologies.ObjectType.list_outgoing_link_types(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v1/ontologies/{ontologyRid}/objectTypes/{objectType}/outgoingLinkTypes", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={ + "ontologyRid": ontology_rid, + "objectType": object_type, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListOutgoingLinkTypesResponse, + request_timeout=request_timeout, + ), + ) + + +class _ObjectTypeClientStreaming: + """ + The API client for the ObjectType Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + ontology_rid: OntologyRid, + object_type: ObjectTypeApiName, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ObjectType]: + """ + Gets a specific object type with the given API name. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ObjectType] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v1/ontologies/{ontologyRid}/objectTypes/{objectType}", + query_params={}, + path_params={ + "ontologyRid": ontology_rid, + "objectType": object_type, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ObjectType, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get_outgoing_link_type( + self, + ontology_rid: OntologyRid, + object_type: ObjectTypeApiName, + link_type: LinkTypeApiName, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[LinkTypeSide]: + """ + Get an outgoing link for an object type. + + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-read`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param link_type: linkType + :type link_type: LinkTypeApiName + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[LinkTypeSide] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v1/ontologies/{ontologyRid}/objectTypes/{objectType}/outgoingLinkTypes/{linkType}", + query_params={}, + path_params={ + "ontologyRid": ontology_rid, + "objectType": object_type, + "linkType": link_type, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=LinkTypeSide, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + ontology_rid: OntologyRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListObjectTypesResponse]: + """ + Lists the object types for the given Ontology. + + Each page may be smaller or larger than the requested page size. However, it is guaranteed that if there are + more results available, at least one result will be present in the + response. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListObjectTypesResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v1/ontologies/{ontologyRid}/objectTypes", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={ + "ontologyRid": ontology_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListObjectTypesResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list_outgoing_link_types( + self, + ontology_rid: OntologyRid, + object_type: ObjectTypeApiName, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListOutgoingLinkTypesResponse]: + """ + List the outgoing links for an object type. + + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-read`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListOutgoingLinkTypesResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v1/ontologies/{ontologyRid}/objectTypes/{objectType}/outgoingLinkTypes", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={ + "ontologyRid": ontology_rid, + "objectType": object_type, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListOutgoingLinkTypesResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + ontology_rid: OntologyRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListObjectTypesResponse]: + """ + Lists the object types for the given Ontology. + + Each page may be smaller or larger than the requested page size. However, it is guaranteed that if there are + more results available, at least one result will be present in the + response. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListObjectTypesResponse] + """ + + warnings.warn( + "The client.ontologies.ObjectType.page(...) method has been deprecated. Please use client.ontologies.ObjectType.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v1/ontologies/{ontologyRid}/objectTypes", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={ + "ontologyRid": ontology_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListObjectTypesResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page_outgoing_link_types( + self, + ontology_rid: OntologyRid, + object_type: ObjectTypeApiName, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListOutgoingLinkTypesResponse]: + """ + List the outgoing links for an object type. + + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-read`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListOutgoingLinkTypesResponse] + """ + + warnings.warn( + "The client.ontologies.ObjectType.page_outgoing_link_types(...) method has been deprecated. Please use client.ontologies.ObjectType.list_outgoing_link_types(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v1/ontologies/{ontologyRid}/objectTypes/{objectType}/outgoingLinkTypes", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={ + "ontologyRid": ontology_rid, + "objectType": object_type, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListOutgoingLinkTypesResponse, + request_timeout=request_timeout, + ), + ) diff --git a/foundry/v1/ontologies/ontology.py b/foundry/v1/ontologies/ontology.py index e8458fd7..ed0a7f59 100644 --- a/foundry/v1/ontologies/ontology.py +++ b/foundry/v1/ontologies/ontology.py @@ -23,9 +23,11 @@ from typing_extensions import Annotated from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v1.ontologies.action_type import ActionTypeClient @@ -41,7 +43,7 @@ class OntologyClient: The API client for the Ontology Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -52,6 +54,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _OntologyClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _OntologyClientRaw(auth=auth, hostname=hostname, config=config) self.ActionType = ActionTypeClient(auth=auth, hostname=hostname, config=config) self.ObjectType = ObjectTypeClient(auth=auth, hostname=hostname, config=config) self.QueryType = QueryTypeClient(auth=auth, hostname=hostname, config=config) @@ -94,7 +100,7 @@ def get( response_type=Ontology, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -129,4 +135,190 @@ def list( response_type=ListOntologiesResponse, request_timeout=request_timeout, ), + ).decode() + + +class _OntologyClientRaw: + """ + The API client for the Ontology Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + ontology_rid: OntologyRid, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Ontology]: + """ + Gets a specific ontology with the given Ontology RID. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Ontology] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v1/ontologies/{ontologyRid}", + query_params={}, + path_params={ + "ontologyRid": ontology_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Ontology, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListOntologiesResponse]: + """ + Lists the Ontologies visible to the current user. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListOntologiesResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v1/ontologies", + query_params={}, + path_params={}, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListOntologiesResponse, + request_timeout=request_timeout, + ), + ) + + +class _OntologyClientStreaming: + """ + The API client for the Ontology Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + ontology_rid: OntologyRid, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Ontology]: + """ + Gets a specific ontology with the given Ontology RID. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Ontology] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v1/ontologies/{ontologyRid}", + query_params={}, + path_params={ + "ontologyRid": ontology_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Ontology, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListOntologiesResponse]: + """ + Lists the Ontologies visible to the current user. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListOntologiesResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v1/ontologies", + query_params={}, + path_params={}, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListOntologiesResponse, + request_timeout=request_timeout, + ), ) diff --git a/foundry/v1/ontologies/ontology_object.py b/foundry/v1/ontologies/ontology_object.py index 5fd1a089..8036b1ea 100644 --- a/foundry/v1/ontologies/ontology_object.py +++ b/foundry/v1/ontologies/ontology_object.py @@ -26,10 +26,12 @@ from typing_extensions import TypedDict from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo from foundry._core import ResourceIterator +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v1.core.models._page_size import PageSize @@ -63,7 +65,7 @@ class OntologyObjectClient: The API client for the OntologyObject Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -74,6 +76,12 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _OntologyObjectClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _OntologyObjectClientRaw( + auth=auth, hostname=hostname, config=config + ) @maybe_ignore_preview @pydantic.validate_call @@ -138,7 +146,7 @@ def aggregate( response_type=AggregateObjectsResponse, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -191,7 +199,7 @@ def get( response_type=OntologyObject, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -253,7 +261,7 @@ def get_linked_object( response_type=OntologyObject, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -468,8 +476,9 @@ def page( """ warnings.warn( - "The OntologyObjectClient.page(...) method has been deprecated. Please use OntologyObjectClient.list(...) instead.", + "The client.ontologies.OntologyObject.page(...) method has been deprecated. Please use client.ontologies.OntologyObject.list(...) instead.", DeprecationWarning, + stacklevel=2, ) return self._api_client.call_api( @@ -494,7 +503,7 @@ def page( response_type=ListObjectsResponse, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -555,8 +564,9 @@ def page_linked_objects( """ warnings.warn( - "The OntologyObjectClient.pageLinkedObjects(...) method has been deprecated. Please use OntologyObjectClient.listLinkedObjects(...) instead.", + "The client.ontologies.OntologyObject.page_linked_objects(...) method has been deprecated. Please use client.ontologies.OntologyObject.list_linked_objects(...) instead.", DeprecationWarning, + stacklevel=2, ) return self._api_client.call_api( @@ -583,7 +593,7 @@ def page_linked_objects( response_type=ListLinkedObjectsResponse, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -679,4 +689,1256 @@ def search( response_type=SearchObjectsResponse, request_timeout=request_timeout, ), + ).decode() + + +class _OntologyObjectClientRaw: + """ + The API client for the OntologyObject Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def aggregate( + self, + ontology_rid: OntologyRid, + object_type: ObjectTypeApiName, + *, + aggregation: List[AggregationDict], + group_by: List[AggregationGroupByDict], + query: Optional[SearchJsonQueryDict] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[AggregateObjectsResponse]: + """ + Perform functions on object fields in the specified ontology and object type. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param aggregation: + :type aggregation: List[AggregationDict] + :param group_by: + :type group_by: List[AggregationGroupByDict] + :param query: + :type query: Optional[SearchJsonQueryDict] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[AggregateObjectsResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v1/ontologies/{ontologyRid}/objects/{objectType}/aggregate", + query_params={}, + path_params={ + "ontologyRid": ontology_rid, + "objectType": object_type, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "aggregation": aggregation, + "query": query, + "groupBy": group_by, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "aggregation": List[AggregationDict], + "query": Optional[SearchJsonQueryDict], + "groupBy": List[AggregationGroupByDict], + }, + ), + response_type=AggregateObjectsResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + ontology_rid: OntologyRid, + object_type: ObjectTypeApiName, + primary_key: PropertyValueEscapedString, + *, + properties: Optional[List[SelectedPropertyApiName]] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[OntologyObject]: + """ + Gets a specific object with the given primary key. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param primary_key: primaryKey + :type primary_key: PropertyValueEscapedString + :param properties: properties + :type properties: Optional[List[SelectedPropertyApiName]] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[OntologyObject] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v1/ontologies/{ontologyRid}/objects/{objectType}/{primaryKey}", + query_params={ + "properties": properties, + }, + path_params={ + "ontologyRid": ontology_rid, + "objectType": object_type, + "primaryKey": primary_key, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=OntologyObject, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get_linked_object( + self, + ontology_rid: OntologyRid, + object_type: ObjectTypeApiName, + primary_key: PropertyValueEscapedString, + link_type: LinkTypeApiName, + linked_object_primary_key: PropertyValueEscapedString, + *, + properties: Optional[List[SelectedPropertyApiName]] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[OntologyObject]: + """ + Get a specific linked object that originates from another object. If there is no link between the two objects, + LinkedObjectNotFound is thrown. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param primary_key: primaryKey + :type primary_key: PropertyValueEscapedString + :param link_type: linkType + :type link_type: LinkTypeApiName + :param linked_object_primary_key: linkedObjectPrimaryKey + :type linked_object_primary_key: PropertyValueEscapedString + :param properties: properties + :type properties: Optional[List[SelectedPropertyApiName]] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[OntologyObject] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v1/ontologies/{ontologyRid}/objects/{objectType}/{primaryKey}/links/{linkType}/{linkedObjectPrimaryKey}", + query_params={ + "properties": properties, + }, + path_params={ + "ontologyRid": ontology_rid, + "objectType": object_type, + "primaryKey": primary_key, + "linkType": link_type, + "linkedObjectPrimaryKey": linked_object_primary_key, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=OntologyObject, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + ontology_rid: OntologyRid, + object_type: ObjectTypeApiName, + *, + order_by: Optional[OrderBy] = None, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + properties: Optional[List[SelectedPropertyApiName]] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListObjectsResponse]: + """ + Lists the objects for the given Ontology and object type. + + This endpoint supports filtering objects. + See the [Filtering Objects documentation](/docs/foundry/api/ontology-resources/objects/ontology-object-basics#filter-objects) for details. + + Note that this endpoint does not guarantee consistency. Changes to the data could result in missing or + repeated objects in the response pages. + + For Object Storage V1 backed objects, this endpoint returns a maximum of 10,000 objects. After 10,000 objects have been returned and if more objects + are available, attempting to load another page will result in an `ObjectsExceededLimit` error being returned. There is no limit on Object Storage V2 backed objects. + + Each page may be smaller or larger than the requested page size. However, it + is guaranteed that if there are more results available, at least one result will be present + in the response. + + Note that null value properties will not be returned. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param order_by: orderBy + :type order_by: Optional[OrderBy] + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param properties: properties + :type properties: Optional[List[SelectedPropertyApiName]] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListObjectsResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v1/ontologies/{ontologyRid}/objects/{objectType}", + query_params={ + "orderBy": order_by, + "pageSize": page_size, + "pageToken": page_token, + "properties": properties, + }, + path_params={ + "ontologyRid": ontology_rid, + "objectType": object_type, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListObjectsResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list_linked_objects( + self, + ontology_rid: OntologyRid, + object_type: ObjectTypeApiName, + primary_key: PropertyValueEscapedString, + link_type: LinkTypeApiName, + *, + order_by: Optional[OrderBy] = None, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + properties: Optional[List[SelectedPropertyApiName]] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListLinkedObjectsResponse]: + """ + Lists the linked objects for a specific object and the given link type. + + This endpoint supports filtering objects. + See the [Filtering Objects documentation](/docs/foundry/api/ontology-resources/objects/ontology-object-basics#filter-objects) for details. + + Note that this endpoint does not guarantee consistency. Changes to the data could result in missing or + repeated objects in the response pages. + + For Object Storage V1 backed objects, this endpoint returns a maximum of 10,000 objects. After 10,000 objects have been returned and if more objects + are available, attempting to load another page will result in an `ObjectsExceededLimit` error being returned. There is no limit on Object Storage V2 backed objects. + + Each page may be smaller or larger than the requested page size. However, it + is guaranteed that if there are more results available, at least one result will be present + in the response. + + Note that null value properties will not be returned. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param primary_key: primaryKey + :type primary_key: PropertyValueEscapedString + :param link_type: linkType + :type link_type: LinkTypeApiName + :param order_by: orderBy + :type order_by: Optional[OrderBy] + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param properties: properties + :type properties: Optional[List[SelectedPropertyApiName]] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListLinkedObjectsResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v1/ontologies/{ontologyRid}/objects/{objectType}/{primaryKey}/links/{linkType}", + query_params={ + "orderBy": order_by, + "pageSize": page_size, + "pageToken": page_token, + "properties": properties, + }, + path_params={ + "ontologyRid": ontology_rid, + "objectType": object_type, + "primaryKey": primary_key, + "linkType": link_type, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListLinkedObjectsResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + ontology_rid: OntologyRid, + object_type: ObjectTypeApiName, + *, + order_by: Optional[OrderBy] = None, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + properties: Optional[List[SelectedPropertyApiName]] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListObjectsResponse]: + """ + Lists the objects for the given Ontology and object type. + + This endpoint supports filtering objects. + See the [Filtering Objects documentation](/docs/foundry/api/ontology-resources/objects/ontology-object-basics#filter-objects) for details. + + Note that this endpoint does not guarantee consistency. Changes to the data could result in missing or + repeated objects in the response pages. + + For Object Storage V1 backed objects, this endpoint returns a maximum of 10,000 objects. After 10,000 objects have been returned and if more objects + are available, attempting to load another page will result in an `ObjectsExceededLimit` error being returned. There is no limit on Object Storage V2 backed objects. + + Each page may be smaller or larger than the requested page size. However, it + is guaranteed that if there are more results available, at least one result will be present + in the response. + + Note that null value properties will not be returned. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param order_by: orderBy + :type order_by: Optional[OrderBy] + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param properties: properties + :type properties: Optional[List[SelectedPropertyApiName]] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListObjectsResponse] + """ + + warnings.warn( + "The client.ontologies.OntologyObject.page(...) method has been deprecated. Please use client.ontologies.OntologyObject.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v1/ontologies/{ontologyRid}/objects/{objectType}", + query_params={ + "orderBy": order_by, + "pageSize": page_size, + "pageToken": page_token, + "properties": properties, + }, + path_params={ + "ontologyRid": ontology_rid, + "objectType": object_type, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListObjectsResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page_linked_objects( + self, + ontology_rid: OntologyRid, + object_type: ObjectTypeApiName, + primary_key: PropertyValueEscapedString, + link_type: LinkTypeApiName, + *, + order_by: Optional[OrderBy] = None, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + properties: Optional[List[SelectedPropertyApiName]] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListLinkedObjectsResponse]: + """ + Lists the linked objects for a specific object and the given link type. + + This endpoint supports filtering objects. + See the [Filtering Objects documentation](/docs/foundry/api/ontology-resources/objects/ontology-object-basics#filter-objects) for details. + + Note that this endpoint does not guarantee consistency. Changes to the data could result in missing or + repeated objects in the response pages. + + For Object Storage V1 backed objects, this endpoint returns a maximum of 10,000 objects. After 10,000 objects have been returned and if more objects + are available, attempting to load another page will result in an `ObjectsExceededLimit` error being returned. There is no limit on Object Storage V2 backed objects. + + Each page may be smaller or larger than the requested page size. However, it + is guaranteed that if there are more results available, at least one result will be present + in the response. + + Note that null value properties will not be returned. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param primary_key: primaryKey + :type primary_key: PropertyValueEscapedString + :param link_type: linkType + :type link_type: LinkTypeApiName + :param order_by: orderBy + :type order_by: Optional[OrderBy] + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param properties: properties + :type properties: Optional[List[SelectedPropertyApiName]] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListLinkedObjectsResponse] + """ + + warnings.warn( + "The client.ontologies.OntologyObject.page_linked_objects(...) method has been deprecated. Please use client.ontologies.OntologyObject.list_linked_objects(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v1/ontologies/{ontologyRid}/objects/{objectType}/{primaryKey}/links/{linkType}", + query_params={ + "orderBy": order_by, + "pageSize": page_size, + "pageToken": page_token, + "properties": properties, + }, + path_params={ + "ontologyRid": ontology_rid, + "objectType": object_type, + "primaryKey": primary_key, + "linkType": link_type, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListLinkedObjectsResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def search( + self, + ontology_rid: OntologyRid, + object_type: ObjectTypeApiName, + *, + fields: List[PropertyApiName], + query: SearchJsonQueryDict, + order_by: Optional[SearchOrderByDict] = None, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[SearchObjectsResponse]: + """ + Search for objects in the specified ontology and object type. The request body is used + to filter objects based on the specified query. The supported queries are: + + | Query type | Description | Supported Types | + |----------|-----------------------------------------------------------------------------------|---------------------------------| + | lt | The provided property is less than the provided value. | number, string, date, timestamp | + | gt | The provided property is greater than the provided value. | number, string, date, timestamp | + | lte | The provided property is less than or equal to the provided value. | number, string, date, timestamp | + | gte | The provided property is greater than or equal to the provided value. | number, string, date, timestamp | + | eq | The provided property is exactly equal to the provided value. | number, string, date, timestamp | + | isNull | The provided property is (or is not) null. | all | + | contains | The provided property contains the provided value. | array | + | not | The sub-query does not match. | N/A (applied on a query) | + | and | All the sub-queries match. | N/A (applied on queries) | + | or | At least one of the sub-queries match. | N/A (applied on queries) | + | prefix | The provided property starts with the provided term. | string | + | phrase | The provided property contains the provided term as a substring. | string | + | anyTerm | The provided property contains at least one of the terms separated by whitespace. | string | + | allTerms | The provided property contains all the terms separated by whitespace. | string | + + Queries can be at most three levels deep. By default, terms are separated by whitespace or punctuation (`?!,:;-[](){}'"~`). Periods (`.`) on their own are ignored. + Partial terms are not matched by terms filters except where explicitly noted. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param fields: The API names of the object type properties to include in the response. + :type fields: List[PropertyApiName] + :param query: + :type query: SearchJsonQueryDict + :param order_by: + :type order_by: Optional[SearchOrderByDict] + :param page_size: + :type page_size: Optional[PageSize] + :param page_token: + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[SearchObjectsResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v1/ontologies/{ontologyRid}/objects/{objectType}/search", + query_params={}, + path_params={ + "ontologyRid": ontology_rid, + "objectType": object_type, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "query": query, + "orderBy": order_by, + "pageSize": page_size, + "pageToken": page_token, + "fields": fields, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "query": SearchJsonQueryDict, + "orderBy": Optional[SearchOrderByDict], + "pageSize": Optional[PageSize], + "pageToken": Optional[PageToken], + "fields": List[PropertyApiName], + }, + ), + response_type=SearchObjectsResponse, + request_timeout=request_timeout, + ), + ) + + +class _OntologyObjectClientStreaming: + """ + The API client for the OntologyObject Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def aggregate( + self, + ontology_rid: OntologyRid, + object_type: ObjectTypeApiName, + *, + aggregation: List[AggregationDict], + group_by: List[AggregationGroupByDict], + query: Optional[SearchJsonQueryDict] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[AggregateObjectsResponse]: + """ + Perform functions on object fields in the specified ontology and object type. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param aggregation: + :type aggregation: List[AggregationDict] + :param group_by: + :type group_by: List[AggregationGroupByDict] + :param query: + :type query: Optional[SearchJsonQueryDict] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[AggregateObjectsResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v1/ontologies/{ontologyRid}/objects/{objectType}/aggregate", + query_params={}, + path_params={ + "ontologyRid": ontology_rid, + "objectType": object_type, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "aggregation": aggregation, + "query": query, + "groupBy": group_by, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "aggregation": List[AggregationDict], + "query": Optional[SearchJsonQueryDict], + "groupBy": List[AggregationGroupByDict], + }, + ), + response_type=AggregateObjectsResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + ontology_rid: OntologyRid, + object_type: ObjectTypeApiName, + primary_key: PropertyValueEscapedString, + *, + properties: Optional[List[SelectedPropertyApiName]] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[OntologyObject]: + """ + Gets a specific object with the given primary key. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param primary_key: primaryKey + :type primary_key: PropertyValueEscapedString + :param properties: properties + :type properties: Optional[List[SelectedPropertyApiName]] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[OntologyObject] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v1/ontologies/{ontologyRid}/objects/{objectType}/{primaryKey}", + query_params={ + "properties": properties, + }, + path_params={ + "ontologyRid": ontology_rid, + "objectType": object_type, + "primaryKey": primary_key, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=OntologyObject, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get_linked_object( + self, + ontology_rid: OntologyRid, + object_type: ObjectTypeApiName, + primary_key: PropertyValueEscapedString, + link_type: LinkTypeApiName, + linked_object_primary_key: PropertyValueEscapedString, + *, + properties: Optional[List[SelectedPropertyApiName]] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[OntologyObject]: + """ + Get a specific linked object that originates from another object. If there is no link between the two objects, + LinkedObjectNotFound is thrown. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param primary_key: primaryKey + :type primary_key: PropertyValueEscapedString + :param link_type: linkType + :type link_type: LinkTypeApiName + :param linked_object_primary_key: linkedObjectPrimaryKey + :type linked_object_primary_key: PropertyValueEscapedString + :param properties: properties + :type properties: Optional[List[SelectedPropertyApiName]] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[OntologyObject] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v1/ontologies/{ontologyRid}/objects/{objectType}/{primaryKey}/links/{linkType}/{linkedObjectPrimaryKey}", + query_params={ + "properties": properties, + }, + path_params={ + "ontologyRid": ontology_rid, + "objectType": object_type, + "primaryKey": primary_key, + "linkType": link_type, + "linkedObjectPrimaryKey": linked_object_primary_key, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=OntologyObject, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + ontology_rid: OntologyRid, + object_type: ObjectTypeApiName, + *, + order_by: Optional[OrderBy] = None, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + properties: Optional[List[SelectedPropertyApiName]] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListObjectsResponse]: + """ + Lists the objects for the given Ontology and object type. + + This endpoint supports filtering objects. + See the [Filtering Objects documentation](/docs/foundry/api/ontology-resources/objects/ontology-object-basics#filter-objects) for details. + + Note that this endpoint does not guarantee consistency. Changes to the data could result in missing or + repeated objects in the response pages. + + For Object Storage V1 backed objects, this endpoint returns a maximum of 10,000 objects. After 10,000 objects have been returned and if more objects + are available, attempting to load another page will result in an `ObjectsExceededLimit` error being returned. There is no limit on Object Storage V2 backed objects. + + Each page may be smaller or larger than the requested page size. However, it + is guaranteed that if there are more results available, at least one result will be present + in the response. + + Note that null value properties will not be returned. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param order_by: orderBy + :type order_by: Optional[OrderBy] + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param properties: properties + :type properties: Optional[List[SelectedPropertyApiName]] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListObjectsResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v1/ontologies/{ontologyRid}/objects/{objectType}", + query_params={ + "orderBy": order_by, + "pageSize": page_size, + "pageToken": page_token, + "properties": properties, + }, + path_params={ + "ontologyRid": ontology_rid, + "objectType": object_type, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListObjectsResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list_linked_objects( + self, + ontology_rid: OntologyRid, + object_type: ObjectTypeApiName, + primary_key: PropertyValueEscapedString, + link_type: LinkTypeApiName, + *, + order_by: Optional[OrderBy] = None, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + properties: Optional[List[SelectedPropertyApiName]] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListLinkedObjectsResponse]: + """ + Lists the linked objects for a specific object and the given link type. + + This endpoint supports filtering objects. + See the [Filtering Objects documentation](/docs/foundry/api/ontology-resources/objects/ontology-object-basics#filter-objects) for details. + + Note that this endpoint does not guarantee consistency. Changes to the data could result in missing or + repeated objects in the response pages. + + For Object Storage V1 backed objects, this endpoint returns a maximum of 10,000 objects. After 10,000 objects have been returned and if more objects + are available, attempting to load another page will result in an `ObjectsExceededLimit` error being returned. There is no limit on Object Storage V2 backed objects. + + Each page may be smaller or larger than the requested page size. However, it + is guaranteed that if there are more results available, at least one result will be present + in the response. + + Note that null value properties will not be returned. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param primary_key: primaryKey + :type primary_key: PropertyValueEscapedString + :param link_type: linkType + :type link_type: LinkTypeApiName + :param order_by: orderBy + :type order_by: Optional[OrderBy] + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param properties: properties + :type properties: Optional[List[SelectedPropertyApiName]] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListLinkedObjectsResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v1/ontologies/{ontologyRid}/objects/{objectType}/{primaryKey}/links/{linkType}", + query_params={ + "orderBy": order_by, + "pageSize": page_size, + "pageToken": page_token, + "properties": properties, + }, + path_params={ + "ontologyRid": ontology_rid, + "objectType": object_type, + "primaryKey": primary_key, + "linkType": link_type, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListLinkedObjectsResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + ontology_rid: OntologyRid, + object_type: ObjectTypeApiName, + *, + order_by: Optional[OrderBy] = None, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + properties: Optional[List[SelectedPropertyApiName]] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListObjectsResponse]: + """ + Lists the objects for the given Ontology and object type. + + This endpoint supports filtering objects. + See the [Filtering Objects documentation](/docs/foundry/api/ontology-resources/objects/ontology-object-basics#filter-objects) for details. + + Note that this endpoint does not guarantee consistency. Changes to the data could result in missing or + repeated objects in the response pages. + + For Object Storage V1 backed objects, this endpoint returns a maximum of 10,000 objects. After 10,000 objects have been returned and if more objects + are available, attempting to load another page will result in an `ObjectsExceededLimit` error being returned. There is no limit on Object Storage V2 backed objects. + + Each page may be smaller or larger than the requested page size. However, it + is guaranteed that if there are more results available, at least one result will be present + in the response. + + Note that null value properties will not be returned. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param order_by: orderBy + :type order_by: Optional[OrderBy] + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param properties: properties + :type properties: Optional[List[SelectedPropertyApiName]] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListObjectsResponse] + """ + + warnings.warn( + "The client.ontologies.OntologyObject.page(...) method has been deprecated. Please use client.ontologies.OntologyObject.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v1/ontologies/{ontologyRid}/objects/{objectType}", + query_params={ + "orderBy": order_by, + "pageSize": page_size, + "pageToken": page_token, + "properties": properties, + }, + path_params={ + "ontologyRid": ontology_rid, + "objectType": object_type, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListObjectsResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page_linked_objects( + self, + ontology_rid: OntologyRid, + object_type: ObjectTypeApiName, + primary_key: PropertyValueEscapedString, + link_type: LinkTypeApiName, + *, + order_by: Optional[OrderBy] = None, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + properties: Optional[List[SelectedPropertyApiName]] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListLinkedObjectsResponse]: + """ + Lists the linked objects for a specific object and the given link type. + + This endpoint supports filtering objects. + See the [Filtering Objects documentation](/docs/foundry/api/ontology-resources/objects/ontology-object-basics#filter-objects) for details. + + Note that this endpoint does not guarantee consistency. Changes to the data could result in missing or + repeated objects in the response pages. + + For Object Storage V1 backed objects, this endpoint returns a maximum of 10,000 objects. After 10,000 objects have been returned and if more objects + are available, attempting to load another page will result in an `ObjectsExceededLimit` error being returned. There is no limit on Object Storage V2 backed objects. + + Each page may be smaller or larger than the requested page size. However, it + is guaranteed that if there are more results available, at least one result will be present + in the response. + + Note that null value properties will not be returned. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param primary_key: primaryKey + :type primary_key: PropertyValueEscapedString + :param link_type: linkType + :type link_type: LinkTypeApiName + :param order_by: orderBy + :type order_by: Optional[OrderBy] + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param properties: properties + :type properties: Optional[List[SelectedPropertyApiName]] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListLinkedObjectsResponse] + """ + + warnings.warn( + "The client.ontologies.OntologyObject.page_linked_objects(...) method has been deprecated. Please use client.ontologies.OntologyObject.list_linked_objects(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v1/ontologies/{ontologyRid}/objects/{objectType}/{primaryKey}/links/{linkType}", + query_params={ + "orderBy": order_by, + "pageSize": page_size, + "pageToken": page_token, + "properties": properties, + }, + path_params={ + "ontologyRid": ontology_rid, + "objectType": object_type, + "primaryKey": primary_key, + "linkType": link_type, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListLinkedObjectsResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def search( + self, + ontology_rid: OntologyRid, + object_type: ObjectTypeApiName, + *, + fields: List[PropertyApiName], + query: SearchJsonQueryDict, + order_by: Optional[SearchOrderByDict] = None, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[SearchObjectsResponse]: + """ + Search for objects in the specified ontology and object type. The request body is used + to filter objects based on the specified query. The supported queries are: + + | Query type | Description | Supported Types | + |----------|-----------------------------------------------------------------------------------|---------------------------------| + | lt | The provided property is less than the provided value. | number, string, date, timestamp | + | gt | The provided property is greater than the provided value. | number, string, date, timestamp | + | lte | The provided property is less than or equal to the provided value. | number, string, date, timestamp | + | gte | The provided property is greater than or equal to the provided value. | number, string, date, timestamp | + | eq | The provided property is exactly equal to the provided value. | number, string, date, timestamp | + | isNull | The provided property is (or is not) null. | all | + | contains | The provided property contains the provided value. | array | + | not | The sub-query does not match. | N/A (applied on a query) | + | and | All the sub-queries match. | N/A (applied on queries) | + | or | At least one of the sub-queries match. | N/A (applied on queries) | + | prefix | The provided property starts with the provided term. | string | + | phrase | The provided property contains the provided term as a substring. | string | + | anyTerm | The provided property contains at least one of the terms separated by whitespace. | string | + | allTerms | The provided property contains all the terms separated by whitespace. | string | + + Queries can be at most three levels deep. By default, terms are separated by whitespace or punctuation (`?!,:;-[](){}'"~`). Periods (`.`) on their own are ignored. + Partial terms are not matched by terms filters except where explicitly noted. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param fields: The API names of the object type properties to include in the response. + :type fields: List[PropertyApiName] + :param query: + :type query: SearchJsonQueryDict + :param order_by: + :type order_by: Optional[SearchOrderByDict] + :param page_size: + :type page_size: Optional[PageSize] + :param page_token: + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[SearchObjectsResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v1/ontologies/{ontologyRid}/objects/{objectType}/search", + query_params={}, + path_params={ + "ontologyRid": ontology_rid, + "objectType": object_type, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "query": query, + "orderBy": order_by, + "pageSize": page_size, + "pageToken": page_token, + "fields": fields, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "query": SearchJsonQueryDict, + "orderBy": Optional[SearchOrderByDict], + "pageSize": Optional[PageSize], + "pageToken": Optional[PageToken], + "fields": List[PropertyApiName], + }, + ), + response_type=SearchObjectsResponse, + request_timeout=request_timeout, + ), ) diff --git a/foundry/v1/ontologies/query.py b/foundry/v1/ontologies/query.py index fd37eaea..07f783ad 100644 --- a/foundry/v1/ontologies/query.py +++ b/foundry/v1/ontologies/query.py @@ -24,9 +24,11 @@ from typing_extensions import TypedDict from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v1.ontologies.models._data_value import DataValue @@ -41,7 +43,7 @@ class QueryClient: The API client for the Query Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -52,6 +54,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _QueryClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _QueryClientRaw(auth=auth, hostname=hostname, config=config) @maybe_ignore_preview @pydantic.validate_call @@ -106,4 +112,150 @@ def execute( response_type=ExecuteQueryResponse, request_timeout=request_timeout, ), + ).decode() + + +class _QueryClientRaw: + """ + The API client for the Query Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def execute( + self, + ontology_rid: OntologyRid, + query_api_name: QueryApiName, + *, + parameters: Dict[ParameterId, Optional[DataValue]], + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ExecuteQueryResponse]: + """ + Executes a Query using the given parameters. Optional parameters do not need to be supplied. + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-read`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param query_api_name: queryApiName + :type query_api_name: QueryApiName + :param parameters: + :type parameters: Dict[ParameterId, Optional[DataValue]] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ExecuteQueryResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v1/ontologies/{ontologyRid}/queries/{queryApiName}/execute", + query_params={}, + path_params={ + "ontologyRid": ontology_rid, + "queryApiName": query_api_name, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "parameters": parameters, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "parameters": Dict[ParameterId, Optional[DataValue]], + }, + ), + response_type=ExecuteQueryResponse, + request_timeout=request_timeout, + ), + ) + + +class _QueryClientStreaming: + """ + The API client for the Query Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def execute( + self, + ontology_rid: OntologyRid, + query_api_name: QueryApiName, + *, + parameters: Dict[ParameterId, Optional[DataValue]], + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ExecuteQueryResponse]: + """ + Executes a Query using the given parameters. Optional parameters do not need to be supplied. + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-read`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param query_api_name: queryApiName + :type query_api_name: QueryApiName + :param parameters: + :type parameters: Dict[ParameterId, Optional[DataValue]] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ExecuteQueryResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v1/ontologies/{ontologyRid}/queries/{queryApiName}/execute", + query_params={}, + path_params={ + "ontologyRid": ontology_rid, + "queryApiName": query_api_name, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "parameters": parameters, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "parameters": Dict[ParameterId, Optional[DataValue]], + }, + ), + response_type=ExecuteQueryResponse, + request_timeout=request_timeout, + ), ) diff --git a/foundry/v1/ontologies/query_type.py b/foundry/v1/ontologies/query_type.py index 63603aa2..372e9a0d 100644 --- a/foundry/v1/ontologies/query_type.py +++ b/foundry/v1/ontologies/query_type.py @@ -24,10 +24,12 @@ from typing_extensions import Annotated from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo from foundry._core import ResourceIterator +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v1.core.models._page_size import PageSize @@ -43,7 +45,7 @@ class QueryTypeClient: The API client for the QueryType Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -54,6 +56,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _QueryTypeClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _QueryTypeClientRaw(auth=auth, hostname=hostname, config=config) @maybe_ignore_preview @pydantic.validate_call @@ -97,7 +103,7 @@ def get( response_type=QueryType, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -183,8 +189,181 @@ def page( """ warnings.warn( - "The QueryTypeClient.page(...) method has been deprecated. Please use QueryTypeClient.list(...) instead.", + "The client.ontologies.QueryType.page(...) method has been deprecated. Please use client.ontologies.QueryType.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v1/ontologies/{ontologyRid}/queryTypes", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={ + "ontologyRid": ontology_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListQueryTypesResponse, + request_timeout=request_timeout, + ), + ).decode() + + +class _QueryTypeClientRaw: + """ + The API client for the QueryType Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + ontology_rid: OntologyRid, + query_api_name: QueryApiName, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[QueryType]: + """ + Gets a specific query type with the given API name. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param query_api_name: queryApiName + :type query_api_name: QueryApiName + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[QueryType] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v1/ontologies/{ontologyRid}/queryTypes/{queryApiName}", + query_params={}, + path_params={ + "ontologyRid": ontology_rid, + "queryApiName": query_api_name, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=QueryType, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + ontology_rid: OntologyRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListQueryTypesResponse]: + """ + Lists the query types for the given Ontology. + + Each page may be smaller than the requested page size. However, it is guaranteed that if there are more + results available, at least one result will be present in the response. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListQueryTypesResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v1/ontologies/{ontologyRid}/queryTypes", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={ + "ontologyRid": ontology_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListQueryTypesResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + ontology_rid: OntologyRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListQueryTypesResponse]: + """ + Lists the query types for the given Ontology. + + Each page may be smaller than the requested page size. However, it is guaranteed that if there are more + results available, at least one result will be present in the response. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListQueryTypesResponse] + """ + + warnings.warn( + "The client.ontologies.QueryType.page(...) method has been deprecated. Please use client.ontologies.QueryType.list(...) instead.", DeprecationWarning, + stacklevel=2, ) return self._api_client.call_api( @@ -207,3 +386,175 @@ def page( request_timeout=request_timeout, ), ) + + +class _QueryTypeClientStreaming: + """ + The API client for the QueryType Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + ontology_rid: OntologyRid, + query_api_name: QueryApiName, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[QueryType]: + """ + Gets a specific query type with the given API name. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param query_api_name: queryApiName + :type query_api_name: QueryApiName + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[QueryType] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v1/ontologies/{ontologyRid}/queryTypes/{queryApiName}", + query_params={}, + path_params={ + "ontologyRid": ontology_rid, + "queryApiName": query_api_name, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=QueryType, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + ontology_rid: OntologyRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListQueryTypesResponse]: + """ + Lists the query types for the given Ontology. + + Each page may be smaller than the requested page size. However, it is guaranteed that if there are more + results available, at least one result will be present in the response. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListQueryTypesResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v1/ontologies/{ontologyRid}/queryTypes", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={ + "ontologyRid": ontology_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListQueryTypesResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + ontology_rid: OntologyRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListQueryTypesResponse]: + """ + Lists the query types for the given Ontology. + + Each page may be smaller than the requested page size. However, it is guaranteed that if there are more + results available, at least one result will be present in the response. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology_rid: ontologyRid + :type ontology_rid: OntologyRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListQueryTypesResponse] + """ + + warnings.warn( + "The client.ontologies.QueryType.page(...) method has been deprecated. Please use client.ontologies.QueryType.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v1/ontologies/{ontologyRid}/queryTypes", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={ + "ontologyRid": ontology_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListQueryTypesResponse, + request_timeout=request_timeout, + ), + ) diff --git a/foundry/v2/admin/client.py b/foundry/v2/admin/client.py index c44b13a0..9b4aa01c 100644 --- a/foundry/v2/admin/client.py +++ b/foundry/v2/admin/client.py @@ -31,7 +31,7 @@ class AdminClient: The API client for the Admin Namespace. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ diff --git a/foundry/v2/admin/enrollment.py b/foundry/v2/admin/enrollment.py index 5b88f07c..6b4ca8f7 100644 --- a/foundry/v2/admin/enrollment.py +++ b/foundry/v2/admin/enrollment.py @@ -23,9 +23,11 @@ from typing_extensions import Annotated from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.admin.host import HostClient @@ -39,7 +41,7 @@ class EnrollmentClient: The API client for the Enrollment Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -50,6 +52,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _EnrollmentClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _EnrollmentClientRaw(auth=auth, hostname=hostname, config=config) self.Host = HostClient(auth=auth, hostname=hostname, config=config) @maybe_ignore_preview @@ -92,7 +98,7 @@ def get( response_type=Enrollment, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -130,4 +136,200 @@ def get_current( response_type=Enrollment, request_timeout=request_timeout, ), + ).decode() + + +class _EnrollmentClientRaw: + """ + The API client for the Enrollment Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + enrollment_rid: EnrollmentRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Enrollment]: + """ + Get the Enrollment with the specified rid. + :param enrollment_rid: enrollmentRid + :type enrollment_rid: EnrollmentRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Enrollment] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/enrollments/{enrollmentRid}", + query_params={ + "preview": preview, + }, + path_params={ + "enrollmentRid": enrollment_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Enrollment, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get_current( + self, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Enrollment]: + """ + Returns the Enrollment associated with the current User's primary organization. + + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Enrollment] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/enrollments/getCurrent", + query_params={ + "preview": preview, + }, + path_params={}, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Enrollment, + request_timeout=request_timeout, + ), + ) + + +class _EnrollmentClientStreaming: + """ + The API client for the Enrollment Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + enrollment_rid: EnrollmentRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Enrollment]: + """ + Get the Enrollment with the specified rid. + :param enrollment_rid: enrollmentRid + :type enrollment_rid: EnrollmentRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Enrollment] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/enrollments/{enrollmentRid}", + query_params={ + "preview": preview, + }, + path_params={ + "enrollmentRid": enrollment_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Enrollment, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get_current( + self, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Enrollment]: + """ + Returns the Enrollment associated with the current User's primary organization. + + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Enrollment] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/enrollments/getCurrent", + query_params={ + "preview": preview, + }, + path_params={}, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Enrollment, + request_timeout=request_timeout, + ), ) diff --git a/foundry/v2/admin/group.py b/foundry/v2/admin/group.py index 37486732..2a9e9a96 100644 --- a/foundry/v2/admin/group.py +++ b/foundry/v2/admin/group.py @@ -27,10 +27,12 @@ from typing_extensions import TypedDict from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo from foundry._core import ResourceIterator +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.admin.group_member import GroupMemberClient @@ -56,7 +58,7 @@ class GroupClient: The API client for the Group Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -67,6 +69,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _GroupClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _GroupClientRaw(auth=auth, hostname=hostname, config=config) self.GroupMember = GroupMemberClient(auth=auth, hostname=hostname, config=config) @maybe_ignore_preview @@ -125,7 +131,7 @@ def create( response_type=Group, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -160,7 +166,7 @@ def delete( response_type=None, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -197,7 +203,7 @@ def get( response_type=Group, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -237,7 +243,7 @@ def get_batch( response_type=GetGroupsBatchResponse, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -307,8 +313,9 @@ def page( """ warnings.warn( - "The GroupClient.page(...) method has been deprecated. Please use GroupClient.list(...) instead.", + "The client.admin.Group.page(...) method has been deprecated. Please use client.admin.Group.list(...) instead.", DeprecationWarning, + stacklevel=2, ) return self._api_client.call_api( @@ -328,7 +335,7 @@ def page( response_type=ListGroupsResponse, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -381,4 +388,670 @@ def search( response_type=SearchGroupsResponse, request_timeout=request_timeout, ), + ).decode() + + +class _GroupClientRaw: + """ + The API client for the Group Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def create( + self, + *, + attributes: Dict[AttributeName, AttributeValues], + name: GroupName, + organizations: List[OrganizationRid], + description: Optional[str] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Group]: + """ + Creates a new Group. + :param attributes: A map of the Group's attributes. Attributes prefixed with "multipass:" are reserved for internal use by Foundry and are subject to change. + :type attributes: Dict[AttributeName, AttributeValues] + :param name: The name of the Group. + :type name: GroupName + :param organizations: The RIDs of the Organizations whose members can see this group. At least one Organization RID must be listed. + :type organizations: List[OrganizationRid] + :param description: A description of the Group. + :type description: Optional[str] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Group] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/admin/groups", + query_params={}, + path_params={}, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "name": name, + "organizations": organizations, + "description": description, + "attributes": attributes, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "name": GroupName, + "organizations": List[OrganizationRid], + "description": Optional[str], + "attributes": Dict[AttributeName, AttributeValues], + }, + ), + response_type=Group, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def delete( + self, + group_id: PrincipalId, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[None]: + """ + Delete the Group with the specified id. + :param group_id: groupId + :type group_id: PrincipalId + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[None] + """ + + return self._api_client.call_api( + RequestInfo( + method="DELETE", + resource_path="/v2/admin/groups/{groupId}", + query_params={}, + path_params={ + "groupId": group_id, + }, + header_params={}, + body=None, + body_type=None, + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + group_id: PrincipalId, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Group]: + """ + Get the Group with the specified id. + :param group_id: groupId + :type group_id: PrincipalId + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Group] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/groups/{groupId}", + query_params={}, + path_params={ + "groupId": group_id, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Group, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get_batch( + self, + body: Annotated[List[GetGroupsBatchRequestElementDict], Len(min_length=1, max_length=500)], + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[GetGroupsBatchResponse]: + """ + Execute multiple get requests on Group. + + The maximum batch size for this endpoint is 500. + :param body: Body of the request + :type body: Annotated[List[GetGroupsBatchRequestElementDict], Len(min_length=1, max_length=500)] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[GetGroupsBatchResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/admin/groups/getBatch", + query_params={}, + path_params={}, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body=body, + body_type=Annotated[ + List[GetGroupsBatchRequestElementDict], Len(min_length=1, max_length=500) + ], + response_type=GetGroupsBatchResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListGroupsResponse]: + """ + Lists all Groups. + + This is a paged endpoint. Each page may be smaller or larger than the requested page size. However, it is guaranteed that if there are more results available, the `nextPageToken` field will be populated. To get the next page, make the same request again, but set the value of the `pageToken` query parameter to be value of the `nextPageToken` value of the previous response. If there is no `nextPageToken` field in the response, you are on the last page. + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListGroupsResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/groups", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={}, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListGroupsResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListGroupsResponse]: + """ + Lists all Groups. + + This is a paged endpoint. Each page may be smaller or larger than the requested page size. However, it is guaranteed that if there are more results available, the `nextPageToken` field will be populated. To get the next page, make the same request again, but set the value of the `pageToken` query parameter to be value of the `nextPageToken` value of the previous response. If there is no `nextPageToken` field in the response, you are on the last page. + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListGroupsResponse] + """ + + warnings.warn( + "The client.admin.Group.page(...) method has been deprecated. Please use client.admin.Group.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/groups", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={}, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListGroupsResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def search( + self, + *, + where: GroupSearchFilterDict, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[SearchGroupsResponse]: + """ + + :param where: + :type where: GroupSearchFilterDict + :param page_size: + :type page_size: Optional[PageSize] + :param page_token: + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[SearchGroupsResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/admin/groups/search", + query_params={}, + path_params={}, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "where": where, + "pageSize": page_size, + "pageToken": page_token, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "where": GroupSearchFilterDict, + "pageSize": Optional[PageSize], + "pageToken": Optional[PageToken], + }, + ), + response_type=SearchGroupsResponse, + request_timeout=request_timeout, + ), + ) + + +class _GroupClientStreaming: + """ + The API client for the Group Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def create( + self, + *, + attributes: Dict[AttributeName, AttributeValues], + name: GroupName, + organizations: List[OrganizationRid], + description: Optional[str] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Group]: + """ + Creates a new Group. + :param attributes: A map of the Group's attributes. Attributes prefixed with "multipass:" are reserved for internal use by Foundry and are subject to change. + :type attributes: Dict[AttributeName, AttributeValues] + :param name: The name of the Group. + :type name: GroupName + :param organizations: The RIDs of the Organizations whose members can see this group. At least one Organization RID must be listed. + :type organizations: List[OrganizationRid] + :param description: A description of the Group. + :type description: Optional[str] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Group] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/admin/groups", + query_params={}, + path_params={}, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "name": name, + "organizations": organizations, + "description": description, + "attributes": attributes, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "name": GroupName, + "organizations": List[OrganizationRid], + "description": Optional[str], + "attributes": Dict[AttributeName, AttributeValues], + }, + ), + response_type=Group, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def delete( + self, + group_id: PrincipalId, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[None]: + """ + Delete the Group with the specified id. + :param group_id: groupId + :type group_id: PrincipalId + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[None] + """ + + return self._api_client.stream_api( + RequestInfo( + method="DELETE", + resource_path="/v2/admin/groups/{groupId}", + query_params={}, + path_params={ + "groupId": group_id, + }, + header_params={}, + body=None, + body_type=None, + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + group_id: PrincipalId, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Group]: + """ + Get the Group with the specified id. + :param group_id: groupId + :type group_id: PrincipalId + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Group] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/groups/{groupId}", + query_params={}, + path_params={ + "groupId": group_id, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Group, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get_batch( + self, + body: Annotated[List[GetGroupsBatchRequestElementDict], Len(min_length=1, max_length=500)], + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[GetGroupsBatchResponse]: + """ + Execute multiple get requests on Group. + + The maximum batch size for this endpoint is 500. + :param body: Body of the request + :type body: Annotated[List[GetGroupsBatchRequestElementDict], Len(min_length=1, max_length=500)] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[GetGroupsBatchResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/admin/groups/getBatch", + query_params={}, + path_params={}, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body=body, + body_type=Annotated[ + List[GetGroupsBatchRequestElementDict], Len(min_length=1, max_length=500) + ], + response_type=GetGroupsBatchResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListGroupsResponse]: + """ + Lists all Groups. + + This is a paged endpoint. Each page may be smaller or larger than the requested page size. However, it is guaranteed that if there are more results available, the `nextPageToken` field will be populated. To get the next page, make the same request again, but set the value of the `pageToken` query parameter to be value of the `nextPageToken` value of the previous response. If there is no `nextPageToken` field in the response, you are on the last page. + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListGroupsResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/groups", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={}, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListGroupsResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListGroupsResponse]: + """ + Lists all Groups. + + This is a paged endpoint. Each page may be smaller or larger than the requested page size. However, it is guaranteed that if there are more results available, the `nextPageToken` field will be populated. To get the next page, make the same request again, but set the value of the `pageToken` query parameter to be value of the `nextPageToken` value of the previous response. If there is no `nextPageToken` field in the response, you are on the last page. + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListGroupsResponse] + """ + + warnings.warn( + "The client.admin.Group.page(...) method has been deprecated. Please use client.admin.Group.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/groups", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={}, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListGroupsResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def search( + self, + *, + where: GroupSearchFilterDict, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[SearchGroupsResponse]: + """ + + :param where: + :type where: GroupSearchFilterDict + :param page_size: + :type page_size: Optional[PageSize] + :param page_token: + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[SearchGroupsResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/admin/groups/search", + query_params={}, + path_params={}, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "where": where, + "pageSize": page_size, + "pageToken": page_token, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "where": GroupSearchFilterDict, + "pageSize": Optional[PageSize], + "pageToken": Optional[PageToken], + }, + ), + response_type=SearchGroupsResponse, + request_timeout=request_timeout, + ), ) diff --git a/foundry/v2/admin/group_member.py b/foundry/v2/admin/group_member.py index 314217c5..8f52992b 100644 --- a/foundry/v2/admin/group_member.py +++ b/foundry/v2/admin/group_member.py @@ -26,10 +26,12 @@ from typing_extensions import TypedDict from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo from foundry._core import ResourceIterator +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.admin.models._group_member import GroupMember @@ -45,7 +47,7 @@ class GroupMemberClient: The API client for the GroupMember Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -56,6 +58,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _GroupMemberClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _GroupMemberClientRaw(auth=auth, hostname=hostname, config=config) @maybe_ignore_preview @pydantic.validate_call @@ -107,7 +113,7 @@ def add( response_type=None, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -202,8 +208,9 @@ def page( """ warnings.warn( - "The GroupMemberClient.page(...) method has been deprecated. Please use GroupMemberClient.list(...) instead.", + "The client.admin.GroupMember.page(...) method has been deprecated. Please use client.admin.GroupMember.list(...) instead.", DeprecationWarning, + stacklevel=2, ) return self._api_client.call_api( @@ -226,7 +233,7 @@ def page( response_type=ListGroupMembersResponse, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -273,4 +280,478 @@ def remove( response_type=None, request_timeout=request_timeout, ), + ).decode() + + +class _GroupMemberClientRaw: + """ + The API client for the GroupMember Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def add( + self, + group_id: PrincipalId, + *, + principal_ids: List[PrincipalId], + expiration: Optional[GroupMembershipExpiration] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[None]: + """ + + :param group_id: groupId + :type group_id: PrincipalId + :param principal_ids: + :type principal_ids: List[PrincipalId] + :param expiration: + :type expiration: Optional[GroupMembershipExpiration] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[None] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/admin/groups/{groupId}/groupMembers/add", + query_params={}, + path_params={ + "groupId": group_id, + }, + header_params={ + "Content-Type": "application/json", + }, + body={ + "principalIds": principal_ids, + "expiration": expiration, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "principalIds": List[PrincipalId], + "expiration": Optional[GroupMembershipExpiration], + }, + ), + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + group_id: PrincipalId, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + transitive: Optional[bool] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListGroupMembersResponse]: + """ + Lists all members (which can be a User or a Group) of a given Group. + + This is a paged endpoint. Each page may be smaller or larger than the requested page size. However, + it is guaranteed that if there are more results available, the `nextPageToken` field will be populated. + To get the next page, make the same request again, but set the value of the `pageToken` query parameter + to be value of the `nextPageToken` value of the previous response. If there is no `nextPageToken` field + in the response, you are on the last page. + + :param group_id: groupId + :type group_id: PrincipalId + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param transitive: transitive + :type transitive: Optional[bool] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListGroupMembersResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/groups/{groupId}/groupMembers", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "transitive": transitive, + }, + path_params={ + "groupId": group_id, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListGroupMembersResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + group_id: PrincipalId, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + transitive: Optional[bool] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListGroupMembersResponse]: + """ + Lists all members (which can be a User or a Group) of a given Group. + + This is a paged endpoint. Each page may be smaller or larger than the requested page size. However, + it is guaranteed that if there are more results available, the `nextPageToken` field will be populated. + To get the next page, make the same request again, but set the value of the `pageToken` query parameter + to be value of the `nextPageToken` value of the previous response. If there is no `nextPageToken` field + in the response, you are on the last page. + + :param group_id: groupId + :type group_id: PrincipalId + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param transitive: transitive + :type transitive: Optional[bool] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListGroupMembersResponse] + """ + + warnings.warn( + "The client.admin.GroupMember.page(...) method has been deprecated. Please use client.admin.GroupMember.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/groups/{groupId}/groupMembers", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "transitive": transitive, + }, + path_params={ + "groupId": group_id, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListGroupMembersResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def remove( + self, + group_id: PrincipalId, + *, + principal_ids: List[PrincipalId], + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[None]: + """ + + :param group_id: groupId + :type group_id: PrincipalId + :param principal_ids: + :type principal_ids: List[PrincipalId] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[None] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/admin/groups/{groupId}/groupMembers/remove", + query_params={}, + path_params={ + "groupId": group_id, + }, + header_params={ + "Content-Type": "application/json", + }, + body={ + "principalIds": principal_ids, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "principalIds": List[PrincipalId], + }, + ), + response_type=None, + request_timeout=request_timeout, + ), + ) + + +class _GroupMemberClientStreaming: + """ + The API client for the GroupMember Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def add( + self, + group_id: PrincipalId, + *, + principal_ids: List[PrincipalId], + expiration: Optional[GroupMembershipExpiration] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[None]: + """ + + :param group_id: groupId + :type group_id: PrincipalId + :param principal_ids: + :type principal_ids: List[PrincipalId] + :param expiration: + :type expiration: Optional[GroupMembershipExpiration] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[None] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/admin/groups/{groupId}/groupMembers/add", + query_params={}, + path_params={ + "groupId": group_id, + }, + header_params={ + "Content-Type": "application/json", + }, + body={ + "principalIds": principal_ids, + "expiration": expiration, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "principalIds": List[PrincipalId], + "expiration": Optional[GroupMembershipExpiration], + }, + ), + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + group_id: PrincipalId, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + transitive: Optional[bool] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListGroupMembersResponse]: + """ + Lists all members (which can be a User or a Group) of a given Group. + + This is a paged endpoint. Each page may be smaller or larger than the requested page size. However, + it is guaranteed that if there are more results available, the `nextPageToken` field will be populated. + To get the next page, make the same request again, but set the value of the `pageToken` query parameter + to be value of the `nextPageToken` value of the previous response. If there is no `nextPageToken` field + in the response, you are on the last page. + + :param group_id: groupId + :type group_id: PrincipalId + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param transitive: transitive + :type transitive: Optional[bool] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListGroupMembersResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/groups/{groupId}/groupMembers", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "transitive": transitive, + }, + path_params={ + "groupId": group_id, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListGroupMembersResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + group_id: PrincipalId, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + transitive: Optional[bool] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListGroupMembersResponse]: + """ + Lists all members (which can be a User or a Group) of a given Group. + + This is a paged endpoint. Each page may be smaller or larger than the requested page size. However, + it is guaranteed that if there are more results available, the `nextPageToken` field will be populated. + To get the next page, make the same request again, but set the value of the `pageToken` query parameter + to be value of the `nextPageToken` value of the previous response. If there is no `nextPageToken` field + in the response, you are on the last page. + + :param group_id: groupId + :type group_id: PrincipalId + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param transitive: transitive + :type transitive: Optional[bool] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListGroupMembersResponse] + """ + + warnings.warn( + "The client.admin.GroupMember.page(...) method has been deprecated. Please use client.admin.GroupMember.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/groups/{groupId}/groupMembers", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "transitive": transitive, + }, + path_params={ + "groupId": group_id, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListGroupMembersResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def remove( + self, + group_id: PrincipalId, + *, + principal_ids: List[PrincipalId], + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[None]: + """ + + :param group_id: groupId + :type group_id: PrincipalId + :param principal_ids: + :type principal_ids: List[PrincipalId] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[None] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/admin/groups/{groupId}/groupMembers/remove", + query_params={}, + path_params={ + "groupId": group_id, + }, + header_params={ + "Content-Type": "application/json", + }, + body={ + "principalIds": principal_ids, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "principalIds": List[PrincipalId], + }, + ), + response_type=None, + request_timeout=request_timeout, + ), ) diff --git a/foundry/v2/admin/group_membership.py b/foundry/v2/admin/group_membership.py index 13101a89..34e9a90c 100644 --- a/foundry/v2/admin/group_membership.py +++ b/foundry/v2/admin/group_membership.py @@ -24,10 +24,12 @@ from typing_extensions import Annotated from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo from foundry._core import ResourceIterator +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.admin.models._group_membership import GroupMembership @@ -44,7 +46,7 @@ class GroupMembershipClient: The API client for the GroupMembership Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -55,6 +57,12 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _GroupMembershipClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _GroupMembershipClientRaw( + auth=auth, hostname=hostname, config=config + ) @maybe_ignore_preview @pydantic.validate_call @@ -149,8 +157,9 @@ def page( """ warnings.warn( - "The GroupMembershipClient.page(...) method has been deprecated. Please use GroupMembershipClient.list(...) instead.", + "The client.admin.GroupMembership.page(...) method has been deprecated. Please use client.admin.GroupMembership.list(...) instead.", DeprecationWarning, + stacklevel=2, ) return self._api_client.call_api( @@ -173,4 +182,280 @@ def page( response_type=ListGroupMembershipsResponse, request_timeout=request_timeout, ), + ).decode() + + +class _GroupMembershipClientRaw: + """ + The API client for the GroupMembership Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + user_id: PrincipalId, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + transitive: Optional[bool] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListGroupMembershipsResponse]: + """ + Lists all Groups a given User is a member of. + + This is a paged endpoint. Each page may be smaller or larger than the requested page size. However, + it is guaranteed that if there are more results available, the `nextPageToken` field will be populated. + To get the next page, make the same request again, but set the value of the `pageToken` query parameter + to be value of the `nextPageToken` value of the previous response. If there is no `nextPageToken` field + in the response, you are on the last page. + + :param user_id: userId + :type user_id: PrincipalId + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param transitive: transitive + :type transitive: Optional[bool] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListGroupMembershipsResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/users/{userId}/groupMemberships", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "transitive": transitive, + }, + path_params={ + "userId": user_id, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListGroupMembershipsResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + user_id: PrincipalId, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + transitive: Optional[bool] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListGroupMembershipsResponse]: + """ + Lists all Groups a given User is a member of. + + This is a paged endpoint. Each page may be smaller or larger than the requested page size. However, + it is guaranteed that if there are more results available, the `nextPageToken` field will be populated. + To get the next page, make the same request again, but set the value of the `pageToken` query parameter + to be value of the `nextPageToken` value of the previous response. If there is no `nextPageToken` field + in the response, you are on the last page. + + :param user_id: userId + :type user_id: PrincipalId + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param transitive: transitive + :type transitive: Optional[bool] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListGroupMembershipsResponse] + """ + + warnings.warn( + "The client.admin.GroupMembership.page(...) method has been deprecated. Please use client.admin.GroupMembership.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/users/{userId}/groupMemberships", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "transitive": transitive, + }, + path_params={ + "userId": user_id, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListGroupMembershipsResponse, + request_timeout=request_timeout, + ), + ) + + +class _GroupMembershipClientStreaming: + """ + The API client for the GroupMembership Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + user_id: PrincipalId, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + transitive: Optional[bool] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListGroupMembershipsResponse]: + """ + Lists all Groups a given User is a member of. + + This is a paged endpoint. Each page may be smaller or larger than the requested page size. However, + it is guaranteed that if there are more results available, the `nextPageToken` field will be populated. + To get the next page, make the same request again, but set the value of the `pageToken` query parameter + to be value of the `nextPageToken` value of the previous response. If there is no `nextPageToken` field + in the response, you are on the last page. + + :param user_id: userId + :type user_id: PrincipalId + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param transitive: transitive + :type transitive: Optional[bool] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListGroupMembershipsResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/users/{userId}/groupMemberships", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "transitive": transitive, + }, + path_params={ + "userId": user_id, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListGroupMembershipsResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + user_id: PrincipalId, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + transitive: Optional[bool] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListGroupMembershipsResponse]: + """ + Lists all Groups a given User is a member of. + + This is a paged endpoint. Each page may be smaller or larger than the requested page size. However, + it is guaranteed that if there are more results available, the `nextPageToken` field will be populated. + To get the next page, make the same request again, but set the value of the `pageToken` query parameter + to be value of the `nextPageToken` value of the previous response. If there is no `nextPageToken` field + in the response, you are on the last page. + + :param user_id: userId + :type user_id: PrincipalId + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param transitive: transitive + :type transitive: Optional[bool] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListGroupMembershipsResponse] + """ + + warnings.warn( + "The client.admin.GroupMembership.page(...) method has been deprecated. Please use client.admin.GroupMembership.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/users/{userId}/groupMemberships", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "transitive": transitive, + }, + path_params={ + "userId": user_id, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListGroupMembershipsResponse, + request_timeout=request_timeout, + ), ) diff --git a/foundry/v2/admin/host.py b/foundry/v2/admin/host.py index 342966bd..7ab8a284 100644 --- a/foundry/v2/admin/host.py +++ b/foundry/v2/admin/host.py @@ -24,10 +24,12 @@ from typing_extensions import Annotated from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo from foundry._core import ResourceIterator +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.admin.models._host import Host @@ -43,7 +45,7 @@ class HostClient: The API client for the Host Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -54,6 +56,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _HostClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _HostClientRaw(auth=auth, hostname=hostname, config=config) @maybe_ignore_preview @pydantic.validate_call @@ -138,8 +144,137 @@ def page( """ warnings.warn( - "The HostClient.page(...) method has been deprecated. Please use HostClient.list(...) instead.", + "The client.admin.Host.page(...) method has been deprecated. Please use client.admin.Host.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/enrollments/{enrollmentRid}/hosts", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "enrollmentRid": enrollment_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListHostsResponse, + request_timeout=request_timeout, + ), + ).decode() + + +class _HostClientRaw: + """ + The API client for the Host Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + enrollment_rid: EnrollmentRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListHostsResponse]: + """ + Lists all Hosts. + + This is a paged endpoint. Each page may be smaller or larger than the requested page size. However, it is guaranteed that if there are more results available, the `nextPageToken` field will be populated. To get the next page, make the same request again, but set the value of the `pageToken` query parameter to be value of the `nextPageToken` value of the previous response. If there is no `nextPageToken` field in the response, you are on the last page. + :param enrollment_rid: enrollmentRid + :type enrollment_rid: EnrollmentRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListHostsResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/enrollments/{enrollmentRid}/hosts", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "enrollmentRid": enrollment_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListHostsResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + enrollment_rid: EnrollmentRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListHostsResponse]: + """ + Lists all Hosts. + + This is a paged endpoint. Each page may be smaller or larger than the requested page size. However, it is guaranteed that if there are more results available, the `nextPageToken` field will be populated. To get the next page, make the same request again, but set the value of the `pageToken` query parameter to be value of the `nextPageToken` value of the previous response. If there is no `nextPageToken` field in the response, you are on the last page. + :param enrollment_rid: enrollmentRid + :type enrollment_rid: EnrollmentRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListHostsResponse] + """ + + warnings.warn( + "The client.admin.Host.page(...) method has been deprecated. Please use client.admin.Host.list(...) instead.", DeprecationWarning, + stacklevel=2, ) return self._api_client.call_api( @@ -163,3 +298,131 @@ def page( request_timeout=request_timeout, ), ) + + +class _HostClientStreaming: + """ + The API client for the Host Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + enrollment_rid: EnrollmentRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListHostsResponse]: + """ + Lists all Hosts. + + This is a paged endpoint. Each page may be smaller or larger than the requested page size. However, it is guaranteed that if there are more results available, the `nextPageToken` field will be populated. To get the next page, make the same request again, but set the value of the `pageToken` query parameter to be value of the `nextPageToken` value of the previous response. If there is no `nextPageToken` field in the response, you are on the last page. + :param enrollment_rid: enrollmentRid + :type enrollment_rid: EnrollmentRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListHostsResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/enrollments/{enrollmentRid}/hosts", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "enrollmentRid": enrollment_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListHostsResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + enrollment_rid: EnrollmentRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListHostsResponse]: + """ + Lists all Hosts. + + This is a paged endpoint. Each page may be smaller or larger than the requested page size. However, it is guaranteed that if there are more results available, the `nextPageToken` field will be populated. To get the next page, make the same request again, but set the value of the `pageToken` query parameter to be value of the `nextPageToken` value of the previous response. If there is no `nextPageToken` field in the response, you are on the last page. + :param enrollment_rid: enrollmentRid + :type enrollment_rid: EnrollmentRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListHostsResponse] + """ + + warnings.warn( + "The client.admin.Host.page(...) method has been deprecated. Please use client.admin.Host.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/enrollments/{enrollmentRid}/hosts", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "enrollmentRid": enrollment_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListHostsResponse, + request_timeout=request_timeout, + ), + ) diff --git a/foundry/v2/admin/marking.py b/foundry/v2/admin/marking.py index a0414bbc..42b1cca2 100644 --- a/foundry/v2/admin/marking.py +++ b/foundry/v2/admin/marking.py @@ -26,10 +26,12 @@ from typing_extensions import Annotated from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo from foundry._core import ResourceIterator +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.admin.marking_member import MarkingMemberClient @@ -51,7 +53,7 @@ class MarkingClient: The API client for the Marking Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -62,6 +64,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _MarkingClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _MarkingClientRaw(auth=auth, hostname=hostname, config=config) self.MarkingMember = MarkingMemberClient(auth=auth, hostname=hostname, config=config) self.MarkingRoleAssignment = MarkingRoleAssignmentClient( auth=auth, hostname=hostname, config=config @@ -107,7 +113,7 @@ def get( response_type=Marking, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -154,7 +160,7 @@ def get_batch( response_type=GetMarkingsBatchResponse, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -227,8 +233,9 @@ def page( """ warnings.warn( - "The MarkingClient.page(...) method has been deprecated. Please use MarkingClient.list(...) instead.", + "The client.admin.Marking.page(...) method has been deprecated. Please use client.admin.Marking.list(...) instead.", DeprecationWarning, + stacklevel=2, ) return self._api_client.call_api( @@ -249,4 +256,410 @@ def page( response_type=ListMarkingsResponse, request_timeout=request_timeout, ), + ).decode() + + +class _MarkingClientRaw: + """ + The API client for the Marking Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + marking_id: MarkingId, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Marking]: + """ + Get the Marking with the specified id. + :param marking_id: markingId + :type marking_id: MarkingId + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Marking] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/markings/{markingId}", + query_params={ + "preview": preview, + }, + path_params={ + "markingId": marking_id, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Marking, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get_batch( + self, + body: Annotated[ + List[GetMarkingsBatchRequestElementDict], Len(min_length=1, max_length=500) + ], + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[GetMarkingsBatchResponse]: + """ + Execute multiple get requests on Marking. + + The maximum batch size for this endpoint is 500. + :param body: Body of the request + :type body: Annotated[List[GetMarkingsBatchRequestElementDict], Len(min_length=1, max_length=500)] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[GetMarkingsBatchResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/admin/markings/getBatch", + query_params={ + "preview": preview, + }, + path_params={}, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body=body, + body_type=Annotated[ + List[GetMarkingsBatchRequestElementDict], Len(min_length=1, max_length=500) + ], + response_type=GetMarkingsBatchResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListMarkingsResponse]: + """ + Maximum page size 100. + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListMarkingsResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/markings", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={}, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListMarkingsResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListMarkingsResponse]: + """ + Maximum page size 100. + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListMarkingsResponse] + """ + + warnings.warn( + "The client.admin.Marking.page(...) method has been deprecated. Please use client.admin.Marking.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/markings", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={}, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListMarkingsResponse, + request_timeout=request_timeout, + ), + ) + + +class _MarkingClientStreaming: + """ + The API client for the Marking Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + marking_id: MarkingId, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Marking]: + """ + Get the Marking with the specified id. + :param marking_id: markingId + :type marking_id: MarkingId + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Marking] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/markings/{markingId}", + query_params={ + "preview": preview, + }, + path_params={ + "markingId": marking_id, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Marking, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get_batch( + self, + body: Annotated[ + List[GetMarkingsBatchRequestElementDict], Len(min_length=1, max_length=500) + ], + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[GetMarkingsBatchResponse]: + """ + Execute multiple get requests on Marking. + + The maximum batch size for this endpoint is 500. + :param body: Body of the request + :type body: Annotated[List[GetMarkingsBatchRequestElementDict], Len(min_length=1, max_length=500)] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[GetMarkingsBatchResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/admin/markings/getBatch", + query_params={ + "preview": preview, + }, + path_params={}, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body=body, + body_type=Annotated[ + List[GetMarkingsBatchRequestElementDict], Len(min_length=1, max_length=500) + ], + response_type=GetMarkingsBatchResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListMarkingsResponse]: + """ + Maximum page size 100. + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListMarkingsResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/markings", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={}, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListMarkingsResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListMarkingsResponse]: + """ + Maximum page size 100. + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListMarkingsResponse] + """ + + warnings.warn( + "The client.admin.Marking.page(...) method has been deprecated. Please use client.admin.Marking.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/markings", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={}, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListMarkingsResponse, + request_timeout=request_timeout, + ), ) diff --git a/foundry/v2/admin/marking_category.py b/foundry/v2/admin/marking_category.py index b535c113..fbdf0c9a 100644 --- a/foundry/v2/admin/marking_category.py +++ b/foundry/v2/admin/marking_category.py @@ -24,10 +24,12 @@ from typing_extensions import Annotated from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo from foundry._core import ResourceIterator +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.admin.models._list_marking_categories_response import ( @@ -45,7 +47,7 @@ class MarkingCategoryClient: The API client for the MarkingCategory Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -56,6 +58,12 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _MarkingCategoryClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _MarkingCategoryClientRaw( + auth=auth, hostname=hostname, config=config + ) @maybe_ignore_preview @pydantic.validate_call @@ -97,7 +105,7 @@ def get( response_type=MarkingCategory, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -170,10 +178,116 @@ def page( """ warnings.warn( - "The MarkingCategoryClient.page(...) method has been deprecated. Please use MarkingCategoryClient.list(...) instead.", + "The client.admin.MarkingCategory.page(...) method has been deprecated. Please use client.admin.MarkingCategory.list(...) instead.", DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/markingCategories", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={}, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListMarkingCategoriesResponse, + request_timeout=request_timeout, + ), + ).decode() + + +class _MarkingCategoryClientRaw: + """ + The API client for the MarkingCategory Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + marking_category_id: MarkingCategoryId, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[MarkingCategory]: + """ + Get the MarkingCategory with the specified id. + :param marking_category_id: markingCategoryId + :type marking_category_id: MarkingCategoryId + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[MarkingCategory] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/markingCategories/{markingCategoryId}", + query_params={ + "preview": preview, + }, + path_params={ + "markingCategoryId": marking_category_id, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=MarkingCategory, + request_timeout=request_timeout, + ), ) + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListMarkingCategoriesResponse]: + """ + Maximum page size 100. + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListMarkingCategoriesResponse] + """ + return self._api_client.call_api( RequestInfo( method="GET", @@ -193,3 +307,210 @@ def page( request_timeout=request_timeout, ), ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListMarkingCategoriesResponse]: + """ + Maximum page size 100. + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListMarkingCategoriesResponse] + """ + + warnings.warn( + "The client.admin.MarkingCategory.page(...) method has been deprecated. Please use client.admin.MarkingCategory.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/markingCategories", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={}, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListMarkingCategoriesResponse, + request_timeout=request_timeout, + ), + ) + + +class _MarkingCategoryClientStreaming: + """ + The API client for the MarkingCategory Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + marking_category_id: MarkingCategoryId, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[MarkingCategory]: + """ + Get the MarkingCategory with the specified id. + :param marking_category_id: markingCategoryId + :type marking_category_id: MarkingCategoryId + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[MarkingCategory] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/markingCategories/{markingCategoryId}", + query_params={ + "preview": preview, + }, + path_params={ + "markingCategoryId": marking_category_id, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=MarkingCategory, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListMarkingCategoriesResponse]: + """ + Maximum page size 100. + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListMarkingCategoriesResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/markingCategories", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={}, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListMarkingCategoriesResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListMarkingCategoriesResponse]: + """ + Maximum page size 100. + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListMarkingCategoriesResponse] + """ + + warnings.warn( + "The client.admin.MarkingCategory.page(...) method has been deprecated. Please use client.admin.MarkingCategory.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/markingCategories", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={}, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListMarkingCategoriesResponse, + request_timeout=request_timeout, + ), + ) diff --git a/foundry/v2/admin/marking_member.py b/foundry/v2/admin/marking_member.py index 1697effe..07eab853 100644 --- a/foundry/v2/admin/marking_member.py +++ b/foundry/v2/admin/marking_member.py @@ -26,10 +26,12 @@ from typing_extensions import TypedDict from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo from foundry._core import ResourceIterator +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.admin.models._list_marking_members_response import ( @@ -48,7 +50,7 @@ class MarkingMemberClient: The API client for the MarkingMember Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -59,6 +61,12 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _MarkingMemberClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _MarkingMemberClientRaw( + auth=auth, hostname=hostname, config=config + ) @maybe_ignore_preview @pydantic.validate_call @@ -110,7 +118,7 @@ def add( response_type=None, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -202,8 +210,9 @@ def page( """ warnings.warn( - "The MarkingMemberClient.page(...) method has been deprecated. Please use MarkingMemberClient.list(...) instead.", + "The client.admin.MarkingMember.page(...) method has been deprecated. Please use client.admin.MarkingMember.list(...) instead.", DeprecationWarning, + stacklevel=2, ) return self._api_client.call_api( @@ -227,7 +236,7 @@ def page( response_type=ListMarkingMembersResponse, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -279,4 +288,484 @@ def remove( response_type=None, request_timeout=request_timeout, ), + ).decode() + + +class _MarkingMemberClientRaw: + """ + The API client for the MarkingMember Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def add( + self, + marking_id: MarkingId, + *, + principal_ids: List[PrincipalId], + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[None]: + """ + + :param marking_id: markingId + :type marking_id: MarkingId + :param principal_ids: + :type principal_ids: List[PrincipalId] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[None] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/admin/markings/{markingId}/markingMembers/add", + query_params={ + "preview": preview, + }, + path_params={ + "markingId": marking_id, + }, + header_params={ + "Content-Type": "application/json", + }, + body={ + "principalIds": principal_ids, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "principalIds": List[PrincipalId], + }, + ), + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + marking_id: MarkingId, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + transitive: Optional[bool] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListMarkingMembersResponse]: + """ + Lists all principals who can view resources protected by the given Marking. Ignores the `pageSize` parameter. + Requires `api:admin-write` because only marking administrators can view marking members. + + :param marking_id: markingId + :type marking_id: MarkingId + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param transitive: transitive + :type transitive: Optional[bool] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListMarkingMembersResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/markings/{markingId}/markingMembers", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + "transitive": transitive, + }, + path_params={ + "markingId": marking_id, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListMarkingMembersResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + marking_id: MarkingId, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + transitive: Optional[bool] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListMarkingMembersResponse]: + """ + Lists all principals who can view resources protected by the given Marking. Ignores the `pageSize` parameter. + Requires `api:admin-write` because only marking administrators can view marking members. + + :param marking_id: markingId + :type marking_id: MarkingId + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param transitive: transitive + :type transitive: Optional[bool] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListMarkingMembersResponse] + """ + + warnings.warn( + "The client.admin.MarkingMember.page(...) method has been deprecated. Please use client.admin.MarkingMember.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/markings/{markingId}/markingMembers", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + "transitive": transitive, + }, + path_params={ + "markingId": marking_id, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListMarkingMembersResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def remove( + self, + marking_id: MarkingId, + *, + principal_ids: List[PrincipalId], + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[None]: + """ + + :param marking_id: markingId + :type marking_id: MarkingId + :param principal_ids: + :type principal_ids: List[PrincipalId] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[None] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/admin/markings/{markingId}/markingMembers/remove", + query_params={ + "preview": preview, + }, + path_params={ + "markingId": marking_id, + }, + header_params={ + "Content-Type": "application/json", + }, + body={ + "principalIds": principal_ids, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "principalIds": List[PrincipalId], + }, + ), + response_type=None, + request_timeout=request_timeout, + ), + ) + + +class _MarkingMemberClientStreaming: + """ + The API client for the MarkingMember Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def add( + self, + marking_id: MarkingId, + *, + principal_ids: List[PrincipalId], + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[None]: + """ + + :param marking_id: markingId + :type marking_id: MarkingId + :param principal_ids: + :type principal_ids: List[PrincipalId] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[None] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/admin/markings/{markingId}/markingMembers/add", + query_params={ + "preview": preview, + }, + path_params={ + "markingId": marking_id, + }, + header_params={ + "Content-Type": "application/json", + }, + body={ + "principalIds": principal_ids, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "principalIds": List[PrincipalId], + }, + ), + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + marking_id: MarkingId, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + transitive: Optional[bool] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListMarkingMembersResponse]: + """ + Lists all principals who can view resources protected by the given Marking. Ignores the `pageSize` parameter. + Requires `api:admin-write` because only marking administrators can view marking members. + + :param marking_id: markingId + :type marking_id: MarkingId + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param transitive: transitive + :type transitive: Optional[bool] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListMarkingMembersResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/markings/{markingId}/markingMembers", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + "transitive": transitive, + }, + path_params={ + "markingId": marking_id, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListMarkingMembersResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + marking_id: MarkingId, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + transitive: Optional[bool] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListMarkingMembersResponse]: + """ + Lists all principals who can view resources protected by the given Marking. Ignores the `pageSize` parameter. + Requires `api:admin-write` because only marking administrators can view marking members. + + :param marking_id: markingId + :type marking_id: MarkingId + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param transitive: transitive + :type transitive: Optional[bool] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListMarkingMembersResponse] + """ + + warnings.warn( + "The client.admin.MarkingMember.page(...) method has been deprecated. Please use client.admin.MarkingMember.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/markings/{markingId}/markingMembers", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + "transitive": transitive, + }, + path_params={ + "markingId": marking_id, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListMarkingMembersResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def remove( + self, + marking_id: MarkingId, + *, + principal_ids: List[PrincipalId], + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[None]: + """ + + :param marking_id: markingId + :type marking_id: MarkingId + :param principal_ids: + :type principal_ids: List[PrincipalId] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[None] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/admin/markings/{markingId}/markingMembers/remove", + query_params={ + "preview": preview, + }, + path_params={ + "markingId": marking_id, + }, + header_params={ + "Content-Type": "application/json", + }, + body={ + "principalIds": principal_ids, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "principalIds": List[PrincipalId], + }, + ), + response_type=None, + request_timeout=request_timeout, + ), ) diff --git a/foundry/v2/admin/marking_role_assignment.py b/foundry/v2/admin/marking_role_assignment.py index fda83cd5..4ff8e8c7 100644 --- a/foundry/v2/admin/marking_role_assignment.py +++ b/foundry/v2/admin/marking_role_assignment.py @@ -26,10 +26,12 @@ from typing_extensions import TypedDict from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo from foundry._core import ResourceIterator +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.admin.models._list_marking_role_assignments_response import ( @@ -48,7 +50,7 @@ class MarkingRoleAssignmentClient: The API client for the MarkingRoleAssignment Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -59,6 +61,12 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _MarkingRoleAssignmentClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _MarkingRoleAssignmentClientRaw( + auth=auth, hostname=hostname, config=config + ) @maybe_ignore_preview @pydantic.validate_call @@ -110,7 +118,7 @@ def add( response_type=None, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -193,8 +201,9 @@ def page( """ warnings.warn( - "The MarkingRoleAssignmentClient.page(...) method has been deprecated. Please use MarkingRoleAssignmentClient.list(...) instead.", + "The client.admin.MarkingRoleAssignment.page(...) method has been deprecated. Please use client.admin.MarkingRoleAssignment.list(...) instead.", DeprecationWarning, + stacklevel=2, ) return self._api_client.call_api( @@ -217,7 +226,7 @@ def page( response_type=ListMarkingRoleAssignmentsResponse, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -269,4 +278,464 @@ def remove( response_type=None, request_timeout=request_timeout, ), + ).decode() + + +class _MarkingRoleAssignmentClientRaw: + """ + The API client for the MarkingRoleAssignment Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def add( + self, + marking_id: MarkingId, + *, + role_assignments: List[MarkingRoleUpdateDict], + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[None]: + """ + + :param marking_id: markingId + :type marking_id: MarkingId + :param role_assignments: + :type role_assignments: List[MarkingRoleUpdateDict] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[None] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/admin/markings/{markingId}/roleAssignments/add", + query_params={ + "preview": preview, + }, + path_params={ + "markingId": marking_id, + }, + header_params={ + "Content-Type": "application/json", + }, + body={ + "roleAssignments": role_assignments, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "roleAssignments": List[MarkingRoleUpdateDict], + }, + ), + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + marking_id: MarkingId, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListMarkingRoleAssignmentsResponse]: + """ + List all principals who are assigned a role for the given Marking. Ignores the `pageSize` parameter. + + :param marking_id: markingId + :type marking_id: MarkingId + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListMarkingRoleAssignmentsResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/markings/{markingId}/roleAssignments", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "markingId": marking_id, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListMarkingRoleAssignmentsResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + marking_id: MarkingId, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListMarkingRoleAssignmentsResponse]: + """ + List all principals who are assigned a role for the given Marking. Ignores the `pageSize` parameter. + + :param marking_id: markingId + :type marking_id: MarkingId + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListMarkingRoleAssignmentsResponse] + """ + + warnings.warn( + "The client.admin.MarkingRoleAssignment.page(...) method has been deprecated. Please use client.admin.MarkingRoleAssignment.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/markings/{markingId}/roleAssignments", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "markingId": marking_id, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListMarkingRoleAssignmentsResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def remove( + self, + marking_id: MarkingId, + *, + role_assignments: List[MarkingRoleUpdateDict], + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[None]: + """ + + :param marking_id: markingId + :type marking_id: MarkingId + :param role_assignments: + :type role_assignments: List[MarkingRoleUpdateDict] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[None] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/admin/markings/{markingId}/roleAssignments/remove", + query_params={ + "preview": preview, + }, + path_params={ + "markingId": marking_id, + }, + header_params={ + "Content-Type": "application/json", + }, + body={ + "roleAssignments": role_assignments, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "roleAssignments": List[MarkingRoleUpdateDict], + }, + ), + response_type=None, + request_timeout=request_timeout, + ), + ) + + +class _MarkingRoleAssignmentClientStreaming: + """ + The API client for the MarkingRoleAssignment Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def add( + self, + marking_id: MarkingId, + *, + role_assignments: List[MarkingRoleUpdateDict], + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[None]: + """ + + :param marking_id: markingId + :type marking_id: MarkingId + :param role_assignments: + :type role_assignments: List[MarkingRoleUpdateDict] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[None] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/admin/markings/{markingId}/roleAssignments/add", + query_params={ + "preview": preview, + }, + path_params={ + "markingId": marking_id, + }, + header_params={ + "Content-Type": "application/json", + }, + body={ + "roleAssignments": role_assignments, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "roleAssignments": List[MarkingRoleUpdateDict], + }, + ), + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + marking_id: MarkingId, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListMarkingRoleAssignmentsResponse]: + """ + List all principals who are assigned a role for the given Marking. Ignores the `pageSize` parameter. + + :param marking_id: markingId + :type marking_id: MarkingId + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListMarkingRoleAssignmentsResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/markings/{markingId}/roleAssignments", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "markingId": marking_id, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListMarkingRoleAssignmentsResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + marking_id: MarkingId, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListMarkingRoleAssignmentsResponse]: + """ + List all principals who are assigned a role for the given Marking. Ignores the `pageSize` parameter. + + :param marking_id: markingId + :type marking_id: MarkingId + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListMarkingRoleAssignmentsResponse] + """ + + warnings.warn( + "The client.admin.MarkingRoleAssignment.page(...) method has been deprecated. Please use client.admin.MarkingRoleAssignment.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/markings/{markingId}/roleAssignments", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "markingId": marking_id, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListMarkingRoleAssignmentsResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def remove( + self, + marking_id: MarkingId, + *, + role_assignments: List[MarkingRoleUpdateDict], + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[None]: + """ + + :param marking_id: markingId + :type marking_id: MarkingId + :param role_assignments: + :type role_assignments: List[MarkingRoleUpdateDict] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[None] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/admin/markings/{markingId}/roleAssignments/remove", + query_params={ + "preview": preview, + }, + path_params={ + "markingId": marking_id, + }, + header_params={ + "Content-Type": "application/json", + }, + body={ + "roleAssignments": role_assignments, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "roleAssignments": List[MarkingRoleUpdateDict], + }, + ), + response_type=None, + request_timeout=request_timeout, + ), ) diff --git a/foundry/v2/admin/user.py b/foundry/v2/admin/user.py index 3dfb7f7f..985a0c80 100644 --- a/foundry/v2/admin/user.py +++ b/foundry/v2/admin/user.py @@ -27,14 +27,17 @@ from annotated_types import Len from typing_extensions import Annotated from typing_extensions import TypedDict +from typing_extensions import deprecated from typing_extensions import overload from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import BinaryStream from foundry._core import Config from foundry._core import RequestInfo from foundry._core import ResourceIterator +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.admin.group_membership import GroupMembershipClient @@ -58,7 +61,7 @@ class UserClient: The API client for the User Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -69,6 +72,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _UserClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _UserClientRaw(auth=auth, hostname=hostname, config=config) self.GroupMembership = GroupMembershipClient(auth=auth, hostname=hostname, config=config) @maybe_ignore_preview @@ -104,7 +111,7 @@ def delete( response_type=None, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -141,7 +148,7 @@ def get( response_type=User, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -181,7 +188,7 @@ def get_batch( response_type=GetUsersBatchResponse, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -213,7 +220,7 @@ def get_current( response_type=User, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -255,7 +262,7 @@ def get_markings( response_type=GetUserMarkingsResponse, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -325,8 +332,9 @@ def page( """ warnings.warn( - "The UserClient.page(...) method has been deprecated. Please use UserClient.list(...) instead.", + "The client.admin.User.page(...) method has been deprecated. Please use client.admin.User.list(...) instead.", DeprecationWarning, + stacklevel=2, ) return self._api_client.call_api( @@ -346,9 +354,12 @@ def page( response_type=ListUsersResponse, request_timeout=request_timeout, ), - ) + ).decode() @overload + @deprecated( + "Using the `stream` parameter is deprecated. Please use the `with_streaming_response` instead." + ) def profile_picture( self, user_id: PrincipalId, @@ -394,6 +405,9 @@ def profile_picture( ... @overload + @deprecated( + "Using the `stream` parameter is deprecated. Please use the `with_streaming_response` instead." + ) def profile_picture( self, user_id: PrincipalId, @@ -442,6 +456,13 @@ def profile_picture( :rtype: Union[bytes, BinaryStream] """ + if stream: + warnings.warn( + f"client.admin.User.profile_picture(..., stream=True, chunk_size={chunk_size}) is deprecated. Please use:\n\nwith client.admin.User.with_streaming_response.profile_picture(...) as response:\n response.iter_bytes(chunk_size={chunk_size})\n", + DeprecationWarning, + stacklevel=2, + ) + return self._api_client.call_api( RequestInfo( method="GET", @@ -460,7 +481,7 @@ def profile_picture( chunk_size=chunk_size, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -513,4 +534,776 @@ def search( response_type=SearchUsersResponse, request_timeout=request_timeout, ), + ).decode() + + +class _UserClientRaw: + """ + The API client for the User Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def delete( + self, + user_id: PrincipalId, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[None]: + """ + Delete the User with the specified id. + :param user_id: userId + :type user_id: PrincipalId + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[None] + """ + + return self._api_client.call_api( + RequestInfo( + method="DELETE", + resource_path="/v2/admin/users/{userId}", + query_params={}, + path_params={ + "userId": user_id, + }, + header_params={}, + body=None, + body_type=None, + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + user_id: PrincipalId, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[User]: + """ + Get the User with the specified id. + :param user_id: userId + :type user_id: PrincipalId + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[User] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/users/{userId}", + query_params={}, + path_params={ + "userId": user_id, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=User, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get_batch( + self, + body: Annotated[List[GetUsersBatchRequestElementDict], Len(min_length=1, max_length=500)], + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[GetUsersBatchResponse]: + """ + Execute multiple get requests on User. + + The maximum batch size for this endpoint is 500. + :param body: Body of the request + :type body: Annotated[List[GetUsersBatchRequestElementDict], Len(min_length=1, max_length=500)] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[GetUsersBatchResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/admin/users/getBatch", + query_params={}, + path_params={}, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body=body, + body_type=Annotated[ + List[GetUsersBatchRequestElementDict], Len(min_length=1, max_length=500) + ], + response_type=GetUsersBatchResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get_current( + self, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[User]: + """ + + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[User] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/users/getCurrent", + query_params={}, + path_params={}, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=User, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get_markings( + self, + user_id: PrincipalId, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[GetUserMarkingsResponse]: + """ + Retrieve Markings that the user is currently a member of. + :param user_id: userId + :type user_id: PrincipalId + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[GetUserMarkingsResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/users/{userId}/getMarkings", + query_params={ + "preview": preview, + }, + path_params={ + "userId": user_id, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=GetUserMarkingsResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListUsersResponse]: + """ + Lists all Users. + + This is a paged endpoint. Each page may be smaller or larger than the requested page size. However, it is guaranteed that if there are more results available, the `nextPageToken` field will be populated. To get the next page, make the same request again, but set the value of the `pageToken` query parameter to be value of the `nextPageToken` value of the previous response. If there is no `nextPageToken` field in the response, you are on the last page. + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListUsersResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/users", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={}, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListUsersResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListUsersResponse]: + """ + Lists all Users. + + This is a paged endpoint. Each page may be smaller or larger than the requested page size. However, it is guaranteed that if there are more results available, the `nextPageToken` field will be populated. To get the next page, make the same request again, but set the value of the `pageToken` query parameter to be value of the `nextPageToken` value of the previous response. If there is no `nextPageToken` field in the response, you are on the last page. + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListUsersResponse] + """ + + warnings.warn( + "The client.admin.User.page(...) method has been deprecated. Please use client.admin.User.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/users", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={}, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListUsersResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def profile_picture( + self, + user_id: PrincipalId, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[bytes]: + """ + + :param user_id: userId + :type user_id: PrincipalId + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[bytes] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/users/{userId}/profilePicture", + query_params={}, + path_params={ + "userId": user_id, + }, + header_params={ + "Accept": "application/octet-stream", + }, + body=None, + body_type=None, + response_type=bytes, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def search( + self, + *, + where: UserSearchFilterDict, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[SearchUsersResponse]: + """ + + :param where: + :type where: UserSearchFilterDict + :param page_size: + :type page_size: Optional[PageSize] + :param page_token: + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[SearchUsersResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/admin/users/search", + query_params={}, + path_params={}, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "where": where, + "pageSize": page_size, + "pageToken": page_token, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "where": UserSearchFilterDict, + "pageSize": Optional[PageSize], + "pageToken": Optional[PageToken], + }, + ), + response_type=SearchUsersResponse, + request_timeout=request_timeout, + ), + ) + + +class _UserClientStreaming: + """ + The API client for the User Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def delete( + self, + user_id: PrincipalId, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[None]: + """ + Delete the User with the specified id. + :param user_id: userId + :type user_id: PrincipalId + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[None] + """ + + return self._api_client.stream_api( + RequestInfo( + method="DELETE", + resource_path="/v2/admin/users/{userId}", + query_params={}, + path_params={ + "userId": user_id, + }, + header_params={}, + body=None, + body_type=None, + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + user_id: PrincipalId, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[User]: + """ + Get the User with the specified id. + :param user_id: userId + :type user_id: PrincipalId + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[User] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/users/{userId}", + query_params={}, + path_params={ + "userId": user_id, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=User, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get_batch( + self, + body: Annotated[List[GetUsersBatchRequestElementDict], Len(min_length=1, max_length=500)], + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[GetUsersBatchResponse]: + """ + Execute multiple get requests on User. + + The maximum batch size for this endpoint is 500. + :param body: Body of the request + :type body: Annotated[List[GetUsersBatchRequestElementDict], Len(min_length=1, max_length=500)] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[GetUsersBatchResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/admin/users/getBatch", + query_params={}, + path_params={}, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body=body, + body_type=Annotated[ + List[GetUsersBatchRequestElementDict], Len(min_length=1, max_length=500) + ], + response_type=GetUsersBatchResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get_current( + self, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[User]: + """ + + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[User] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/users/getCurrent", + query_params={}, + path_params={}, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=User, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get_markings( + self, + user_id: PrincipalId, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[GetUserMarkingsResponse]: + """ + Retrieve Markings that the user is currently a member of. + :param user_id: userId + :type user_id: PrincipalId + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[GetUserMarkingsResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/users/{userId}/getMarkings", + query_params={ + "preview": preview, + }, + path_params={ + "userId": user_id, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=GetUserMarkingsResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListUsersResponse]: + """ + Lists all Users. + + This is a paged endpoint. Each page may be smaller or larger than the requested page size. However, it is guaranteed that if there are more results available, the `nextPageToken` field will be populated. To get the next page, make the same request again, but set the value of the `pageToken` query parameter to be value of the `nextPageToken` value of the previous response. If there is no `nextPageToken` field in the response, you are on the last page. + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListUsersResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/users", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={}, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListUsersResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListUsersResponse]: + """ + Lists all Users. + + This is a paged endpoint. Each page may be smaller or larger than the requested page size. However, it is guaranteed that if there are more results available, the `nextPageToken` field will be populated. To get the next page, make the same request again, but set the value of the `pageToken` query parameter to be value of the `nextPageToken` value of the previous response. If there is no `nextPageToken` field in the response, you are on the last page. + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListUsersResponse] + """ + + warnings.warn( + "The client.admin.User.page(...) method has been deprecated. Please use client.admin.User.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/users", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={}, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListUsersResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def profile_picture( + self, + user_id: PrincipalId, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[bytes]: + """ + + :param user_id: userId + :type user_id: PrincipalId + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[bytes] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/admin/users/{userId}/profilePicture", + query_params={}, + path_params={ + "userId": user_id, + }, + header_params={ + "Accept": "application/octet-stream", + }, + body=None, + body_type=None, + response_type=bytes, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def search( + self, + *, + where: UserSearchFilterDict, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[SearchUsersResponse]: + """ + + :param where: + :type where: UserSearchFilterDict + :param page_size: + :type page_size: Optional[PageSize] + :param page_token: + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[SearchUsersResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/admin/users/search", + query_params={}, + path_params={}, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "where": where, + "pageSize": page_size, + "pageToken": page_token, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "where": UserSearchFilterDict, + "pageSize": Optional[PageSize], + "pageToken": Optional[PageToken], + }, + ), + response_type=SearchUsersResponse, + request_timeout=request_timeout, + ), ) diff --git a/foundry/v2/aip_agents/agent.py b/foundry/v2/aip_agents/agent.py index 1ecd1294..2ba8c271 100644 --- a/foundry/v2/aip_agents/agent.py +++ b/foundry/v2/aip_agents/agent.py @@ -24,10 +24,12 @@ from typing_extensions import Annotated from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo from foundry._core import ResourceIterator +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.aip_agents.agent_version import AgentVersionClient @@ -47,7 +49,7 @@ class AgentClient: The API client for the Agent Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -58,6 +60,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _AgentClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _AgentClientRaw(auth=auth, hostname=hostname, config=config) self.AgentVersion = AgentVersionClient(auth=auth, hostname=hostname, config=config) self.Session = SessionClient(auth=auth, hostname=hostname, config=config) @@ -136,8 +142,9 @@ def all_sessions_page( """ warnings.warn( - "The AgentClient.allSessionsPage(...) method has been deprecated. Please use AgentClient.allSessions(...) instead.", + "The client.aip_agents.Agent.all_sessions_page(...) method has been deprecated. Please use client.aip_agents.Agent.all_sessions(...) instead.", DeprecationWarning, + stacklevel=2, ) return self._api_client.call_api( @@ -158,7 +165,7 @@ def all_sessions_page( response_type=AgentsSessionsPage, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -204,4 +211,332 @@ def get( response_type=Agent, request_timeout=request_timeout, ), + ).decode() + + +class _AgentClientRaw: + """ + The API client for the Agent Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def all_sessions( + self, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[AgentsSessionsPage]: + """ + List all conversation sessions between the calling user and all accessible Agents that were created by this client. + Sessions are returned in order of most recently updated first. + + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[AgentsSessionsPage] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/aipAgents/agents/allSessions", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={}, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=AgentsSessionsPage, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def all_sessions_page( + self, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[AgentsSessionsPage]: + """ + List all conversation sessions between the calling user and all accessible Agents that were created by this client. + Sessions are returned in order of most recently updated first. + + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[AgentsSessionsPage] + """ + + warnings.warn( + "The client.aip_agents.Agent.all_sessions_page(...) method has been deprecated. Please use client.aip_agents.Agent.all_sessions(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/aipAgents/agents/allSessions", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={}, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=AgentsSessionsPage, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + agent_rid: AgentRid, + *, + preview: Optional[PreviewMode] = None, + version: Optional[AgentVersionString] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Agent]: + """ + Get details for an AIP Agent. + :param agent_rid: agentRid + :type agent_rid: AgentRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param version: version + :type version: Optional[AgentVersionString] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Agent] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/aipAgents/agents/{agentRid}", + query_params={ + "preview": preview, + "version": version, + }, + path_params={ + "agentRid": agent_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Agent, + request_timeout=request_timeout, + ), + ) + + +class _AgentClientStreaming: + """ + The API client for the Agent Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def all_sessions( + self, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[AgentsSessionsPage]: + """ + List all conversation sessions between the calling user and all accessible Agents that were created by this client. + Sessions are returned in order of most recently updated first. + + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[AgentsSessionsPage] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/aipAgents/agents/allSessions", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={}, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=AgentsSessionsPage, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def all_sessions_page( + self, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[AgentsSessionsPage]: + """ + List all conversation sessions between the calling user and all accessible Agents that were created by this client. + Sessions are returned in order of most recently updated first. + + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[AgentsSessionsPage] + """ + + warnings.warn( + "The client.aip_agents.Agent.all_sessions_page(...) method has been deprecated. Please use client.aip_agents.Agent.all_sessions(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/aipAgents/agents/allSessions", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={}, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=AgentsSessionsPage, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + agent_rid: AgentRid, + *, + preview: Optional[PreviewMode] = None, + version: Optional[AgentVersionString] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Agent]: + """ + Get details for an AIP Agent. + :param agent_rid: agentRid + :type agent_rid: AgentRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param version: version + :type version: Optional[AgentVersionString] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Agent] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/aipAgents/agents/{agentRid}", + query_params={ + "preview": preview, + "version": version, + }, + path_params={ + "agentRid": agent_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Agent, + request_timeout=request_timeout, + ), ) diff --git a/foundry/v2/aip_agents/agent_version.py b/foundry/v2/aip_agents/agent_version.py index 50df592a..2748322a 100644 --- a/foundry/v2/aip_agents/agent_version.py +++ b/foundry/v2/aip_agents/agent_version.py @@ -24,10 +24,12 @@ from typing_extensions import Annotated from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo from foundry._core import ResourceIterator +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.aip_agents.models._agent_rid import AgentRid @@ -46,7 +48,7 @@ class AgentVersionClient: The API client for the AgentVersion Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -57,6 +59,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _AgentVersionClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _AgentVersionClientRaw(auth=auth, hostname=hostname, config=config) @maybe_ignore_preview @pydantic.validate_call @@ -102,7 +108,7 @@ def get( response_type=AgentVersion, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -187,8 +193,183 @@ def page( """ warnings.warn( - "The AgentVersionClient.page(...) method has been deprecated. Please use AgentVersionClient.list(...) instead.", + "The client.aip_agents.AgentVersion.page(...) method has been deprecated. Please use client.aip_agents.AgentVersion.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/aipAgents/agents/{agentRid}/agentVersions", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "agentRid": agent_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListAgentVersionsResponse, + request_timeout=request_timeout, + ), + ).decode() + + +class _AgentVersionClientRaw: + """ + The API client for the AgentVersion Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + agent_rid: AgentRid, + agent_version_string: AgentVersionString, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[AgentVersion]: + """ + Get version details for an AIP Agent. + :param agent_rid: agentRid + :type agent_rid: AgentRid + :param agent_version_string: agentVersionString + :type agent_version_string: AgentVersionString + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[AgentVersion] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/aipAgents/agents/{agentRid}/agentVersions/{agentVersionString}", + query_params={ + "preview": preview, + }, + path_params={ + "agentRid": agent_rid, + "agentVersionString": agent_version_string, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=AgentVersion, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + agent_rid: AgentRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListAgentVersionsResponse]: + """ + List all versions for an AIP Agent. + Versions are returned in descending order, by most recent versions first. + + :param agent_rid: agentRid + :type agent_rid: AgentRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListAgentVersionsResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/aipAgents/agents/{agentRid}/agentVersions", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "agentRid": agent_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListAgentVersionsResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + agent_rid: AgentRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListAgentVersionsResponse]: + """ + List all versions for an AIP Agent. + Versions are returned in descending order, by most recent versions first. + + :param agent_rid: agentRid + :type agent_rid: AgentRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListAgentVersionsResponse] + """ + + warnings.warn( + "The client.aip_agents.AgentVersion.page(...) method has been deprecated. Please use client.aip_agents.AgentVersion.list(...) instead.", DeprecationWarning, + stacklevel=2, ) return self._api_client.call_api( @@ -212,3 +393,177 @@ def page( request_timeout=request_timeout, ), ) + + +class _AgentVersionClientStreaming: + """ + The API client for the AgentVersion Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + agent_rid: AgentRid, + agent_version_string: AgentVersionString, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[AgentVersion]: + """ + Get version details for an AIP Agent. + :param agent_rid: agentRid + :type agent_rid: AgentRid + :param agent_version_string: agentVersionString + :type agent_version_string: AgentVersionString + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[AgentVersion] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/aipAgents/agents/{agentRid}/agentVersions/{agentVersionString}", + query_params={ + "preview": preview, + }, + path_params={ + "agentRid": agent_rid, + "agentVersionString": agent_version_string, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=AgentVersion, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + agent_rid: AgentRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListAgentVersionsResponse]: + """ + List all versions for an AIP Agent. + Versions are returned in descending order, by most recent versions first. + + :param agent_rid: agentRid + :type agent_rid: AgentRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListAgentVersionsResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/aipAgents/agents/{agentRid}/agentVersions", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "agentRid": agent_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListAgentVersionsResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + agent_rid: AgentRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListAgentVersionsResponse]: + """ + List all versions for an AIP Agent. + Versions are returned in descending order, by most recent versions first. + + :param agent_rid: agentRid + :type agent_rid: AgentRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListAgentVersionsResponse] + """ + + warnings.warn( + "The client.aip_agents.AgentVersion.page(...) method has been deprecated. Please use client.aip_agents.AgentVersion.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/aipAgents/agents/{agentRid}/agentVersions", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "agentRid": agent_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListAgentVersionsResponse, + request_timeout=request_timeout, + ), + ) diff --git a/foundry/v2/aip_agents/client.py b/foundry/v2/aip_agents/client.py index 36df3daa..e22da96e 100644 --- a/foundry/v2/aip_agents/client.py +++ b/foundry/v2/aip_agents/client.py @@ -27,7 +27,7 @@ class AipAgentsClient: The API client for the AipAgents Namespace. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ diff --git a/foundry/v2/aip_agents/content.py b/foundry/v2/aip_agents/content.py index 89be8b6f..d148f23a 100644 --- a/foundry/v2/aip_agents/content.py +++ b/foundry/v2/aip_agents/content.py @@ -23,9 +23,11 @@ from typing_extensions import Annotated from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.aip_agents.models._agent_rid import AgentRid @@ -39,7 +41,7 @@ class ContentClient: The API client for the Content Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -50,6 +52,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _ContentClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _ContentClientRaw(auth=auth, hostname=hostname, config=config) @maybe_ignore_preview @pydantic.validate_call @@ -95,4 +101,132 @@ def get( response_type=Content, request_timeout=request_timeout, ), + ).decode() + + +class _ContentClientRaw: + """ + The API client for the Content Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + agent_rid: AgentRid, + session_rid: SessionRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Content]: + """ + Get the conversation content for a session between the calling user and an Agent. + :param agent_rid: agentRid + :type agent_rid: AgentRid + :param session_rid: sessionRid + :type session_rid: SessionRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Content] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/aipAgents/agents/{agentRid}/sessions/{sessionRid}/content", + query_params={ + "preview": preview, + }, + path_params={ + "agentRid": agent_rid, + "sessionRid": session_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Content, + request_timeout=request_timeout, + ), + ) + + +class _ContentClientStreaming: + """ + The API client for the Content Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + agent_rid: AgentRid, + session_rid: SessionRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Content]: + """ + Get the conversation content for a session between the calling user and an Agent. + :param agent_rid: agentRid + :type agent_rid: AgentRid + :param session_rid: sessionRid + :type session_rid: SessionRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Content] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/aipAgents/agents/{agentRid}/sessions/{sessionRid}/content", + query_params={ + "preview": preview, + }, + path_params={ + "agentRid": agent_rid, + "sessionRid": session_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Content, + request_timeout=request_timeout, + ), ) diff --git a/foundry/v2/aip_agents/session.py b/foundry/v2/aip_agents/session.py index 8e34e37a..0c939661 100644 --- a/foundry/v2/aip_agents/session.py +++ b/foundry/v2/aip_agents/session.py @@ -26,14 +26,17 @@ import pydantic from typing_extensions import Annotated from typing_extensions import TypedDict +from typing_extensions import deprecated from typing_extensions import overload from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import BinaryStream from foundry._core import Config from foundry._core import RequestInfo from foundry._core import ResourceIterator +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.aip_agents.content import ContentClient @@ -63,7 +66,7 @@ class SessionClient: The API client for the Session Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -74,6 +77,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _SessionClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _SessionClientRaw(auth=auth, hostname=hostname, config=config) self.Content = ContentClient(auth=auth, hostname=hostname, config=config) @maybe_ignore_preview @@ -147,7 +154,7 @@ def blocking_continue( response_type=SessionExchangeResult, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -212,7 +219,7 @@ def cancel( response_type=CancelSessionResponse, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -267,7 +274,7 @@ def create( response_type=Session, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -313,7 +320,7 @@ def get( response_type=Session, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -402,8 +409,9 @@ def page( """ warnings.warn( - "The SessionClient.page(...) method has been deprecated. Please use SessionClient.list(...) instead.", + "The client.aip_agents.Session.page(...) method has been deprecated. Please use client.aip_agents.Session.list(...) instead.", DeprecationWarning, + stacklevel=2, ) return self._api_client.call_api( @@ -426,7 +434,7 @@ def page( response_type=ListSessionsResponse, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -490,9 +498,12 @@ def rag_context( response_type=AgentSessionRagContextResponse, request_timeout=request_timeout, ), - ) + ).decode() @overload + @deprecated( + "Using the `stream` parameter is deprecated. Please use the `with_streaming_response` instead." + ) def streaming_continue( self, agent_rid: AgentRid, @@ -588,6 +599,9 @@ def streaming_continue( ... @overload + @deprecated( + "Using the `stream` parameter is deprecated. Please use the `with_streaming_response` instead." + ) def streaming_continue( self, agent_rid: AgentRid, @@ -686,6 +700,13 @@ def streaming_continue( :rtype: Union[bytes, BinaryStream] """ + if stream: + warnings.warn( + f"client.aip_agents.Agent.Session.streaming_continue(..., stream=True, chunk_size={chunk_size}) is deprecated. Please use:\n\nwith client.aip_agents.Agent.Session.with_streaming_response.streaming_continue(...) as response:\n response.iter_bytes(chunk_size={chunk_size})\n", + DeprecationWarning, + stacklevel=2, + ) + return self._api_client.call_api( RequestInfo( method="POST", @@ -721,4 +742,1032 @@ def streaming_continue( chunk_size=chunk_size, request_timeout=request_timeout, ), + ).decode() + + +class _SessionClientRaw: + """ + The API client for the Session Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def blocking_continue( + self, + agent_rid: AgentRid, + session_rid: SessionRid, + *, + parameter_inputs: Dict[ParameterId, ParameterValueDict], + user_input: UserTextInputDict, + contexts_override: Optional[List[InputContextDict]] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[SessionExchangeResult]: + """ + Continue a conversation session with an Agent, or add the first exchange to a session after creation. + Adds a new exchange to the session with the provided inputs, and generates a response from the Agent. + Blocks on returning the result of the added exchange until the response is fully generated. + Streamed responses are also supported; see `streamingContinue` for details. + Concurrent requests to continue the same session are not supported. + Clients should wait to receive a response before sending the next message. + + :param agent_rid: agentRid + :type agent_rid: AgentRid + :param session_rid: sessionRid + :type session_rid: SessionRid + :param parameter_inputs: Any supplied values for [application variables](/docs/foundry/agent-studio/application-state/) to pass to the Agent for the exchange. + :type parameter_inputs: Dict[ParameterId, ParameterValueDict] + :param user_input: The user message for the Agent to respond to. + :type user_input: UserTextInputDict + :param contexts_override: If set, automatic [context retrieval](/docs/foundry/agent-studio/retrieval-context/) is skipped and the list of specified context is provided to the Agent instead. If omitted, relevant context for the user message is automatically retrieved and included in the prompt, based on data sources configured on the Agent for the session. + :type contexts_override: Optional[List[InputContextDict]] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[SessionExchangeResult] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/aipAgents/agents/{agentRid}/sessions/{sessionRid}/blockingContinue", + query_params={ + "preview": preview, + }, + path_params={ + "agentRid": agent_rid, + "sessionRid": session_rid, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "userInput": user_input, + "parameterInputs": parameter_inputs, + "contextsOverride": contexts_override, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "userInput": UserTextInputDict, + "parameterInputs": Dict[ParameterId, ParameterValueDict], + "contextsOverride": Optional[List[InputContextDict]], + }, + ), + response_type=SessionExchangeResult, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def cancel( + self, + agent_rid: AgentRid, + session_rid: SessionRid, + *, + message_id: MessageId, + preview: Optional[PreviewMode] = None, + response: Optional[AgentMarkdownResponse] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[CancelSessionResponse]: + """ + Cancel an in-progress streamed exchange with an Agent which was initiated with `streamingContinue`. + Canceling an exchange allows clients to prevent the exchange from being added to the session, or to provide a response to replace the Agent-generated response. + Note that canceling an exchange does not terminate the stream returned by `streamingContinue`; clients should close the stream on triggering the cancellation request to stop reading from the stream. + + :param agent_rid: agentRid + :type agent_rid: AgentRid + :param session_rid: sessionRid + :type session_rid: SessionRid + :param message_id: The identifier for the in-progress exchange to cancel. This should match the `messageId` which was provided when initiating the exchange with `streamingContinue`. + :type message_id: MessageId + :param preview: preview + :type preview: Optional[PreviewMode] + :param response: When specified, the exchange is added to the session with the client-provided response as the result. When omitted, the exchange is not added to the session. + :type response: Optional[AgentMarkdownResponse] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[CancelSessionResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/aipAgents/agents/{agentRid}/sessions/{sessionRid}/cancel", + query_params={ + "preview": preview, + }, + path_params={ + "agentRid": agent_rid, + "sessionRid": session_rid, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "messageId": message_id, + "response": response, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "messageId": MessageId, + "response": Optional[AgentMarkdownResponse], + }, + ), + response_type=CancelSessionResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def create( + self, + agent_rid: AgentRid, + *, + agent_version: Optional[AgentVersionString] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Session]: + """ + Create a new conversation session between the calling user and an Agent. + Use `blockingContinue` or `streamingContinue` to start adding exchanges to the session. + + :param agent_rid: agentRid + :type agent_rid: AgentRid + :param agent_version: The version of the Agent associated with the session. This can be set by clients on session creation. If not specified, defaults to use the latest published version of the Agent at session creation time. + :type agent_version: Optional[AgentVersionString] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Session] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/aipAgents/agents/{agentRid}/sessions", + query_params={ + "preview": preview, + }, + path_params={ + "agentRid": agent_rid, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "agentVersion": agent_version, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "agentVersion": Optional[AgentVersionString], + }, + ), + response_type=Session, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + agent_rid: AgentRid, + session_rid: SessionRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Session]: + """ + Get the details of a conversation session between the calling user and an Agent. + :param agent_rid: agentRid + :type agent_rid: AgentRid + :param session_rid: sessionRid + :type session_rid: SessionRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Session] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/aipAgents/agents/{agentRid}/sessions/{sessionRid}", + query_params={ + "preview": preview, + }, + path_params={ + "agentRid": agent_rid, + "sessionRid": session_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Session, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + agent_rid: AgentRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListSessionsResponse]: + """ + List all conversation sessions between the calling user and an Agent that was created by this client. + This does not list sessions for the user created by other clients. + For example, any sessions created by the user in AIP Agent Studio will not be listed here. + Sessions are returned in order of most recently updated first. + + :param agent_rid: agentRid + :type agent_rid: AgentRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListSessionsResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/aipAgents/agents/{agentRid}/sessions", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "agentRid": agent_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListSessionsResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + agent_rid: AgentRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListSessionsResponse]: + """ + List all conversation sessions between the calling user and an Agent that was created by this client. + This does not list sessions for the user created by other clients. + For example, any sessions created by the user in AIP Agent Studio will not be listed here. + Sessions are returned in order of most recently updated first. + + :param agent_rid: agentRid + :type agent_rid: AgentRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListSessionsResponse] + """ + + warnings.warn( + "The client.aip_agents.Session.page(...) method has been deprecated. Please use client.aip_agents.Session.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/aipAgents/agents/{agentRid}/sessions", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "agentRid": agent_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListSessionsResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def rag_context( + self, + agent_rid: AgentRid, + session_rid: SessionRid, + *, + parameter_inputs: Dict[ParameterId, ParameterValueDict], + user_input: UserTextInputDict, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[AgentSessionRagContextResponse]: + """ + Retrieve relevant [context](/docs/foundry/agent-studio/core-concepts/#retrieval-context) for a user message from the data sources configured for the session. + This allows clients to pre-retrieve context for a user message before sending it to the Agent with the `contextsOverride` option when continuing a session, to allow any pre-processing of the context before sending it to the Agent. + + :param agent_rid: agentRid + :type agent_rid: AgentRid + :param session_rid: sessionRid + :type session_rid: SessionRid + :param parameter_inputs: Any values for [application variables](/docs/foundry/agent-studio/application-state/) to use for the context retrieval. + :type parameter_inputs: Dict[ParameterId, ParameterValueDict] + :param user_input: The user message to retrieve relevant context for from the configured Agent data sources. + :type user_input: UserTextInputDict + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[AgentSessionRagContextResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="PUT", + resource_path="/v2/aipAgents/agents/{agentRid}/sessions/{sessionRid}/ragContext", + query_params={ + "preview": preview, + }, + path_params={ + "agentRid": agent_rid, + "sessionRid": session_rid, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "userInput": user_input, + "parameterInputs": parameter_inputs, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "userInput": UserTextInputDict, + "parameterInputs": Dict[ParameterId, ParameterValueDict], + }, + ), + response_type=AgentSessionRagContextResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def streaming_continue( + self, + agent_rid: AgentRid, + session_rid: SessionRid, + *, + parameter_inputs: Dict[ParameterId, ParameterValueDict], + user_input: UserTextInputDict, + contexts_override: Optional[List[InputContextDict]] = None, + message_id: Optional[MessageId] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[bytes]: + """ + Continue a conversation session with an Agent, or add the first exchange to a session after creation. + Adds a new exchange to the session with the provided inputs, and generates a response from the Agent. + Returns a stream of the Agent response text (formatted using markdown) for clients to consume as the response is generated. + On completion of the streamed response, clients can load the full details of the exchange that was added to the session by reloading the session content. + Streamed exchanges also support cancellation; see `cancel` for details. + Concurrent requests to continue the same session are not supported. + Clients should wait to receive a response, or cancel the in-progress exchange, before sending the next message. + + :param agent_rid: agentRid + :type agent_rid: AgentRid + :param session_rid: sessionRid + :type session_rid: SessionRid + :param parameter_inputs: Any supplied values for [application variables](/docs/foundry/agent-studio/application-state/) to pass to the Agent for the exchange. + :type parameter_inputs: Dict[ParameterId, ParameterValueDict] + :param user_input: The user message for the Agent to respond to. + :type user_input: UserTextInputDict + :param contexts_override: If set, automatic [context](/docs/foundry/agent-studio/retrieval-context/) retrieval is skipped and the list of specified context is provided to the Agent instead. If omitted, relevant context for the user message is automatically retrieved and included in the prompt, based on data sources configured on the Agent for the session. + :type contexts_override: Optional[List[InputContextDict]] + :param message_id: A client-generated Universally Unique Identifier (UUID) to identify the message, which the client can use to cancel the exchange before the streaming response is complete. + :type message_id: Optional[MessageId] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[bytes] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/aipAgents/agents/{agentRid}/sessions/{sessionRid}/streamingContinue", + query_params={ + "preview": preview, + }, + path_params={ + "agentRid": agent_rid, + "sessionRid": session_rid, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/octet-stream", + }, + body={ + "userInput": user_input, + "parameterInputs": parameter_inputs, + "contextsOverride": contexts_override, + "messageId": message_id, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "userInput": UserTextInputDict, + "parameterInputs": Dict[ParameterId, ParameterValueDict], + "contextsOverride": Optional[List[InputContextDict]], + "messageId": Optional[MessageId], + }, + ), + response_type=bytes, + request_timeout=request_timeout, + ), + ) + + +class _SessionClientStreaming: + """ + The API client for the Session Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def blocking_continue( + self, + agent_rid: AgentRid, + session_rid: SessionRid, + *, + parameter_inputs: Dict[ParameterId, ParameterValueDict], + user_input: UserTextInputDict, + contexts_override: Optional[List[InputContextDict]] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[SessionExchangeResult]: + """ + Continue a conversation session with an Agent, or add the first exchange to a session after creation. + Adds a new exchange to the session with the provided inputs, and generates a response from the Agent. + Blocks on returning the result of the added exchange until the response is fully generated. + Streamed responses are also supported; see `streamingContinue` for details. + Concurrent requests to continue the same session are not supported. + Clients should wait to receive a response before sending the next message. + + :param agent_rid: agentRid + :type agent_rid: AgentRid + :param session_rid: sessionRid + :type session_rid: SessionRid + :param parameter_inputs: Any supplied values for [application variables](/docs/foundry/agent-studio/application-state/) to pass to the Agent for the exchange. + :type parameter_inputs: Dict[ParameterId, ParameterValueDict] + :param user_input: The user message for the Agent to respond to. + :type user_input: UserTextInputDict + :param contexts_override: If set, automatic [context retrieval](/docs/foundry/agent-studio/retrieval-context/) is skipped and the list of specified context is provided to the Agent instead. If omitted, relevant context for the user message is automatically retrieved and included in the prompt, based on data sources configured on the Agent for the session. + :type contexts_override: Optional[List[InputContextDict]] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[SessionExchangeResult] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/aipAgents/agents/{agentRid}/sessions/{sessionRid}/blockingContinue", + query_params={ + "preview": preview, + }, + path_params={ + "agentRid": agent_rid, + "sessionRid": session_rid, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "userInput": user_input, + "parameterInputs": parameter_inputs, + "contextsOverride": contexts_override, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "userInput": UserTextInputDict, + "parameterInputs": Dict[ParameterId, ParameterValueDict], + "contextsOverride": Optional[List[InputContextDict]], + }, + ), + response_type=SessionExchangeResult, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def cancel( + self, + agent_rid: AgentRid, + session_rid: SessionRid, + *, + message_id: MessageId, + preview: Optional[PreviewMode] = None, + response: Optional[AgentMarkdownResponse] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[CancelSessionResponse]: + """ + Cancel an in-progress streamed exchange with an Agent which was initiated with `streamingContinue`. + Canceling an exchange allows clients to prevent the exchange from being added to the session, or to provide a response to replace the Agent-generated response. + Note that canceling an exchange does not terminate the stream returned by `streamingContinue`; clients should close the stream on triggering the cancellation request to stop reading from the stream. + + :param agent_rid: agentRid + :type agent_rid: AgentRid + :param session_rid: sessionRid + :type session_rid: SessionRid + :param message_id: The identifier for the in-progress exchange to cancel. This should match the `messageId` which was provided when initiating the exchange with `streamingContinue`. + :type message_id: MessageId + :param preview: preview + :type preview: Optional[PreviewMode] + :param response: When specified, the exchange is added to the session with the client-provided response as the result. When omitted, the exchange is not added to the session. + :type response: Optional[AgentMarkdownResponse] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[CancelSessionResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/aipAgents/agents/{agentRid}/sessions/{sessionRid}/cancel", + query_params={ + "preview": preview, + }, + path_params={ + "agentRid": agent_rid, + "sessionRid": session_rid, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "messageId": message_id, + "response": response, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "messageId": MessageId, + "response": Optional[AgentMarkdownResponse], + }, + ), + response_type=CancelSessionResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def create( + self, + agent_rid: AgentRid, + *, + agent_version: Optional[AgentVersionString] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Session]: + """ + Create a new conversation session between the calling user and an Agent. + Use `blockingContinue` or `streamingContinue` to start adding exchanges to the session. + + :param agent_rid: agentRid + :type agent_rid: AgentRid + :param agent_version: The version of the Agent associated with the session. This can be set by clients on session creation. If not specified, defaults to use the latest published version of the Agent at session creation time. + :type agent_version: Optional[AgentVersionString] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Session] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/aipAgents/agents/{agentRid}/sessions", + query_params={ + "preview": preview, + }, + path_params={ + "agentRid": agent_rid, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "agentVersion": agent_version, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "agentVersion": Optional[AgentVersionString], + }, + ), + response_type=Session, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + agent_rid: AgentRid, + session_rid: SessionRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Session]: + """ + Get the details of a conversation session between the calling user and an Agent. + :param agent_rid: agentRid + :type agent_rid: AgentRid + :param session_rid: sessionRid + :type session_rid: SessionRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Session] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/aipAgents/agents/{agentRid}/sessions/{sessionRid}", + query_params={ + "preview": preview, + }, + path_params={ + "agentRid": agent_rid, + "sessionRid": session_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Session, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + agent_rid: AgentRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListSessionsResponse]: + """ + List all conversation sessions between the calling user and an Agent that was created by this client. + This does not list sessions for the user created by other clients. + For example, any sessions created by the user in AIP Agent Studio will not be listed here. + Sessions are returned in order of most recently updated first. + + :param agent_rid: agentRid + :type agent_rid: AgentRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListSessionsResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/aipAgents/agents/{agentRid}/sessions", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "agentRid": agent_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListSessionsResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + agent_rid: AgentRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListSessionsResponse]: + """ + List all conversation sessions between the calling user and an Agent that was created by this client. + This does not list sessions for the user created by other clients. + For example, any sessions created by the user in AIP Agent Studio will not be listed here. + Sessions are returned in order of most recently updated first. + + :param agent_rid: agentRid + :type agent_rid: AgentRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListSessionsResponse] + """ + + warnings.warn( + "The client.aip_agents.Session.page(...) method has been deprecated. Please use client.aip_agents.Session.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/aipAgents/agents/{agentRid}/sessions", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "agentRid": agent_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListSessionsResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def rag_context( + self, + agent_rid: AgentRid, + session_rid: SessionRid, + *, + parameter_inputs: Dict[ParameterId, ParameterValueDict], + user_input: UserTextInputDict, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[AgentSessionRagContextResponse]: + """ + Retrieve relevant [context](/docs/foundry/agent-studio/core-concepts/#retrieval-context) for a user message from the data sources configured for the session. + This allows clients to pre-retrieve context for a user message before sending it to the Agent with the `contextsOverride` option when continuing a session, to allow any pre-processing of the context before sending it to the Agent. + + :param agent_rid: agentRid + :type agent_rid: AgentRid + :param session_rid: sessionRid + :type session_rid: SessionRid + :param parameter_inputs: Any values for [application variables](/docs/foundry/agent-studio/application-state/) to use for the context retrieval. + :type parameter_inputs: Dict[ParameterId, ParameterValueDict] + :param user_input: The user message to retrieve relevant context for from the configured Agent data sources. + :type user_input: UserTextInputDict + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[AgentSessionRagContextResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="PUT", + resource_path="/v2/aipAgents/agents/{agentRid}/sessions/{sessionRid}/ragContext", + query_params={ + "preview": preview, + }, + path_params={ + "agentRid": agent_rid, + "sessionRid": session_rid, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "userInput": user_input, + "parameterInputs": parameter_inputs, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "userInput": UserTextInputDict, + "parameterInputs": Dict[ParameterId, ParameterValueDict], + }, + ), + response_type=AgentSessionRagContextResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def streaming_continue( + self, + agent_rid: AgentRid, + session_rid: SessionRid, + *, + parameter_inputs: Dict[ParameterId, ParameterValueDict], + user_input: UserTextInputDict, + contexts_override: Optional[List[InputContextDict]] = None, + message_id: Optional[MessageId] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[bytes]: + """ + Continue a conversation session with an Agent, or add the first exchange to a session after creation. + Adds a new exchange to the session with the provided inputs, and generates a response from the Agent. + Returns a stream of the Agent response text (formatted using markdown) for clients to consume as the response is generated. + On completion of the streamed response, clients can load the full details of the exchange that was added to the session by reloading the session content. + Streamed exchanges also support cancellation; see `cancel` for details. + Concurrent requests to continue the same session are not supported. + Clients should wait to receive a response, or cancel the in-progress exchange, before sending the next message. + + :param agent_rid: agentRid + :type agent_rid: AgentRid + :param session_rid: sessionRid + :type session_rid: SessionRid + :param parameter_inputs: Any supplied values for [application variables](/docs/foundry/agent-studio/application-state/) to pass to the Agent for the exchange. + :type parameter_inputs: Dict[ParameterId, ParameterValueDict] + :param user_input: The user message for the Agent to respond to. + :type user_input: UserTextInputDict + :param contexts_override: If set, automatic [context](/docs/foundry/agent-studio/retrieval-context/) retrieval is skipped and the list of specified context is provided to the Agent instead. If omitted, relevant context for the user message is automatically retrieved and included in the prompt, based on data sources configured on the Agent for the session. + :type contexts_override: Optional[List[InputContextDict]] + :param message_id: A client-generated Universally Unique Identifier (UUID) to identify the message, which the client can use to cancel the exchange before the streaming response is complete. + :type message_id: Optional[MessageId] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[bytes] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/aipAgents/agents/{agentRid}/sessions/{sessionRid}/streamingContinue", + query_params={ + "preview": preview, + }, + path_params={ + "agentRid": agent_rid, + "sessionRid": session_rid, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/octet-stream", + }, + body={ + "userInput": user_input, + "parameterInputs": parameter_inputs, + "contextsOverride": contexts_override, + "messageId": message_id, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "userInput": UserTextInputDict, + "parameterInputs": Dict[ParameterId, ParameterValueDict], + "contextsOverride": Optional[List[InputContextDict]], + "messageId": Optional[MessageId], + }, + ), + response_type=bytes, + request_timeout=request_timeout, + ), ) diff --git a/foundry/v2/client.py b/foundry/v2/client.py index 2bfd65a7..fd6041c2 100644 --- a/foundry/v2/client.py +++ b/foundry/v2/client.py @@ -24,7 +24,7 @@ class FoundryClient: The Foundry V2 API client. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ diff --git a/foundry/v2/connectivity/client.py b/foundry/v2/connectivity/client.py index 6d839168..643f7e27 100644 --- a/foundry/v2/connectivity/client.py +++ b/foundry/v2/connectivity/client.py @@ -27,7 +27,7 @@ class ConnectivityClient: The API client for the Connectivity Namespace. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ diff --git a/foundry/v2/connectivity/connection.py b/foundry/v2/connectivity/connection.py index 4a7154f2..162d818f 100644 --- a/foundry/v2/connectivity/connection.py +++ b/foundry/v2/connectivity/connection.py @@ -24,9 +24,11 @@ from typing_extensions import TypedDict from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.connectivity.file_import import FileImportClient @@ -51,7 +53,7 @@ class ConnectionClient: The API client for the Connection Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -62,6 +64,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _ConnectionClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _ConnectionClientRaw(auth=auth, hostname=hostname, config=config) self.FileImport = FileImportClient(auth=auth, hostname=hostname, config=config) self.TableImport = TableImportClient(auth=auth, hostname=hostname, config=config) @@ -134,7 +140,7 @@ def create( response_type=Connection, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -176,7 +182,7 @@ def get( response_type=Connection, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -239,4 +245,392 @@ def update_secrets( response_type=None, request_timeout=request_timeout, ), + ).decode() + + +class _ConnectionClientRaw: + """ + The API client for the Connection Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def create( + self, + *, + configuration: CreateConnectionRequestConnectionConfigurationDict, + display_name: ConnectionDisplayName, + parent_folder_rid: FolderRid, + runtime_platform: CreateConnectionRequestRuntimePlatformDict, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Connection]: + """ + Creates a new Connection. + Any secrets specified in the request body are transmitted over the network encrypted using TLS. Once the + secrets reach Foundry's servers, they will be temporarily decrypted and remain in plaintext in memory to + be processed as needed. They will stay in plaintext in memory until the garbage collection process cleans + up the memory. The secrets are always stored encrypted on our servers. + By using this endpoint, you acknowledge and accept any potential risks associated with the temporary + in-memory handling of secrets. If you do not want your secrets to be temporarily decrypted, you should + use the Foundry UI instead. + + :param configuration: + :type configuration: CreateConnectionRequestConnectionConfigurationDict + :param display_name: The display name of the Connection. The display name must not be blank. + :type display_name: ConnectionDisplayName + :param parent_folder_rid: + :type parent_folder_rid: FolderRid + :param runtime_platform: + :type runtime_platform: CreateConnectionRequestRuntimePlatformDict + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Connection] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/connectivity/connections", + query_params={ + "preview": preview, + }, + path_params={}, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "parentFolderRid": parent_folder_rid, + "runtimePlatform": runtime_platform, + "configuration": configuration, + "displayName": display_name, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "parentFolderRid": FolderRid, + "runtimePlatform": CreateConnectionRequestRuntimePlatformDict, + "configuration": CreateConnectionRequestConnectionConfigurationDict, + "displayName": ConnectionDisplayName, + }, + ), + response_type=Connection, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + connection_rid: ConnectionRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Connection]: + """ + Get the Connection with the specified rid. + :param connection_rid: connectionRid + :type connection_rid: ConnectionRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Connection] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/connectivity/connections/{connectionRid}", + query_params={ + "preview": preview, + }, + path_params={ + "connectionRid": connection_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Connection, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def update_secrets( + self, + connection_rid: ConnectionRid, + *, + secrets: Dict[SecretName, PlaintextValue], + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[None]: + """ + Updates the secrets on the connection to the specified secret values. + Secrets that are currently configured on the connection but are omitted in the request will remain unchanged. + + Secrets are transmitted over the network encrypted using TLS. Once the secrets reach Foundry's servers, + they will be temporarily decrypted and remain in plaintext in memory to be processed as needed. + They will stay in plaintext in memory until the garbage collection process cleans up the memory. + The secrets are always stored encrypted on our servers. + + By using this endpoint, you acknowledge and accept any potential risks associated with the temporary + in-memory handling of secrets. If you do not want your secrets to be temporarily decrypted, you should + use the Foundry UI instead. + + :param connection_rid: connectionRid + :type connection_rid: ConnectionRid + :param secrets: The secrets to be updated. The specified secret names must already be configured on the connection. + :type secrets: Dict[SecretName, PlaintextValue] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[None] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/connectivity/connections/{connectionRid}/updateSecrets", + query_params={ + "preview": preview, + }, + path_params={ + "connectionRid": connection_rid, + }, + header_params={ + "Content-Type": "application/json", + }, + body={ + "secrets": secrets, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "secrets": Dict[SecretName, PlaintextValue], + }, + ), + response_type=None, + request_timeout=request_timeout, + ), + ) + + +class _ConnectionClientStreaming: + """ + The API client for the Connection Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def create( + self, + *, + configuration: CreateConnectionRequestConnectionConfigurationDict, + display_name: ConnectionDisplayName, + parent_folder_rid: FolderRid, + runtime_platform: CreateConnectionRequestRuntimePlatformDict, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Connection]: + """ + Creates a new Connection. + Any secrets specified in the request body are transmitted over the network encrypted using TLS. Once the + secrets reach Foundry's servers, they will be temporarily decrypted and remain in plaintext in memory to + be processed as needed. They will stay in plaintext in memory until the garbage collection process cleans + up the memory. The secrets are always stored encrypted on our servers. + By using this endpoint, you acknowledge and accept any potential risks associated with the temporary + in-memory handling of secrets. If you do not want your secrets to be temporarily decrypted, you should + use the Foundry UI instead. + + :param configuration: + :type configuration: CreateConnectionRequestConnectionConfigurationDict + :param display_name: The display name of the Connection. The display name must not be blank. + :type display_name: ConnectionDisplayName + :param parent_folder_rid: + :type parent_folder_rid: FolderRid + :param runtime_platform: + :type runtime_platform: CreateConnectionRequestRuntimePlatformDict + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Connection] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/connectivity/connections", + query_params={ + "preview": preview, + }, + path_params={}, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "parentFolderRid": parent_folder_rid, + "runtimePlatform": runtime_platform, + "configuration": configuration, + "displayName": display_name, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "parentFolderRid": FolderRid, + "runtimePlatform": CreateConnectionRequestRuntimePlatformDict, + "configuration": CreateConnectionRequestConnectionConfigurationDict, + "displayName": ConnectionDisplayName, + }, + ), + response_type=Connection, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + connection_rid: ConnectionRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Connection]: + """ + Get the Connection with the specified rid. + :param connection_rid: connectionRid + :type connection_rid: ConnectionRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Connection] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/connectivity/connections/{connectionRid}", + query_params={ + "preview": preview, + }, + path_params={ + "connectionRid": connection_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Connection, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def update_secrets( + self, + connection_rid: ConnectionRid, + *, + secrets: Dict[SecretName, PlaintextValue], + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[None]: + """ + Updates the secrets on the connection to the specified secret values. + Secrets that are currently configured on the connection but are omitted in the request will remain unchanged. + + Secrets are transmitted over the network encrypted using TLS. Once the secrets reach Foundry's servers, + they will be temporarily decrypted and remain in plaintext in memory to be processed as needed. + They will stay in plaintext in memory until the garbage collection process cleans up the memory. + The secrets are always stored encrypted on our servers. + + By using this endpoint, you acknowledge and accept any potential risks associated with the temporary + in-memory handling of secrets. If you do not want your secrets to be temporarily decrypted, you should + use the Foundry UI instead. + + :param connection_rid: connectionRid + :type connection_rid: ConnectionRid + :param secrets: The secrets to be updated. The specified secret names must already be configured on the connection. + :type secrets: Dict[SecretName, PlaintextValue] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[None] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/connectivity/connections/{connectionRid}/updateSecrets", + query_params={ + "preview": preview, + }, + path_params={ + "connectionRid": connection_rid, + }, + header_params={ + "Content-Type": "application/json", + }, + body={ + "secrets": secrets, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "secrets": Dict[SecretName, PlaintextValue], + }, + ), + response_type=None, + request_timeout=request_timeout, + ), ) diff --git a/foundry/v2/connectivity/file_import.py b/foundry/v2/connectivity/file_import.py index 271f5405..fc4abc6a 100644 --- a/foundry/v2/connectivity/file_import.py +++ b/foundry/v2/connectivity/file_import.py @@ -26,10 +26,12 @@ from typing_extensions import TypedDict from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo from foundry._core import ResourceIterator +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.connectivity.models._connection_rid import ConnectionRid @@ -54,7 +56,7 @@ class FileImportClient: The API client for the FileImport Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -65,6 +67,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _FileImportClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _FileImportClientRaw(auth=auth, hostname=hostname, config=config) @maybe_ignore_preview @pydantic.validate_call @@ -142,7 +148,7 @@ def create( response_type=FileImport, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -189,7 +195,7 @@ def delete( response_type=None, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -237,7 +243,7 @@ def execute( response_type=BuildRid, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -283,7 +289,7 @@ def get( response_type=FileImport, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -368,8 +374,9 @@ def page( """ warnings.warn( - "The FileImportClient.page(...) method has been deprecated. Please use FileImportClient.list(...) instead.", + "The client.connectivity.FileImport.page(...) method has been deprecated. Please use client.connectivity.FileImport.list(...) instead.", DeprecationWarning, + stacklevel=2, ) return self._api_client.call_api( @@ -392,7 +399,7 @@ def page( response_type=ListFileImportsResponse, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -474,4 +481,862 @@ def replace( response_type=FileImport, request_timeout=request_timeout, ), + ).decode() + + +class _FileImportClientRaw: + """ + The API client for the FileImport Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def create( + self, + connection_rid: ConnectionRid, + *, + dataset_rid: DatasetRid, + display_name: FileImportDisplayName, + file_import_filters: List[FileImportFilterDict], + import_mode: FileImportMode, + branch_name: Optional[BranchName] = None, + preview: Optional[PreviewMode] = None, + subfolder: Optional[str] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[FileImport]: + """ + Creates a new FileImport. + :param connection_rid: connectionRid + :type connection_rid: ConnectionRid + :param dataset_rid: The RID of the output dataset. + :type dataset_rid: DatasetRid + :param display_name: + :type display_name: FileImportDisplayName + :param file_import_filters: Use filters to limit which files should be imported. Filters are applied in the order they are defined. A different ordering of filters may lead to a more optimized import. [Learn more about optimizing file imports.](/docs/foundry/data-connection/file-based-syncs/#optimize-file-based-syncs) + :type file_import_filters: List[FileImportFilterDict] + :param import_mode: + :type import_mode: FileImportMode + :param branch_name: The branch name in the output dataset that will contain the imported data. Defaults to `master` for most enrollments. + :type branch_name: Optional[BranchName] + :param preview: preview + :type preview: Optional[PreviewMode] + :param subfolder: A subfolder in the external system that will be imported. If not specified, defaults to the root folder of the external system. + :type subfolder: Optional[str] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[FileImport] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/connectivity/connections/{connectionRid}/fileImports", + query_params={ + "preview": preview, + }, + path_params={ + "connectionRid": connection_rid, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "datasetRid": dataset_rid, + "importMode": import_mode, + "displayName": display_name, + "branchName": branch_name, + "subfolder": subfolder, + "fileImportFilters": file_import_filters, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "datasetRid": DatasetRid, + "importMode": FileImportMode, + "displayName": FileImportDisplayName, + "branchName": Optional[BranchName], + "subfolder": Optional[str], + "fileImportFilters": List[FileImportFilterDict], + }, + ), + response_type=FileImport, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def delete( + self, + connection_rid: ConnectionRid, + file_import_rid: FileImportRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[None]: + """ + Delete the FileImport with the specified RID. + Deleting the file import does not delete the destination dataset but the dataset will no longer + be updated by this import. + + :param connection_rid: connectionRid + :type connection_rid: ConnectionRid + :param file_import_rid: fileImportRid + :type file_import_rid: FileImportRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[None] + """ + + return self._api_client.call_api( + RequestInfo( + method="DELETE", + resource_path="/v2/connectivity/connections/{connectionRid}/fileImports/{fileImportRid}", + query_params={ + "preview": preview, + }, + path_params={ + "connectionRid": connection_rid, + "fileImportRid": file_import_rid, + }, + header_params={}, + body=None, + body_type=None, + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def execute( + self, + connection_rid: ConnectionRid, + file_import_rid: FileImportRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[BuildRid]: + """ + Executes the FileImport, which runs asynchronously as a [Foundry Build](/docs/foundry/data-integration/builds/). + The returned BuildRid can be used to check the status via the Orchestration API. + + :param connection_rid: connectionRid + :type connection_rid: ConnectionRid + :param file_import_rid: fileImportRid + :type file_import_rid: FileImportRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[BuildRid] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/connectivity/connections/{connectionRid}/fileImports/{fileImportRid}/execute", + query_params={ + "preview": preview, + }, + path_params={ + "connectionRid": connection_rid, + "fileImportRid": file_import_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=BuildRid, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + connection_rid: ConnectionRid, + file_import_rid: FileImportRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[FileImport]: + """ + Get the FileImport with the specified rid. + :param connection_rid: connectionRid + :type connection_rid: ConnectionRid + :param file_import_rid: fileImportRid + :type file_import_rid: FileImportRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[FileImport] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/connectivity/connections/{connectionRid}/fileImports/{fileImportRid}", + query_params={ + "preview": preview, + }, + path_params={ + "connectionRid": connection_rid, + "fileImportRid": file_import_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=FileImport, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + connection_rid: ConnectionRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListFileImportsResponse]: + """ + Lists all file imports defined for this connection. + Only file imports that the user has permissions to view will be returned. + + :param connection_rid: connectionRid + :type connection_rid: ConnectionRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListFileImportsResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/connectivity/connections/{connectionRid}/fileImports", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "connectionRid": connection_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListFileImportsResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + connection_rid: ConnectionRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListFileImportsResponse]: + """ + Lists all file imports defined for this connection. + Only file imports that the user has permissions to view will be returned. + + :param connection_rid: connectionRid + :type connection_rid: ConnectionRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListFileImportsResponse] + """ + + warnings.warn( + "The client.connectivity.FileImport.page(...) method has been deprecated. Please use client.connectivity.FileImport.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/connectivity/connections/{connectionRid}/fileImports", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "connectionRid": connection_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListFileImportsResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def replace( + self, + connection_rid: ConnectionRid, + file_import_rid: FileImportRid, + *, + dataset_rid: DatasetRid, + display_name: FileImportDisplayName, + file_import_filters: List[FileImportFilterDict], + import_mode: FileImportMode, + branch_name: Optional[BranchName] = None, + preview: Optional[PreviewMode] = None, + subfolder: Optional[str] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[FileImport]: + """ + Replace the FileImport with the specified rid. + :param connection_rid: connectionRid + :type connection_rid: ConnectionRid + :param file_import_rid: fileImportRid + :type file_import_rid: FileImportRid + :param dataset_rid: The RID of the output dataset. + :type dataset_rid: DatasetRid + :param display_name: + :type display_name: FileImportDisplayName + :param file_import_filters: Use filters to limit which files should be imported. Filters are applied in the order they are defined. A different ordering of filters may lead to a more optimized import. [Learn more about optimizing file imports.](/docs/foundry/data-connection/file-based-syncs/#optimize-file-based-syncs) + :type file_import_filters: List[FileImportFilterDict] + :param import_mode: + :type import_mode: FileImportMode + :param branch_name: The branch name in the output dataset that will contain the imported data. Defaults to `master` for most enrollments. + :type branch_name: Optional[BranchName] + :param preview: preview + :type preview: Optional[PreviewMode] + :param subfolder: A subfolder in the external system that will be imported. If not specified, defaults to the root folder of the external system. + :type subfolder: Optional[str] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[FileImport] + """ + + return self._api_client.call_api( + RequestInfo( + method="PUT", + resource_path="/v2/connectivity/connections/{connectionRid}/fileImports/{fileImportRid}", + query_params={ + "preview": preview, + }, + path_params={ + "connectionRid": connection_rid, + "fileImportRid": file_import_rid, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "datasetRid": dataset_rid, + "importMode": import_mode, + "displayName": display_name, + "branchName": branch_name, + "subfolder": subfolder, + "fileImportFilters": file_import_filters, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "datasetRid": DatasetRid, + "importMode": FileImportMode, + "displayName": FileImportDisplayName, + "branchName": Optional[BranchName], + "subfolder": Optional[str], + "fileImportFilters": List[FileImportFilterDict], + }, + ), + response_type=FileImport, + request_timeout=request_timeout, + ), + ) + + +class _FileImportClientStreaming: + """ + The API client for the FileImport Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def create( + self, + connection_rid: ConnectionRid, + *, + dataset_rid: DatasetRid, + display_name: FileImportDisplayName, + file_import_filters: List[FileImportFilterDict], + import_mode: FileImportMode, + branch_name: Optional[BranchName] = None, + preview: Optional[PreviewMode] = None, + subfolder: Optional[str] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[FileImport]: + """ + Creates a new FileImport. + :param connection_rid: connectionRid + :type connection_rid: ConnectionRid + :param dataset_rid: The RID of the output dataset. + :type dataset_rid: DatasetRid + :param display_name: + :type display_name: FileImportDisplayName + :param file_import_filters: Use filters to limit which files should be imported. Filters are applied in the order they are defined. A different ordering of filters may lead to a more optimized import. [Learn more about optimizing file imports.](/docs/foundry/data-connection/file-based-syncs/#optimize-file-based-syncs) + :type file_import_filters: List[FileImportFilterDict] + :param import_mode: + :type import_mode: FileImportMode + :param branch_name: The branch name in the output dataset that will contain the imported data. Defaults to `master` for most enrollments. + :type branch_name: Optional[BranchName] + :param preview: preview + :type preview: Optional[PreviewMode] + :param subfolder: A subfolder in the external system that will be imported. If not specified, defaults to the root folder of the external system. + :type subfolder: Optional[str] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[FileImport] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/connectivity/connections/{connectionRid}/fileImports", + query_params={ + "preview": preview, + }, + path_params={ + "connectionRid": connection_rid, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "datasetRid": dataset_rid, + "importMode": import_mode, + "displayName": display_name, + "branchName": branch_name, + "subfolder": subfolder, + "fileImportFilters": file_import_filters, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "datasetRid": DatasetRid, + "importMode": FileImportMode, + "displayName": FileImportDisplayName, + "branchName": Optional[BranchName], + "subfolder": Optional[str], + "fileImportFilters": List[FileImportFilterDict], + }, + ), + response_type=FileImport, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def delete( + self, + connection_rid: ConnectionRid, + file_import_rid: FileImportRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[None]: + """ + Delete the FileImport with the specified RID. + Deleting the file import does not delete the destination dataset but the dataset will no longer + be updated by this import. + + :param connection_rid: connectionRid + :type connection_rid: ConnectionRid + :param file_import_rid: fileImportRid + :type file_import_rid: FileImportRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[None] + """ + + return self._api_client.stream_api( + RequestInfo( + method="DELETE", + resource_path="/v2/connectivity/connections/{connectionRid}/fileImports/{fileImportRid}", + query_params={ + "preview": preview, + }, + path_params={ + "connectionRid": connection_rid, + "fileImportRid": file_import_rid, + }, + header_params={}, + body=None, + body_type=None, + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def execute( + self, + connection_rid: ConnectionRid, + file_import_rid: FileImportRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[BuildRid]: + """ + Executes the FileImport, which runs asynchronously as a [Foundry Build](/docs/foundry/data-integration/builds/). + The returned BuildRid can be used to check the status via the Orchestration API. + + :param connection_rid: connectionRid + :type connection_rid: ConnectionRid + :param file_import_rid: fileImportRid + :type file_import_rid: FileImportRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[BuildRid] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/connectivity/connections/{connectionRid}/fileImports/{fileImportRid}/execute", + query_params={ + "preview": preview, + }, + path_params={ + "connectionRid": connection_rid, + "fileImportRid": file_import_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=BuildRid, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + connection_rid: ConnectionRid, + file_import_rid: FileImportRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[FileImport]: + """ + Get the FileImport with the specified rid. + :param connection_rid: connectionRid + :type connection_rid: ConnectionRid + :param file_import_rid: fileImportRid + :type file_import_rid: FileImportRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[FileImport] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/connectivity/connections/{connectionRid}/fileImports/{fileImportRid}", + query_params={ + "preview": preview, + }, + path_params={ + "connectionRid": connection_rid, + "fileImportRid": file_import_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=FileImport, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + connection_rid: ConnectionRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListFileImportsResponse]: + """ + Lists all file imports defined for this connection. + Only file imports that the user has permissions to view will be returned. + + :param connection_rid: connectionRid + :type connection_rid: ConnectionRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListFileImportsResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/connectivity/connections/{connectionRid}/fileImports", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "connectionRid": connection_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListFileImportsResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + connection_rid: ConnectionRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListFileImportsResponse]: + """ + Lists all file imports defined for this connection. + Only file imports that the user has permissions to view will be returned. + + :param connection_rid: connectionRid + :type connection_rid: ConnectionRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListFileImportsResponse] + """ + + warnings.warn( + "The client.connectivity.FileImport.page(...) method has been deprecated. Please use client.connectivity.FileImport.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/connectivity/connections/{connectionRid}/fileImports", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "connectionRid": connection_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListFileImportsResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def replace( + self, + connection_rid: ConnectionRid, + file_import_rid: FileImportRid, + *, + dataset_rid: DatasetRid, + display_name: FileImportDisplayName, + file_import_filters: List[FileImportFilterDict], + import_mode: FileImportMode, + branch_name: Optional[BranchName] = None, + preview: Optional[PreviewMode] = None, + subfolder: Optional[str] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[FileImport]: + """ + Replace the FileImport with the specified rid. + :param connection_rid: connectionRid + :type connection_rid: ConnectionRid + :param file_import_rid: fileImportRid + :type file_import_rid: FileImportRid + :param dataset_rid: The RID of the output dataset. + :type dataset_rid: DatasetRid + :param display_name: + :type display_name: FileImportDisplayName + :param file_import_filters: Use filters to limit which files should be imported. Filters are applied in the order they are defined. A different ordering of filters may lead to a more optimized import. [Learn more about optimizing file imports.](/docs/foundry/data-connection/file-based-syncs/#optimize-file-based-syncs) + :type file_import_filters: List[FileImportFilterDict] + :param import_mode: + :type import_mode: FileImportMode + :param branch_name: The branch name in the output dataset that will contain the imported data. Defaults to `master` for most enrollments. + :type branch_name: Optional[BranchName] + :param preview: preview + :type preview: Optional[PreviewMode] + :param subfolder: A subfolder in the external system that will be imported. If not specified, defaults to the root folder of the external system. + :type subfolder: Optional[str] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[FileImport] + """ + + return self._api_client.stream_api( + RequestInfo( + method="PUT", + resource_path="/v2/connectivity/connections/{connectionRid}/fileImports/{fileImportRid}", + query_params={ + "preview": preview, + }, + path_params={ + "connectionRid": connection_rid, + "fileImportRid": file_import_rid, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "datasetRid": dataset_rid, + "importMode": import_mode, + "displayName": display_name, + "branchName": branch_name, + "subfolder": subfolder, + "fileImportFilters": file_import_filters, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "datasetRid": DatasetRid, + "importMode": FileImportMode, + "displayName": FileImportDisplayName, + "branchName": Optional[BranchName], + "subfolder": Optional[str], + "fileImportFilters": List[FileImportFilterDict], + }, + ), + response_type=FileImport, + request_timeout=request_timeout, + ), ) diff --git a/foundry/v2/connectivity/table_import.py b/foundry/v2/connectivity/table_import.py index bcef5bf2..e9d4b8f2 100644 --- a/foundry/v2/connectivity/table_import.py +++ b/foundry/v2/connectivity/table_import.py @@ -25,10 +25,12 @@ from typing_extensions import TypedDict from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo from foundry._core import ResourceIterator +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.connectivity.models._connection_rid import ConnectionRid @@ -58,7 +60,7 @@ class TableImportClient: The API client for the TableImport Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -69,6 +71,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _TableImportClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _TableImportClientRaw(auth=auth, hostname=hostname, config=config) @maybe_ignore_preview @pydantic.validate_call @@ -146,7 +152,7 @@ def create( response_type=TableImport, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -193,7 +199,7 @@ def delete( response_type=None, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -241,7 +247,7 @@ def execute( response_type=BuildRid, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -287,7 +293,7 @@ def get( response_type=TableImport, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -372,11 +378,706 @@ def page( """ warnings.warn( - "The TableImportClient.page(...) method has been deprecated. Please use TableImportClient.list(...) instead.", + "The client.connectivity.TableImport.page(...) method has been deprecated. Please use client.connectivity.TableImport.list(...) instead.", DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/connectivity/connections/{connectionRid}/tableImports", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "connectionRid": connection_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListTableImportsResponse, + request_timeout=request_timeout, + ), + ).decode() + + +class _TableImportClientRaw: + """ + The API client for the TableImport Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def create( + self, + connection_rid: ConnectionRid, + *, + config: CreateTableImportRequestTableImportConfigDict, + dataset_rid: DatasetRid, + display_name: TableImportDisplayName, + import_mode: TableImportMode, + allow_schema_changes: Optional[TableImportAllowSchemaChanges] = None, + branch_name: Optional[BranchName] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[TableImport]: + """ + Creates a new TableImport. + :param connection_rid: connectionRid + :type connection_rid: ConnectionRid + :param config: + :type config: CreateTableImportRequestTableImportConfigDict + :param dataset_rid: The RID of the output dataset. + :type dataset_rid: DatasetRid + :param display_name: + :type display_name: TableImportDisplayName + :param import_mode: + :type import_mode: TableImportMode + :param allow_schema_changes: Allow the TableImport to succeed if the schema of imported rows does not match the existing dataset's schema. Defaults to false for new table imports. + :type allow_schema_changes: Optional[TableImportAllowSchemaChanges] + :param branch_name: The branch name in the output dataset that will contain the imported data. Defaults to `master` for most enrollments. + :type branch_name: Optional[BranchName] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[TableImport] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/connectivity/connections/{connectionRid}/tableImports", + query_params={ + "preview": preview, + }, + path_params={ + "connectionRid": connection_rid, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "datasetRid": dataset_rid, + "importMode": import_mode, + "displayName": display_name, + "allowSchemaChanges": allow_schema_changes, + "branchName": branch_name, + "config": config, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "datasetRid": DatasetRid, + "importMode": TableImportMode, + "displayName": TableImportDisplayName, + "allowSchemaChanges": Optional[TableImportAllowSchemaChanges], + "branchName": Optional[BranchName], + "config": CreateTableImportRequestTableImportConfigDict, + }, + ), + response_type=TableImport, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def delete( + self, + connection_rid: ConnectionRid, + table_import_rid: TableImportRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[None]: + """ + Delete the TableImport with the specified RID. + Deleting the table import does not delete the destination dataset but the dataset will no longer + be updated by this import. + + :param connection_rid: connectionRid + :type connection_rid: ConnectionRid + :param table_import_rid: tableImportRid + :type table_import_rid: TableImportRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[None] + """ + + return self._api_client.call_api( + RequestInfo( + method="DELETE", + resource_path="/v2/connectivity/connections/{connectionRid}/tableImports/{tableImportRid}", + query_params={ + "preview": preview, + }, + path_params={ + "connectionRid": connection_rid, + "tableImportRid": table_import_rid, + }, + header_params={}, + body=None, + body_type=None, + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def execute( + self, + connection_rid: ConnectionRid, + table_import_rid: TableImportRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[BuildRid]: + """ + Executes the TableImport, which runs asynchronously as a [Foundry Build](/docs/foundry/data-integration/builds/). + The returned BuildRid can be used to check the status via the Orchestration API. + + :param connection_rid: connectionRid + :type connection_rid: ConnectionRid + :param table_import_rid: tableImportRid + :type table_import_rid: TableImportRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[BuildRid] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/connectivity/connections/{connectionRid}/tableImports/{tableImportRid}/execute", + query_params={ + "preview": preview, + }, + path_params={ + "connectionRid": connection_rid, + "tableImportRid": table_import_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=BuildRid, + request_timeout=request_timeout, + ), ) + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + connection_rid: ConnectionRid, + table_import_rid: TableImportRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[TableImport]: + """ + Get the TableImport with the specified rid. + :param connection_rid: connectionRid + :type connection_rid: ConnectionRid + :param table_import_rid: tableImportRid + :type table_import_rid: TableImportRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[TableImport] + """ + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/connectivity/connections/{connectionRid}/tableImports/{tableImportRid}", + query_params={ + "preview": preview, + }, + path_params={ + "connectionRid": connection_rid, + "tableImportRid": table_import_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=TableImport, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + connection_rid: ConnectionRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListTableImportsResponse]: + """ + Lists all table imports defined for this connection. + Only table imports that the user has permissions to view will be returned. + + :param connection_rid: connectionRid + :type connection_rid: ConnectionRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListTableImportsResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/connectivity/connections/{connectionRid}/tableImports", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "connectionRid": connection_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListTableImportsResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + connection_rid: ConnectionRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListTableImportsResponse]: + """ + Lists all table imports defined for this connection. + Only table imports that the user has permissions to view will be returned. + + :param connection_rid: connectionRid + :type connection_rid: ConnectionRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListTableImportsResponse] + """ + + warnings.warn( + "The client.connectivity.TableImport.page(...) method has been deprecated. Please use client.connectivity.TableImport.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/connectivity/connections/{connectionRid}/tableImports", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "connectionRid": connection_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListTableImportsResponse, + request_timeout=request_timeout, + ), + ) + + +class _TableImportClientStreaming: + """ + The API client for the TableImport Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def create( + self, + connection_rid: ConnectionRid, + *, + config: CreateTableImportRequestTableImportConfigDict, + dataset_rid: DatasetRid, + display_name: TableImportDisplayName, + import_mode: TableImportMode, + allow_schema_changes: Optional[TableImportAllowSchemaChanges] = None, + branch_name: Optional[BranchName] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[TableImport]: + """ + Creates a new TableImport. + :param connection_rid: connectionRid + :type connection_rid: ConnectionRid + :param config: + :type config: CreateTableImportRequestTableImportConfigDict + :param dataset_rid: The RID of the output dataset. + :type dataset_rid: DatasetRid + :param display_name: + :type display_name: TableImportDisplayName + :param import_mode: + :type import_mode: TableImportMode + :param allow_schema_changes: Allow the TableImport to succeed if the schema of imported rows does not match the existing dataset's schema. Defaults to false for new table imports. + :type allow_schema_changes: Optional[TableImportAllowSchemaChanges] + :param branch_name: The branch name in the output dataset that will contain the imported data. Defaults to `master` for most enrollments. + :type branch_name: Optional[BranchName] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[TableImport] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/connectivity/connections/{connectionRid}/tableImports", + query_params={ + "preview": preview, + }, + path_params={ + "connectionRid": connection_rid, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "datasetRid": dataset_rid, + "importMode": import_mode, + "displayName": display_name, + "allowSchemaChanges": allow_schema_changes, + "branchName": branch_name, + "config": config, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "datasetRid": DatasetRid, + "importMode": TableImportMode, + "displayName": TableImportDisplayName, + "allowSchemaChanges": Optional[TableImportAllowSchemaChanges], + "branchName": Optional[BranchName], + "config": CreateTableImportRequestTableImportConfigDict, + }, + ), + response_type=TableImport, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def delete( + self, + connection_rid: ConnectionRid, + table_import_rid: TableImportRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[None]: + """ + Delete the TableImport with the specified RID. + Deleting the table import does not delete the destination dataset but the dataset will no longer + be updated by this import. + + :param connection_rid: connectionRid + :type connection_rid: ConnectionRid + :param table_import_rid: tableImportRid + :type table_import_rid: TableImportRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[None] + """ + + return self._api_client.stream_api( + RequestInfo( + method="DELETE", + resource_path="/v2/connectivity/connections/{connectionRid}/tableImports/{tableImportRid}", + query_params={ + "preview": preview, + }, + path_params={ + "connectionRid": connection_rid, + "tableImportRid": table_import_rid, + }, + header_params={}, + body=None, + body_type=None, + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def execute( + self, + connection_rid: ConnectionRid, + table_import_rid: TableImportRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[BuildRid]: + """ + Executes the TableImport, which runs asynchronously as a [Foundry Build](/docs/foundry/data-integration/builds/). + The returned BuildRid can be used to check the status via the Orchestration API. + + :param connection_rid: connectionRid + :type connection_rid: ConnectionRid + :param table_import_rid: tableImportRid + :type table_import_rid: TableImportRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[BuildRid] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/connectivity/connections/{connectionRid}/tableImports/{tableImportRid}/execute", + query_params={ + "preview": preview, + }, + path_params={ + "connectionRid": connection_rid, + "tableImportRid": table_import_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=BuildRid, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + connection_rid: ConnectionRid, + table_import_rid: TableImportRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[TableImport]: + """ + Get the TableImport with the specified rid. + :param connection_rid: connectionRid + :type connection_rid: ConnectionRid + :param table_import_rid: tableImportRid + :type table_import_rid: TableImportRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[TableImport] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/connectivity/connections/{connectionRid}/tableImports/{tableImportRid}", + query_params={ + "preview": preview, + }, + path_params={ + "connectionRid": connection_rid, + "tableImportRid": table_import_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=TableImport, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + connection_rid: ConnectionRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListTableImportsResponse]: + """ + Lists all table imports defined for this connection. + Only table imports that the user has permissions to view will be returned. + + :param connection_rid: connectionRid + :type connection_rid: ConnectionRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListTableImportsResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/connectivity/connections/{connectionRid}/tableImports", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "connectionRid": connection_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListTableImportsResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + connection_rid: ConnectionRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListTableImportsResponse]: + """ + Lists all table imports defined for this connection. + Only table imports that the user has permissions to view will be returned. + + :param connection_rid: connectionRid + :type connection_rid: ConnectionRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListTableImportsResponse] + """ + + warnings.warn( + "The client.connectivity.TableImport.page(...) method has been deprecated. Please use client.connectivity.TableImport.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.stream_api( RequestInfo( method="GET", resource_path="/v2/connectivity/connections/{connectionRid}/tableImports", diff --git a/foundry/v2/datasets/branch.py b/foundry/v2/datasets/branch.py index 92dd8d32..e488852b 100644 --- a/foundry/v2/datasets/branch.py +++ b/foundry/v2/datasets/branch.py @@ -25,10 +25,12 @@ from typing_extensions import TypedDict from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo from foundry._core import ResourceIterator +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.core.models._page_size import PageSize @@ -45,7 +47,7 @@ class BranchClient: The API client for the Branch Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -56,6 +58,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _BranchClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _BranchClientRaw(auth=auth, hostname=hostname, config=config) @maybe_ignore_preview @pydantic.validate_call @@ -109,7 +115,7 @@ def create( response_type=Branch, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -149,7 +155,7 @@ def delete( response_type=None, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -191,7 +197,7 @@ def get( response_type=Branch, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -267,8 +273,263 @@ def page( """ warnings.warn( - "The BranchClient.page(...) method has been deprecated. Please use BranchClient.list(...) instead.", + "The client.datasets.Branch.page(...) method has been deprecated. Please use client.datasets.Branch.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/datasets/{datasetRid}/branches", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={ + "datasetRid": dataset_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListBranchesResponse, + request_timeout=request_timeout, + ), + ).decode() + + +class _BranchClientRaw: + """ + The API client for the Branch Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def create( + self, + dataset_rid: DatasetRid, + *, + name: BranchName, + transaction_rid: Optional[TransactionRid] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Branch]: + """ + Creates a branch on an existing dataset. A branch may optionally point to a (committed) transaction. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param name: + :type name: BranchName + :param transaction_rid: The most recent OPEN or COMMITTED transaction on the branch. This will never be an ABORTED transaction. + :type transaction_rid: Optional[TransactionRid] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Branch] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/datasets/{datasetRid}/branches", + query_params={}, + path_params={ + "datasetRid": dataset_rid, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "transactionRid": transaction_rid, + "name": name, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "transactionRid": Optional[TransactionRid], + "name": BranchName, + }, + ), + response_type=Branch, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def delete( + self, + dataset_rid: DatasetRid, + branch_name: BranchName, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[None]: + """ + Deletes the Branch with the given BranchName. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param branch_name: branchName + :type branch_name: BranchName + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[None] + """ + + return self._api_client.call_api( + RequestInfo( + method="DELETE", + resource_path="/v2/datasets/{datasetRid}/branches/{branchName}", + query_params={}, + path_params={ + "datasetRid": dataset_rid, + "branchName": branch_name, + }, + header_params={}, + body=None, + body_type=None, + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + dataset_rid: DatasetRid, + branch_name: BranchName, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Branch]: + """ + Get a Branch of a Dataset. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param branch_name: branchName + :type branch_name: BranchName + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Branch] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/datasets/{datasetRid}/branches/{branchName}", + query_params={}, + path_params={ + "datasetRid": dataset_rid, + "branchName": branch_name, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Branch, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + dataset_rid: DatasetRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListBranchesResponse]: + """ + Lists the Branches of a Dataset. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListBranchesResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/datasets/{datasetRid}/branches", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={ + "datasetRid": dataset_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListBranchesResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + dataset_rid: DatasetRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListBranchesResponse]: + """ + Lists the Branches of a Dataset. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListBranchesResponse] + """ + + warnings.warn( + "The client.datasets.Branch.page(...) method has been deprecated. Please use client.datasets.Branch.list(...) instead.", DeprecationWarning, + stacklevel=2, ) return self._api_client.call_api( @@ -291,3 +552,257 @@ def page( request_timeout=request_timeout, ), ) + + +class _BranchClientStreaming: + """ + The API client for the Branch Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def create( + self, + dataset_rid: DatasetRid, + *, + name: BranchName, + transaction_rid: Optional[TransactionRid] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Branch]: + """ + Creates a branch on an existing dataset. A branch may optionally point to a (committed) transaction. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param name: + :type name: BranchName + :param transaction_rid: The most recent OPEN or COMMITTED transaction on the branch. This will never be an ABORTED transaction. + :type transaction_rid: Optional[TransactionRid] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Branch] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/datasets/{datasetRid}/branches", + query_params={}, + path_params={ + "datasetRid": dataset_rid, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "transactionRid": transaction_rid, + "name": name, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "transactionRid": Optional[TransactionRid], + "name": BranchName, + }, + ), + response_type=Branch, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def delete( + self, + dataset_rid: DatasetRid, + branch_name: BranchName, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[None]: + """ + Deletes the Branch with the given BranchName. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param branch_name: branchName + :type branch_name: BranchName + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[None] + """ + + return self._api_client.stream_api( + RequestInfo( + method="DELETE", + resource_path="/v2/datasets/{datasetRid}/branches/{branchName}", + query_params={}, + path_params={ + "datasetRid": dataset_rid, + "branchName": branch_name, + }, + header_params={}, + body=None, + body_type=None, + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + dataset_rid: DatasetRid, + branch_name: BranchName, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Branch]: + """ + Get a Branch of a Dataset. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param branch_name: branchName + :type branch_name: BranchName + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Branch] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/datasets/{datasetRid}/branches/{branchName}", + query_params={}, + path_params={ + "datasetRid": dataset_rid, + "branchName": branch_name, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Branch, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + dataset_rid: DatasetRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListBranchesResponse]: + """ + Lists the Branches of a Dataset. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListBranchesResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/datasets/{datasetRid}/branches", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={ + "datasetRid": dataset_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListBranchesResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + dataset_rid: DatasetRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListBranchesResponse]: + """ + Lists the Branches of a Dataset. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListBranchesResponse] + """ + + warnings.warn( + "The client.datasets.Branch.page(...) method has been deprecated. Please use client.datasets.Branch.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/datasets/{datasetRid}/branches", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={ + "datasetRid": dataset_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListBranchesResponse, + request_timeout=request_timeout, + ), + ) diff --git a/foundry/v2/datasets/client.py b/foundry/v2/datasets/client.py index ed013c4d..b8ff2b20 100644 --- a/foundry/v2/datasets/client.py +++ b/foundry/v2/datasets/client.py @@ -27,7 +27,7 @@ class DatasetsClient: The API client for the Datasets Namespace. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ diff --git a/foundry/v2/datasets/dataset.py b/foundry/v2/datasets/dataset.py index fe0610c0..e8773a0b 100644 --- a/foundry/v2/datasets/dataset.py +++ b/foundry/v2/datasets/dataset.py @@ -25,13 +25,16 @@ import pydantic from typing_extensions import Annotated from typing_extensions import TypedDict +from typing_extensions import deprecated from typing_extensions import overload from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import BinaryStream from foundry._core import Config from foundry._core import RequestInfo +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.datasets.branch import BranchClient @@ -51,7 +54,7 @@ class DatasetClient: The API client for the Dataset Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -62,6 +65,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _DatasetClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _DatasetClientRaw(auth=auth, hostname=hostname, config=config) self.Branch = BranchClient(auth=auth, hostname=hostname, config=config) self.Transaction = TransactionClient(auth=auth, hostname=hostname, config=config) self.File = FileClient(auth=auth, hostname=hostname, config=config) @@ -113,7 +120,7 @@ def create( response_type=Dataset, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -150,9 +157,12 @@ def get( response_type=Dataset, request_timeout=request_timeout, ), - ) + ).decode() @overload + @deprecated( + "Using the `stream` parameter is deprecated. Please use the `with_streaming_response` instead." + ) def read_table( self, dataset_rid: DatasetRid, @@ -240,6 +250,9 @@ def read_table( ... @overload + @deprecated( + "Using the `stream` parameter is deprecated. Please use the `with_streaming_response` instead." + ) def read_table( self, dataset_rid: DatasetRid, @@ -330,6 +343,13 @@ def read_table( :rtype: Union[bytes, BinaryStream] """ + if stream: + warnings.warn( + f"client.datasets.Dataset.read_table(..., stream=True, chunk_size={chunk_size}) is deprecated. Please use:\n\nwith client.datasets.Dataset.with_streaming_response.read_table(...) as response:\n response.iter_bytes(chunk_size={chunk_size})\n", + DeprecationWarning, + stacklevel=2, + ) + return self._api_client.call_api( RequestInfo( method="GET", @@ -355,4 +375,342 @@ def read_table( chunk_size=chunk_size, request_timeout=request_timeout, ), + ).decode() + + +class _DatasetClientRaw: + """ + The API client for the Dataset Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def create( + self, + *, + name: DatasetName, + parent_folder_rid: FolderRid, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Dataset]: + """ + Creates a new Dataset. A default branch - `master` for most enrollments - will be created on the Dataset. + + :param name: + :type name: DatasetName + :param parent_folder_rid: + :type parent_folder_rid: FolderRid + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Dataset] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/datasets", + query_params={}, + path_params={}, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "parentFolderRid": parent_folder_rid, + "name": name, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "parentFolderRid": FolderRid, + "name": DatasetName, + }, + ), + response_type=Dataset, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + dataset_rid: DatasetRid, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Dataset]: + """ + Get the Dataset with the specified rid. + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Dataset] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/datasets/{datasetRid}", + query_params={}, + path_params={ + "datasetRid": dataset_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Dataset, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def read_table( + self, + dataset_rid: DatasetRid, + *, + format: TableExportFormat, + branch_name: Optional[BranchName] = None, + columns: Optional[List[str]] = None, + end_transaction_rid: Optional[TransactionRid] = None, + row_limit: Optional[int] = None, + start_transaction_rid: Optional[TransactionRid] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[bytes]: + """ + Gets the content of a dataset as a table in the specified format. + + This endpoint currently does not support views (virtual datasets composed of other datasets). + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param format: format + :type format: TableExportFormat + :param branch_name: branchName + :type branch_name: Optional[BranchName] + :param columns: columns + :type columns: Optional[List[str]] + :param end_transaction_rid: endTransactionRid + :type end_transaction_rid: Optional[TransactionRid] + :param row_limit: rowLimit + :type row_limit: Optional[int] + :param start_transaction_rid: startTransactionRid + :type start_transaction_rid: Optional[TransactionRid] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[bytes] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/datasets/{datasetRid}/readTable", + query_params={ + "format": format, + "branchName": branch_name, + "columns": columns, + "endTransactionRid": end_transaction_rid, + "rowLimit": row_limit, + "startTransactionRid": start_transaction_rid, + }, + path_params={ + "datasetRid": dataset_rid, + }, + header_params={ + "Accept": "application/octet-stream", + }, + body=None, + body_type=None, + response_type=bytes, + request_timeout=request_timeout, + ), + ) + + +class _DatasetClientStreaming: + """ + The API client for the Dataset Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def create( + self, + *, + name: DatasetName, + parent_folder_rid: FolderRid, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Dataset]: + """ + Creates a new Dataset. A default branch - `master` for most enrollments - will be created on the Dataset. + + :param name: + :type name: DatasetName + :param parent_folder_rid: + :type parent_folder_rid: FolderRid + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Dataset] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/datasets", + query_params={}, + path_params={}, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "parentFolderRid": parent_folder_rid, + "name": name, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "parentFolderRid": FolderRid, + "name": DatasetName, + }, + ), + response_type=Dataset, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + dataset_rid: DatasetRid, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Dataset]: + """ + Get the Dataset with the specified rid. + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Dataset] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/datasets/{datasetRid}", + query_params={}, + path_params={ + "datasetRid": dataset_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Dataset, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def read_table( + self, + dataset_rid: DatasetRid, + *, + format: TableExportFormat, + branch_name: Optional[BranchName] = None, + columns: Optional[List[str]] = None, + end_transaction_rid: Optional[TransactionRid] = None, + row_limit: Optional[int] = None, + start_transaction_rid: Optional[TransactionRid] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[bytes]: + """ + Gets the content of a dataset as a table in the specified format. + + This endpoint currently does not support views (virtual datasets composed of other datasets). + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param format: format + :type format: TableExportFormat + :param branch_name: branchName + :type branch_name: Optional[BranchName] + :param columns: columns + :type columns: Optional[List[str]] + :param end_transaction_rid: endTransactionRid + :type end_transaction_rid: Optional[TransactionRid] + :param row_limit: rowLimit + :type row_limit: Optional[int] + :param start_transaction_rid: startTransactionRid + :type start_transaction_rid: Optional[TransactionRid] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[bytes] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/datasets/{datasetRid}/readTable", + query_params={ + "format": format, + "branchName": branch_name, + "columns": columns, + "endTransactionRid": end_transaction_rid, + "rowLimit": row_limit, + "startTransactionRid": start_transaction_rid, + }, + path_params={ + "datasetRid": dataset_rid, + }, + header_params={ + "Accept": "application/octet-stream", + }, + body=None, + body_type=None, + response_type=bytes, + request_timeout=request_timeout, + ), ) diff --git a/foundry/v2/datasets/file.py b/foundry/v2/datasets/file.py index 9d6aa191..07d184da 100644 --- a/foundry/v2/datasets/file.py +++ b/foundry/v2/datasets/file.py @@ -24,14 +24,17 @@ import pydantic from typing_extensions import Annotated +from typing_extensions import deprecated from typing_extensions import overload from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import BinaryStream from foundry._core import Config from foundry._core import RequestInfo from foundry._core import ResourceIterator +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.core.models._file_path import FilePath @@ -50,7 +53,7 @@ class FileClient: The API client for the File Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -61,8 +64,15 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _FileClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _FileClientRaw(auth=auth, hostname=hostname, config=config) @overload + @deprecated( + "Using the `stream` parameter is deprecated. Please use the `with_streaming_response` instead." + ) def content( self, dataset_rid: DatasetRid, @@ -166,6 +176,9 @@ def content( ... @overload + @deprecated( + "Using the `stream` parameter is deprecated. Please use the `with_streaming_response` instead." + ) def content( self, dataset_rid: DatasetRid, @@ -272,6 +285,13 @@ def content( :rtype: Union[bytes, BinaryStream] """ + if stream: + warnings.warn( + f"client.datasets.Dataset.File.content(..., stream=True, chunk_size={chunk_size}) is deprecated. Please use:\n\nwith client.datasets.Dataset.File.with_streaming_response.content(...) as response:\n response.iter_bytes(chunk_size={chunk_size})\n", + DeprecationWarning, + stacklevel=2, + ) + return self._api_client.call_api( RequestInfo( method="GET", @@ -295,7 +315,7 @@ def content( chunk_size=chunk_size, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -353,7 +373,7 @@ def delete( response_type=None, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -423,7 +443,7 @@ def get( response_type=File, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -554,8 +574,9 @@ def page( """ warnings.warn( - "The FileClient.page(...) method has been deprecated. Please use FileClient.list(...) instead.", + "The client.datasets.File.page(...) method has been deprecated. Please use client.datasets.File.list(...) instead.", DeprecationWarning, + stacklevel=2, ) return self._api_client.call_api( @@ -580,7 +601,7 @@ def page( response_type=ListFilesResponse, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -651,4 +672,896 @@ def upload( response_type=File, request_timeout=request_timeout, ), + ).decode() + + +class _FileClientRaw: + """ + The API client for the File Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def content( + self, + dataset_rid: DatasetRid, + file_path: FilePath, + *, + branch_name: Optional[BranchName] = None, + end_transaction_rid: Optional[TransactionRid] = None, + start_transaction_rid: Optional[TransactionRid] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[bytes]: + """ + Gets the content of a File contained in a Dataset. By default this retrieves the file's content from the latest + view of the default branch - `master` for most enrollments. + #### Advanced Usage + See [Datasets Core Concepts](/docs/foundry/data-integration/datasets/) for details on using branches and transactions. + To **get a file's content from a specific Branch** specify the Branch's name as `branchName`. This will + retrieve the content for the most recent version of the file since the latest snapshot transaction, or the + earliest ancestor transaction of the branch if there are no snapshot transactions. + To **get a file's content from the resolved view of a transaction** specify the Transaction's resource identifier + as `endTransactionRid`. This will retrieve the content for the most recent version of the file since the latest + snapshot transaction, or the earliest ancestor transaction if there are no snapshot transactions. + To **get a file's content from the resolved view of a range of transactions** specify the the start transaction's + resource identifier as `startTransactionRid` and the end transaction's resource identifier as `endTransactionRid`. + This will retrieve the content for the most recent version of the file since the `startTransactionRid` up to the + `endTransactionRid`. Note that an intermediate snapshot transaction will remove all files from the view. Behavior + is undefined when the start and end transactions do not belong to the same root-to-leaf path. + To **get a file's content from a specific transaction** specify the Transaction's resource identifier as both the + `startTransactionRid` and `endTransactionRid`. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param file_path: filePath + :type file_path: FilePath + :param branch_name: branchName + :type branch_name: Optional[BranchName] + :param end_transaction_rid: endTransactionRid + :type end_transaction_rid: Optional[TransactionRid] + :param start_transaction_rid: startTransactionRid + :type start_transaction_rid: Optional[TransactionRid] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[bytes] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/datasets/{datasetRid}/files/{filePath}/content", + query_params={ + "branchName": branch_name, + "endTransactionRid": end_transaction_rid, + "startTransactionRid": start_transaction_rid, + }, + path_params={ + "datasetRid": dataset_rid, + "filePath": file_path, + }, + header_params={ + "Accept": "application/octet-stream", + }, + body=None, + body_type=None, + response_type=bytes, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def delete( + self, + dataset_rid: DatasetRid, + file_path: FilePath, + *, + branch_name: Optional[BranchName] = None, + transaction_rid: Optional[TransactionRid] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[None]: + """ + Deletes a File from a Dataset. By default the file is deleted in a new transaction on the default + branch - `master` for most enrollments. The file will still be visible on historical views. + #### Advanced Usage + See [Datasets Core Concepts](/docs/foundry/data-integration/datasets/) for details on using branches and transactions. + To **delete a File from a specific Branch** specify the Branch's name as `branchName`. A new delete Transaction + will be created and committed on this branch. + To **delete a File using a manually opened Transaction**, specify the Transaction's resource identifier + as `transactionRid`. The transaction must be of type `DELETE`. This is useful for deleting multiple files in a + single transaction. See [createTransaction](/docs/foundry/api/datasets-resources/transactions/create-transaction/) to + open a transaction. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param file_path: filePath + :type file_path: FilePath + :param branch_name: branchName + :type branch_name: Optional[BranchName] + :param transaction_rid: transactionRid + :type transaction_rid: Optional[TransactionRid] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[None] + """ + + return self._api_client.call_api( + RequestInfo( + method="DELETE", + resource_path="/v2/datasets/{datasetRid}/files/{filePath}", + query_params={ + "branchName": branch_name, + "transactionRid": transaction_rid, + }, + path_params={ + "datasetRid": dataset_rid, + "filePath": file_path, + }, + header_params={}, + body=None, + body_type=None, + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + dataset_rid: DatasetRid, + file_path: FilePath, + *, + branch_name: Optional[BranchName] = None, + end_transaction_rid: Optional[TransactionRid] = None, + start_transaction_rid: Optional[TransactionRid] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[File]: + """ + Gets metadata about a File contained in a Dataset. By default this retrieves the file's metadata from the latest + view of the default branch - `master` for most enrollments. + #### Advanced Usage + See [Datasets Core Concepts](/docs/foundry/data-integration/datasets/) for details on using branches and transactions. + To **get a file's metadata from a specific Branch** specify the Branch's name as `branchName`. This will + retrieve metadata for the most recent version of the file since the latest snapshot transaction, or the earliest + ancestor transaction of the branch if there are no snapshot transactions. + To **get a file's metadata from the resolved view of a transaction** specify the Transaction's resource identifier + as `endTransactionRid`. This will retrieve metadata for the most recent version of the file since the latest snapshot + transaction, or the earliest ancestor transaction if there are no snapshot transactions. + To **get a file's metadata from the resolved view of a range of transactions** specify the the start transaction's + resource identifier as `startTransactionRid` and the end transaction's resource identifier as `endTransactionRid`. + This will retrieve metadata for the most recent version of the file since the `startTransactionRid` up to the + `endTransactionRid`. Behavior is undefined when the start and end transactions do not belong to the same root-to-leaf path. + To **get a file's metadata from a specific transaction** specify the Transaction's resource identifier as both the + `startTransactionRid` and `endTransactionRid`. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param file_path: filePath + :type file_path: FilePath + :param branch_name: branchName + :type branch_name: Optional[BranchName] + :param end_transaction_rid: endTransactionRid + :type end_transaction_rid: Optional[TransactionRid] + :param start_transaction_rid: startTransactionRid + :type start_transaction_rid: Optional[TransactionRid] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[File] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/datasets/{datasetRid}/files/{filePath}", + query_params={ + "branchName": branch_name, + "endTransactionRid": end_transaction_rid, + "startTransactionRid": start_transaction_rid, + }, + path_params={ + "datasetRid": dataset_rid, + "filePath": file_path, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=File, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + dataset_rid: DatasetRid, + *, + branch_name: Optional[BranchName] = None, + end_transaction_rid: Optional[TransactionRid] = None, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + start_transaction_rid: Optional[TransactionRid] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListFilesResponse]: + """ + Lists Files contained in a Dataset. By default files are listed on the latest view of the default + branch - `master` for most enrollments. + #### Advanced Usage + See [Datasets Core Concepts](/docs/foundry/data-integration/datasets/) for details on using branches and transactions. + To **list files on a specific Branch** specify the Branch's name as `branchName`. This will include the most + recent version of all files since the latest snapshot transaction, or the earliest ancestor transaction of the + branch if there are no snapshot transactions. + To **list files on the resolved view of a transaction** specify the Transaction's resource identifier + as `endTransactionRid`. This will include the most recent version of all files since the latest snapshot + transaction, or the earliest ancestor transaction if there are no snapshot transactions. + To **list files on the resolved view of a range of transactions** specify the the start transaction's resource + identifier as `startTransactionRid` and the end transaction's resource identifier as `endTransactionRid`. This + will include the most recent version of all files since the `startTransactionRid` up to the `endTransactionRid`. + Note that an intermediate snapshot transaction will remove all files from the view. Behavior is undefined when + the start and end transactions do not belong to the same root-to-leaf path. + To **list files on a specific transaction** specify the Transaction's resource identifier as both the + `startTransactionRid` and `endTransactionRid`. This will include only files that were modified as part of that + Transaction. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param branch_name: branchName + :type branch_name: Optional[BranchName] + :param end_transaction_rid: endTransactionRid + :type end_transaction_rid: Optional[TransactionRid] + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param start_transaction_rid: startTransactionRid + :type start_transaction_rid: Optional[TransactionRid] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListFilesResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/datasets/{datasetRid}/files", + query_params={ + "branchName": branch_name, + "endTransactionRid": end_transaction_rid, + "pageSize": page_size, + "pageToken": page_token, + "startTransactionRid": start_transaction_rid, + }, + path_params={ + "datasetRid": dataset_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListFilesResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + dataset_rid: DatasetRid, + *, + branch_name: Optional[BranchName] = None, + end_transaction_rid: Optional[TransactionRid] = None, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + start_transaction_rid: Optional[TransactionRid] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListFilesResponse]: + """ + Lists Files contained in a Dataset. By default files are listed on the latest view of the default + branch - `master` for most enrollments. + #### Advanced Usage + See [Datasets Core Concepts](/docs/foundry/data-integration/datasets/) for details on using branches and transactions. + To **list files on a specific Branch** specify the Branch's name as `branchName`. This will include the most + recent version of all files since the latest snapshot transaction, or the earliest ancestor transaction of the + branch if there are no snapshot transactions. + To **list files on the resolved view of a transaction** specify the Transaction's resource identifier + as `endTransactionRid`. This will include the most recent version of all files since the latest snapshot + transaction, or the earliest ancestor transaction if there are no snapshot transactions. + To **list files on the resolved view of a range of transactions** specify the the start transaction's resource + identifier as `startTransactionRid` and the end transaction's resource identifier as `endTransactionRid`. This + will include the most recent version of all files since the `startTransactionRid` up to the `endTransactionRid`. + Note that an intermediate snapshot transaction will remove all files from the view. Behavior is undefined when + the start and end transactions do not belong to the same root-to-leaf path. + To **list files on a specific transaction** specify the Transaction's resource identifier as both the + `startTransactionRid` and `endTransactionRid`. This will include only files that were modified as part of that + Transaction. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param branch_name: branchName + :type branch_name: Optional[BranchName] + :param end_transaction_rid: endTransactionRid + :type end_transaction_rid: Optional[TransactionRid] + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param start_transaction_rid: startTransactionRid + :type start_transaction_rid: Optional[TransactionRid] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListFilesResponse] + """ + + warnings.warn( + "The client.datasets.File.page(...) method has been deprecated. Please use client.datasets.File.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/datasets/{datasetRid}/files", + query_params={ + "branchName": branch_name, + "endTransactionRid": end_transaction_rid, + "pageSize": page_size, + "pageToken": page_token, + "startTransactionRid": start_transaction_rid, + }, + path_params={ + "datasetRid": dataset_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListFilesResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def upload( + self, + dataset_rid: DatasetRid, + file_path: FilePath, + body: bytes, + *, + branch_name: Optional[BranchName] = None, + transaction_rid: Optional[TransactionRid] = None, + transaction_type: Optional[TransactionType] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[File]: + """ + Uploads a File to an existing Dataset. + The body of the request must contain the binary content of the file and the `Content-Type` header must be `application/octet-stream`. + By default the file is uploaded to a new transaction on the default branch - `master` for most enrollments. + If the file already exists only the most recent version will be visible in the updated view. + #### Advanced Usage + See [Datasets Core Concepts](/docs/foundry/data-integration/datasets/) for details on using branches and transactions. + To **upload a file to a specific Branch** specify the Branch's name as `branchName`. A new transaction will + be created and committed on this branch. By default the TransactionType will be `UPDATE`, to override this + default specify `transactionType` in addition to `branchName`. + See [createBranch](/docs/foundry/api/datasets-resources/branches/create-branch/) to create a custom branch. + To **upload a file on a manually opened transaction** specify the Transaction's resource identifier as + `transactionRid`. This is useful for uploading multiple files in a single transaction. + See [createTransaction](/docs/foundry/api/datasets-resources/transactions/create-transaction/) to open a transaction. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param file_path: filePath + :type file_path: FilePath + :param body: Body of the request + :type body: bytes + :param branch_name: branchName + :type branch_name: Optional[BranchName] + :param transaction_rid: transactionRid + :type transaction_rid: Optional[TransactionRid] + :param transaction_type: transactionType + :type transaction_type: Optional[TransactionType] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[File] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/datasets/{datasetRid}/files/{filePath}/upload", + query_params={ + "branchName": branch_name, + "transactionRid": transaction_rid, + "transactionType": transaction_type, + }, + path_params={ + "datasetRid": dataset_rid, + "filePath": file_path, + }, + header_params={ + "Content-Type": "application/octet-stream", + "Accept": "application/json", + }, + body=body, + body_type=bytes, + response_type=File, + request_timeout=request_timeout, + ), + ) + + +class _FileClientStreaming: + """ + The API client for the File Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def content( + self, + dataset_rid: DatasetRid, + file_path: FilePath, + *, + branch_name: Optional[BranchName] = None, + end_transaction_rid: Optional[TransactionRid] = None, + start_transaction_rid: Optional[TransactionRid] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[bytes]: + """ + Gets the content of a File contained in a Dataset. By default this retrieves the file's content from the latest + view of the default branch - `master` for most enrollments. + #### Advanced Usage + See [Datasets Core Concepts](/docs/foundry/data-integration/datasets/) for details on using branches and transactions. + To **get a file's content from a specific Branch** specify the Branch's name as `branchName`. This will + retrieve the content for the most recent version of the file since the latest snapshot transaction, or the + earliest ancestor transaction of the branch if there are no snapshot transactions. + To **get a file's content from the resolved view of a transaction** specify the Transaction's resource identifier + as `endTransactionRid`. This will retrieve the content for the most recent version of the file since the latest + snapshot transaction, or the earliest ancestor transaction if there are no snapshot transactions. + To **get a file's content from the resolved view of a range of transactions** specify the the start transaction's + resource identifier as `startTransactionRid` and the end transaction's resource identifier as `endTransactionRid`. + This will retrieve the content for the most recent version of the file since the `startTransactionRid` up to the + `endTransactionRid`. Note that an intermediate snapshot transaction will remove all files from the view. Behavior + is undefined when the start and end transactions do not belong to the same root-to-leaf path. + To **get a file's content from a specific transaction** specify the Transaction's resource identifier as both the + `startTransactionRid` and `endTransactionRid`. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param file_path: filePath + :type file_path: FilePath + :param branch_name: branchName + :type branch_name: Optional[BranchName] + :param end_transaction_rid: endTransactionRid + :type end_transaction_rid: Optional[TransactionRid] + :param start_transaction_rid: startTransactionRid + :type start_transaction_rid: Optional[TransactionRid] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[bytes] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/datasets/{datasetRid}/files/{filePath}/content", + query_params={ + "branchName": branch_name, + "endTransactionRid": end_transaction_rid, + "startTransactionRid": start_transaction_rid, + }, + path_params={ + "datasetRid": dataset_rid, + "filePath": file_path, + }, + header_params={ + "Accept": "application/octet-stream", + }, + body=None, + body_type=None, + response_type=bytes, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def delete( + self, + dataset_rid: DatasetRid, + file_path: FilePath, + *, + branch_name: Optional[BranchName] = None, + transaction_rid: Optional[TransactionRid] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[None]: + """ + Deletes a File from a Dataset. By default the file is deleted in a new transaction on the default + branch - `master` for most enrollments. The file will still be visible on historical views. + #### Advanced Usage + See [Datasets Core Concepts](/docs/foundry/data-integration/datasets/) for details on using branches and transactions. + To **delete a File from a specific Branch** specify the Branch's name as `branchName`. A new delete Transaction + will be created and committed on this branch. + To **delete a File using a manually opened Transaction**, specify the Transaction's resource identifier + as `transactionRid`. The transaction must be of type `DELETE`. This is useful for deleting multiple files in a + single transaction. See [createTransaction](/docs/foundry/api/datasets-resources/transactions/create-transaction/) to + open a transaction. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param file_path: filePath + :type file_path: FilePath + :param branch_name: branchName + :type branch_name: Optional[BranchName] + :param transaction_rid: transactionRid + :type transaction_rid: Optional[TransactionRid] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[None] + """ + + return self._api_client.stream_api( + RequestInfo( + method="DELETE", + resource_path="/v2/datasets/{datasetRid}/files/{filePath}", + query_params={ + "branchName": branch_name, + "transactionRid": transaction_rid, + }, + path_params={ + "datasetRid": dataset_rid, + "filePath": file_path, + }, + header_params={}, + body=None, + body_type=None, + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + dataset_rid: DatasetRid, + file_path: FilePath, + *, + branch_name: Optional[BranchName] = None, + end_transaction_rid: Optional[TransactionRid] = None, + start_transaction_rid: Optional[TransactionRid] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[File]: + """ + Gets metadata about a File contained in a Dataset. By default this retrieves the file's metadata from the latest + view of the default branch - `master` for most enrollments. + #### Advanced Usage + See [Datasets Core Concepts](/docs/foundry/data-integration/datasets/) for details on using branches and transactions. + To **get a file's metadata from a specific Branch** specify the Branch's name as `branchName`. This will + retrieve metadata for the most recent version of the file since the latest snapshot transaction, or the earliest + ancestor transaction of the branch if there are no snapshot transactions. + To **get a file's metadata from the resolved view of a transaction** specify the Transaction's resource identifier + as `endTransactionRid`. This will retrieve metadata for the most recent version of the file since the latest snapshot + transaction, or the earliest ancestor transaction if there are no snapshot transactions. + To **get a file's metadata from the resolved view of a range of transactions** specify the the start transaction's + resource identifier as `startTransactionRid` and the end transaction's resource identifier as `endTransactionRid`. + This will retrieve metadata for the most recent version of the file since the `startTransactionRid` up to the + `endTransactionRid`. Behavior is undefined when the start and end transactions do not belong to the same root-to-leaf path. + To **get a file's metadata from a specific transaction** specify the Transaction's resource identifier as both the + `startTransactionRid` and `endTransactionRid`. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param file_path: filePath + :type file_path: FilePath + :param branch_name: branchName + :type branch_name: Optional[BranchName] + :param end_transaction_rid: endTransactionRid + :type end_transaction_rid: Optional[TransactionRid] + :param start_transaction_rid: startTransactionRid + :type start_transaction_rid: Optional[TransactionRid] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[File] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/datasets/{datasetRid}/files/{filePath}", + query_params={ + "branchName": branch_name, + "endTransactionRid": end_transaction_rid, + "startTransactionRid": start_transaction_rid, + }, + path_params={ + "datasetRid": dataset_rid, + "filePath": file_path, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=File, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + dataset_rid: DatasetRid, + *, + branch_name: Optional[BranchName] = None, + end_transaction_rid: Optional[TransactionRid] = None, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + start_transaction_rid: Optional[TransactionRid] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListFilesResponse]: + """ + Lists Files contained in a Dataset. By default files are listed on the latest view of the default + branch - `master` for most enrollments. + #### Advanced Usage + See [Datasets Core Concepts](/docs/foundry/data-integration/datasets/) for details on using branches and transactions. + To **list files on a specific Branch** specify the Branch's name as `branchName`. This will include the most + recent version of all files since the latest snapshot transaction, or the earliest ancestor transaction of the + branch if there are no snapshot transactions. + To **list files on the resolved view of a transaction** specify the Transaction's resource identifier + as `endTransactionRid`. This will include the most recent version of all files since the latest snapshot + transaction, or the earliest ancestor transaction if there are no snapshot transactions. + To **list files on the resolved view of a range of transactions** specify the the start transaction's resource + identifier as `startTransactionRid` and the end transaction's resource identifier as `endTransactionRid`. This + will include the most recent version of all files since the `startTransactionRid` up to the `endTransactionRid`. + Note that an intermediate snapshot transaction will remove all files from the view. Behavior is undefined when + the start and end transactions do not belong to the same root-to-leaf path. + To **list files on a specific transaction** specify the Transaction's resource identifier as both the + `startTransactionRid` and `endTransactionRid`. This will include only files that were modified as part of that + Transaction. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param branch_name: branchName + :type branch_name: Optional[BranchName] + :param end_transaction_rid: endTransactionRid + :type end_transaction_rid: Optional[TransactionRid] + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param start_transaction_rid: startTransactionRid + :type start_transaction_rid: Optional[TransactionRid] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListFilesResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/datasets/{datasetRid}/files", + query_params={ + "branchName": branch_name, + "endTransactionRid": end_transaction_rid, + "pageSize": page_size, + "pageToken": page_token, + "startTransactionRid": start_transaction_rid, + }, + path_params={ + "datasetRid": dataset_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListFilesResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + dataset_rid: DatasetRid, + *, + branch_name: Optional[BranchName] = None, + end_transaction_rid: Optional[TransactionRid] = None, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + start_transaction_rid: Optional[TransactionRid] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListFilesResponse]: + """ + Lists Files contained in a Dataset. By default files are listed on the latest view of the default + branch - `master` for most enrollments. + #### Advanced Usage + See [Datasets Core Concepts](/docs/foundry/data-integration/datasets/) for details on using branches and transactions. + To **list files on a specific Branch** specify the Branch's name as `branchName`. This will include the most + recent version of all files since the latest snapshot transaction, or the earliest ancestor transaction of the + branch if there are no snapshot transactions. + To **list files on the resolved view of a transaction** specify the Transaction's resource identifier + as `endTransactionRid`. This will include the most recent version of all files since the latest snapshot + transaction, or the earliest ancestor transaction if there are no snapshot transactions. + To **list files on the resolved view of a range of transactions** specify the the start transaction's resource + identifier as `startTransactionRid` and the end transaction's resource identifier as `endTransactionRid`. This + will include the most recent version of all files since the `startTransactionRid` up to the `endTransactionRid`. + Note that an intermediate snapshot transaction will remove all files from the view. Behavior is undefined when + the start and end transactions do not belong to the same root-to-leaf path. + To **list files on a specific transaction** specify the Transaction's resource identifier as both the + `startTransactionRid` and `endTransactionRid`. This will include only files that were modified as part of that + Transaction. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param branch_name: branchName + :type branch_name: Optional[BranchName] + :param end_transaction_rid: endTransactionRid + :type end_transaction_rid: Optional[TransactionRid] + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param start_transaction_rid: startTransactionRid + :type start_transaction_rid: Optional[TransactionRid] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListFilesResponse] + """ + + warnings.warn( + "The client.datasets.File.page(...) method has been deprecated. Please use client.datasets.File.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/datasets/{datasetRid}/files", + query_params={ + "branchName": branch_name, + "endTransactionRid": end_transaction_rid, + "pageSize": page_size, + "pageToken": page_token, + "startTransactionRid": start_transaction_rid, + }, + path_params={ + "datasetRid": dataset_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListFilesResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def upload( + self, + dataset_rid: DatasetRid, + file_path: FilePath, + body: bytes, + *, + branch_name: Optional[BranchName] = None, + transaction_rid: Optional[TransactionRid] = None, + transaction_type: Optional[TransactionType] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[File]: + """ + Uploads a File to an existing Dataset. + The body of the request must contain the binary content of the file and the `Content-Type` header must be `application/octet-stream`. + By default the file is uploaded to a new transaction on the default branch - `master` for most enrollments. + If the file already exists only the most recent version will be visible in the updated view. + #### Advanced Usage + See [Datasets Core Concepts](/docs/foundry/data-integration/datasets/) for details on using branches and transactions. + To **upload a file to a specific Branch** specify the Branch's name as `branchName`. A new transaction will + be created and committed on this branch. By default the TransactionType will be `UPDATE`, to override this + default specify `transactionType` in addition to `branchName`. + See [createBranch](/docs/foundry/api/datasets-resources/branches/create-branch/) to create a custom branch. + To **upload a file on a manually opened transaction** specify the Transaction's resource identifier as + `transactionRid`. This is useful for uploading multiple files in a single transaction. + See [createTransaction](/docs/foundry/api/datasets-resources/transactions/create-transaction/) to open a transaction. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param file_path: filePath + :type file_path: FilePath + :param body: Body of the request + :type body: bytes + :param branch_name: branchName + :type branch_name: Optional[BranchName] + :param transaction_rid: transactionRid + :type transaction_rid: Optional[TransactionRid] + :param transaction_type: transactionType + :type transaction_type: Optional[TransactionType] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[File] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/datasets/{datasetRid}/files/{filePath}/upload", + query_params={ + "branchName": branch_name, + "transactionRid": transaction_rid, + "transactionType": transaction_type, + }, + path_params={ + "datasetRid": dataset_rid, + "filePath": file_path, + }, + header_params={ + "Content-Type": "application/octet-stream", + "Accept": "application/json", + }, + body=body, + body_type=bytes, + response_type=File, + request_timeout=request_timeout, + ), ) diff --git a/foundry/v2/datasets/transaction.py b/foundry/v2/datasets/transaction.py index d2cec603..6cccd3da 100644 --- a/foundry/v2/datasets/transaction.py +++ b/foundry/v2/datasets/transaction.py @@ -24,9 +24,11 @@ from typing_extensions import TypedDict from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.datasets.models._branch_name import BranchName @@ -41,7 +43,7 @@ class TransactionClient: The API client for the Transaction Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -52,6 +54,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _TransactionClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _TransactionClientRaw(auth=auth, hostname=hostname, config=config) @maybe_ignore_preview @pydantic.validate_call @@ -94,7 +100,7 @@ def abort( response_type=Transaction, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -137,7 +143,7 @@ def commit( response_type=Transaction, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -191,7 +197,7 @@ def create( response_type=Transaction, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -233,4 +239,404 @@ def get( response_type=Transaction, request_timeout=request_timeout, ), + ).decode() + + +class _TransactionClientRaw: + """ + The API client for the Transaction Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def abort( + self, + dataset_rid: DatasetRid, + transaction_rid: TransactionRid, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Transaction]: + """ + Aborts an open Transaction. File modifications made on this Transaction are not preserved and the Branch is + not updated. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param transaction_rid: transactionRid + :type transaction_rid: TransactionRid + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Transaction] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/datasets/{datasetRid}/transactions/{transactionRid}/abort", + query_params={}, + path_params={ + "datasetRid": dataset_rid, + "transactionRid": transaction_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Transaction, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def commit( + self, + dataset_rid: DatasetRid, + transaction_rid: TransactionRid, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Transaction]: + """ + Commits an open Transaction. File modifications made on this Transaction are preserved and the Branch is + updated to point to the Transaction. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param transaction_rid: transactionRid + :type transaction_rid: TransactionRid + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Transaction] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/datasets/{datasetRid}/transactions/{transactionRid}/commit", + query_params={}, + path_params={ + "datasetRid": dataset_rid, + "transactionRid": transaction_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Transaction, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def create( + self, + dataset_rid: DatasetRid, + *, + transaction_type: TransactionType, + branch_name: Optional[BranchName] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Transaction]: + """ + Creates a Transaction on a Branch of a Dataset. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param transaction_type: + :type transaction_type: TransactionType + :param branch_name: branchName + :type branch_name: Optional[BranchName] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Transaction] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/datasets/{datasetRid}/transactions", + query_params={ + "branchName": branch_name, + }, + path_params={ + "datasetRid": dataset_rid, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "transactionType": transaction_type, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "transactionType": TransactionType, + }, + ), + response_type=Transaction, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + dataset_rid: DatasetRid, + transaction_rid: TransactionRid, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Transaction]: + """ + Gets a Transaction of a Dataset. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param transaction_rid: transactionRid + :type transaction_rid: TransactionRid + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Transaction] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/datasets/{datasetRid}/transactions/{transactionRid}", + query_params={}, + path_params={ + "datasetRid": dataset_rid, + "transactionRid": transaction_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Transaction, + request_timeout=request_timeout, + ), + ) + + +class _TransactionClientStreaming: + """ + The API client for the Transaction Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def abort( + self, + dataset_rid: DatasetRid, + transaction_rid: TransactionRid, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Transaction]: + """ + Aborts an open Transaction. File modifications made on this Transaction are not preserved and the Branch is + not updated. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param transaction_rid: transactionRid + :type transaction_rid: TransactionRid + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Transaction] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/datasets/{datasetRid}/transactions/{transactionRid}/abort", + query_params={}, + path_params={ + "datasetRid": dataset_rid, + "transactionRid": transaction_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Transaction, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def commit( + self, + dataset_rid: DatasetRid, + transaction_rid: TransactionRid, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Transaction]: + """ + Commits an open Transaction. File modifications made on this Transaction are preserved and the Branch is + updated to point to the Transaction. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param transaction_rid: transactionRid + :type transaction_rid: TransactionRid + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Transaction] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/datasets/{datasetRid}/transactions/{transactionRid}/commit", + query_params={}, + path_params={ + "datasetRid": dataset_rid, + "transactionRid": transaction_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Transaction, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def create( + self, + dataset_rid: DatasetRid, + *, + transaction_type: TransactionType, + branch_name: Optional[BranchName] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Transaction]: + """ + Creates a Transaction on a Branch of a Dataset. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param transaction_type: + :type transaction_type: TransactionType + :param branch_name: branchName + :type branch_name: Optional[BranchName] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Transaction] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/datasets/{datasetRid}/transactions", + query_params={ + "branchName": branch_name, + }, + path_params={ + "datasetRid": dataset_rid, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "transactionType": transaction_type, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "transactionType": TransactionType, + }, + ), + response_type=Transaction, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + dataset_rid: DatasetRid, + transaction_rid: TransactionRid, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Transaction]: + """ + Gets a Transaction of a Dataset. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param transaction_rid: transactionRid + :type transaction_rid: TransactionRid + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Transaction] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/datasets/{datasetRid}/transactions/{transactionRid}", + query_params={}, + path_params={ + "datasetRid": dataset_rid, + "transactionRid": transaction_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Transaction, + request_timeout=request_timeout, + ), ) diff --git a/foundry/v2/filesystem/client.py b/foundry/v2/filesystem/client.py index c98a6d9a..72f5af77 100644 --- a/foundry/v2/filesystem/client.py +++ b/foundry/v2/filesystem/client.py @@ -29,7 +29,7 @@ class FilesystemClient: The API client for the Filesystem Namespace. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ diff --git a/foundry/v2/filesystem/folder.py b/foundry/v2/filesystem/folder.py index f5962f45..a255ef52 100644 --- a/foundry/v2/filesystem/folder.py +++ b/foundry/v2/filesystem/folder.py @@ -25,10 +25,12 @@ from typing_extensions import TypedDict from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo from foundry._core import ResourceIterator +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.core.models._page_size import PageSize @@ -48,7 +50,7 @@ class FolderClient: The API client for the Folder Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -59,6 +61,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _FolderClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _FolderClientRaw(auth=auth, hostname=hostname, config=config) @maybe_ignore_preview @pydantic.validate_call @@ -147,8 +153,9 @@ def children_page( """ warnings.warn( - "The FolderClient.childrenPage(...) method has been deprecated. Please use FolderClient.children(...) instead.", + "The client.filesystem.Folder.children_page(...) method has been deprecated. Please use client.filesystem.Folder.children(...) instead.", DeprecationWarning, + stacklevel=2, ) return self._api_client.call_api( @@ -171,7 +178,7 @@ def children_page( response_type=ListChildrenOfFolderResponse, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -224,7 +231,7 @@ def create( response_type=Folder, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -266,4 +273,458 @@ def get( response_type=Folder, request_timeout=request_timeout, ), + ).decode() + + +class _FolderClientRaw: + """ + The API client for the Folder Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def children( + self, + folder_rid: FolderRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListChildrenOfFolderResponse]: + """ + List all child Resources of the Folder. + + This is a paged endpoint. The page size will be limited to 2,000 results per page. If no page size is + provided, this page size will also be used as the default. + + :param folder_rid: folderRid + :type folder_rid: FolderRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListChildrenOfFolderResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/filesystem/folders/{folderRid}/children", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "folderRid": folder_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListChildrenOfFolderResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def children_page( + self, + folder_rid: FolderRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListChildrenOfFolderResponse]: + """ + List all child Resources of the Folder. + + This is a paged endpoint. The page size will be limited to 2,000 results per page. If no page size is + provided, this page size will also be used as the default. + + :param folder_rid: folderRid + :type folder_rid: FolderRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListChildrenOfFolderResponse] + """ + + warnings.warn( + "The client.filesystem.Folder.children_page(...) method has been deprecated. Please use client.filesystem.Folder.children(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/filesystem/folders/{folderRid}/children", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "folderRid": folder_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListChildrenOfFolderResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def create( + self, + *, + display_name: ResourceDisplayName, + parent_folder_rid: FolderRid, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Folder]: + """ + Creates a new Folder. + :param display_name: + :type display_name: ResourceDisplayName + :param parent_folder_rid: The parent folder Resource Identifier (RID). For Projects, this will be the Space RID and for Spaces, this value will be the root folder (`ri.compass.main.folder.0`). + :type parent_folder_rid: FolderRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Folder] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/filesystem/folders", + query_params={ + "preview": preview, + }, + path_params={}, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "parentFolderRid": parent_folder_rid, + "displayName": display_name, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "parentFolderRid": FolderRid, + "displayName": ResourceDisplayName, + }, + ), + response_type=Folder, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + folder_rid: FolderRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Folder]: + """ + Get the Folder with the specified rid. + :param folder_rid: folderRid + :type folder_rid: FolderRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Folder] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/filesystem/folders/{folderRid}", + query_params={ + "preview": preview, + }, + path_params={ + "folderRid": folder_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Folder, + request_timeout=request_timeout, + ), + ) + + +class _FolderClientStreaming: + """ + The API client for the Folder Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def children( + self, + folder_rid: FolderRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListChildrenOfFolderResponse]: + """ + List all child Resources of the Folder. + + This is a paged endpoint. The page size will be limited to 2,000 results per page. If no page size is + provided, this page size will also be used as the default. + + :param folder_rid: folderRid + :type folder_rid: FolderRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListChildrenOfFolderResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/filesystem/folders/{folderRid}/children", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "folderRid": folder_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListChildrenOfFolderResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def children_page( + self, + folder_rid: FolderRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListChildrenOfFolderResponse]: + """ + List all child Resources of the Folder. + + This is a paged endpoint. The page size will be limited to 2,000 results per page. If no page size is + provided, this page size will also be used as the default. + + :param folder_rid: folderRid + :type folder_rid: FolderRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListChildrenOfFolderResponse] + """ + + warnings.warn( + "The client.filesystem.Folder.children_page(...) method has been deprecated. Please use client.filesystem.Folder.children(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/filesystem/folders/{folderRid}/children", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "folderRid": folder_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListChildrenOfFolderResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def create( + self, + *, + display_name: ResourceDisplayName, + parent_folder_rid: FolderRid, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Folder]: + """ + Creates a new Folder. + :param display_name: + :type display_name: ResourceDisplayName + :param parent_folder_rid: The parent folder Resource Identifier (RID). For Projects, this will be the Space RID and for Spaces, this value will be the root folder (`ri.compass.main.folder.0`). + :type parent_folder_rid: FolderRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Folder] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/filesystem/folders", + query_params={ + "preview": preview, + }, + path_params={}, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "parentFolderRid": parent_folder_rid, + "displayName": display_name, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "parentFolderRid": FolderRid, + "displayName": ResourceDisplayName, + }, + ), + response_type=Folder, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + folder_rid: FolderRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Folder]: + """ + Get the Folder with the specified rid. + :param folder_rid: folderRid + :type folder_rid: FolderRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Folder] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/filesystem/folders/{folderRid}", + query_params={ + "preview": preview, + }, + path_params={ + "folderRid": folder_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Folder, + request_timeout=request_timeout, + ), ) diff --git a/foundry/v2/filesystem/project.py b/foundry/v2/filesystem/project.py index 79113c66..3696b278 100644 --- a/foundry/v2/filesystem/project.py +++ b/foundry/v2/filesystem/project.py @@ -26,10 +26,12 @@ from typing_extensions import TypedDict from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo from foundry._core import ResourceIterator +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.core.models._organization_rid import OrganizationRid @@ -52,7 +54,7 @@ class ProjectClient: The API client for the Project Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -63,6 +65,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _ProjectClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _ProjectClientRaw(auth=auth, hostname=hostname, config=config) @maybe_ignore_preview @pydantic.validate_call @@ -114,7 +120,7 @@ def add_organizations( response_type=None, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -187,7 +193,7 @@ def create( response_type=Project, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -229,7 +235,7 @@ def get( response_type=Project, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -314,8 +320,9 @@ def organizations_page( """ warnings.warn( - "The ProjectClient.organizationsPage(...) method has been deprecated. Please use ProjectClient.organizations(...) instead.", + "The client.filesystem.Project.organizations_page(...) method has been deprecated. Please use client.filesystem.Project.organizations(...) instead.", DeprecationWarning, + stacklevel=2, ) return self._api_client.call_api( @@ -338,7 +345,7 @@ def organizations_page( response_type=ListOrganizationsOfProjectResponse, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -390,4 +397,698 @@ def remove_organizations( response_type=None, request_timeout=request_timeout, ), + ).decode() + + +class _ProjectClientRaw: + """ + The API client for the Project Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def add_organizations( + self, + project_rid: ProjectRid, + *, + organization_rids: List[OrganizationRid], + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[None]: + """ + Adds a list of Organizations to a Project. + :param project_rid: projectRid + :type project_rid: ProjectRid + :param organization_rids: + :type organization_rids: List[OrganizationRid] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[None] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/filesystem/projects/{projectRid}/addOrganizations", + query_params={ + "preview": preview, + }, + path_params={ + "projectRid": project_rid, + }, + header_params={ + "Content-Type": "application/json", + }, + body={ + "organizationRids": organization_rids, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "organizationRids": List[OrganizationRid], + }, + ), + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def create( + self, + *, + default_roles: List[RoleId], + display_name: ResourceDisplayName, + organization_rids: List[OrganizationRid], + role_grants: Dict[RoleId, List[PrincipalWithIdDict]], + space_rid: SpaceRid, + description: Optional[str] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Project]: + """ + Creates a project. + :param default_roles: + :type default_roles: List[RoleId] + :param display_name: + :type display_name: ResourceDisplayName + :param organization_rids: + :type organization_rids: List[OrganizationRid] + :param role_grants: + :type role_grants: Dict[RoleId, List[PrincipalWithIdDict]] + :param space_rid: + :type space_rid: SpaceRid + :param description: + :type description: Optional[str] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Project] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/filesystem/projects/create", + query_params={ + "preview": preview, + }, + path_params={}, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "displayName": display_name, + "description": description, + "spaceRid": space_rid, + "roleGrants": role_grants, + "defaultRoles": default_roles, + "organizationRids": organization_rids, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "displayName": ResourceDisplayName, + "description": Optional[str], + "spaceRid": SpaceRid, + "roleGrants": Dict[RoleId, List[PrincipalWithIdDict]], + "defaultRoles": List[RoleId], + "organizationRids": List[OrganizationRid], + }, + ), + response_type=Project, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + project_rid: ProjectRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Project]: + """ + Get the Project with the specified rid. + :param project_rid: projectRid + :type project_rid: ProjectRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Project] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/filesystem/projects/{projectRid}", + query_params={ + "preview": preview, + }, + path_params={ + "projectRid": project_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Project, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def organizations( + self, + project_rid: ProjectRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListOrganizationsOfProjectResponse]: + """ + List of Organizations directly applied to a Project. The number of Organizations on a Project is + typically small so the `pageSize` and `pageToken` parameters are not required. + + :param project_rid: projectRid + :type project_rid: ProjectRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListOrganizationsOfProjectResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/filesystem/projects/{projectRid}/organizations", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "projectRid": project_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListOrganizationsOfProjectResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def organizations_page( + self, + project_rid: ProjectRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListOrganizationsOfProjectResponse]: + """ + List of Organizations directly applied to a Project. The number of Organizations on a Project is + typically small so the `pageSize` and `pageToken` parameters are not required. + + :param project_rid: projectRid + :type project_rid: ProjectRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListOrganizationsOfProjectResponse] + """ + + warnings.warn( + "The client.filesystem.Project.organizations_page(...) method has been deprecated. Please use client.filesystem.Project.organizations(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/filesystem/projects/{projectRid}/organizations", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "projectRid": project_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListOrganizationsOfProjectResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def remove_organizations( + self, + project_rid: ProjectRid, + *, + organization_rids: List[OrganizationRid], + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[None]: + """ + Removes Organizations from a Project. + :param project_rid: projectRid + :type project_rid: ProjectRid + :param organization_rids: + :type organization_rids: List[OrganizationRid] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[None] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/filesystem/projects/{projectRid}/removeOrganizations", + query_params={ + "preview": preview, + }, + path_params={ + "projectRid": project_rid, + }, + header_params={ + "Content-Type": "application/json", + }, + body={ + "organizationRids": organization_rids, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "organizationRids": List[OrganizationRid], + }, + ), + response_type=None, + request_timeout=request_timeout, + ), + ) + + +class _ProjectClientStreaming: + """ + The API client for the Project Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def add_organizations( + self, + project_rid: ProjectRid, + *, + organization_rids: List[OrganizationRid], + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[None]: + """ + Adds a list of Organizations to a Project. + :param project_rid: projectRid + :type project_rid: ProjectRid + :param organization_rids: + :type organization_rids: List[OrganizationRid] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[None] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/filesystem/projects/{projectRid}/addOrganizations", + query_params={ + "preview": preview, + }, + path_params={ + "projectRid": project_rid, + }, + header_params={ + "Content-Type": "application/json", + }, + body={ + "organizationRids": organization_rids, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "organizationRids": List[OrganizationRid], + }, + ), + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def create( + self, + *, + default_roles: List[RoleId], + display_name: ResourceDisplayName, + organization_rids: List[OrganizationRid], + role_grants: Dict[RoleId, List[PrincipalWithIdDict]], + space_rid: SpaceRid, + description: Optional[str] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Project]: + """ + Creates a project. + :param default_roles: + :type default_roles: List[RoleId] + :param display_name: + :type display_name: ResourceDisplayName + :param organization_rids: + :type organization_rids: List[OrganizationRid] + :param role_grants: + :type role_grants: Dict[RoleId, List[PrincipalWithIdDict]] + :param space_rid: + :type space_rid: SpaceRid + :param description: + :type description: Optional[str] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Project] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/filesystem/projects/create", + query_params={ + "preview": preview, + }, + path_params={}, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "displayName": display_name, + "description": description, + "spaceRid": space_rid, + "roleGrants": role_grants, + "defaultRoles": default_roles, + "organizationRids": organization_rids, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "displayName": ResourceDisplayName, + "description": Optional[str], + "spaceRid": SpaceRid, + "roleGrants": Dict[RoleId, List[PrincipalWithIdDict]], + "defaultRoles": List[RoleId], + "organizationRids": List[OrganizationRid], + }, + ), + response_type=Project, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + project_rid: ProjectRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Project]: + """ + Get the Project with the specified rid. + :param project_rid: projectRid + :type project_rid: ProjectRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Project] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/filesystem/projects/{projectRid}", + query_params={ + "preview": preview, + }, + path_params={ + "projectRid": project_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Project, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def organizations( + self, + project_rid: ProjectRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListOrganizationsOfProjectResponse]: + """ + List of Organizations directly applied to a Project. The number of Organizations on a Project is + typically small so the `pageSize` and `pageToken` parameters are not required. + + :param project_rid: projectRid + :type project_rid: ProjectRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListOrganizationsOfProjectResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/filesystem/projects/{projectRid}/organizations", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "projectRid": project_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListOrganizationsOfProjectResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def organizations_page( + self, + project_rid: ProjectRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListOrganizationsOfProjectResponse]: + """ + List of Organizations directly applied to a Project. The number of Organizations on a Project is + typically small so the `pageSize` and `pageToken` parameters are not required. + + :param project_rid: projectRid + :type project_rid: ProjectRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListOrganizationsOfProjectResponse] + """ + + warnings.warn( + "The client.filesystem.Project.organizations_page(...) method has been deprecated. Please use client.filesystem.Project.organizations(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/filesystem/projects/{projectRid}/organizations", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "projectRid": project_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListOrganizationsOfProjectResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def remove_organizations( + self, + project_rid: ProjectRid, + *, + organization_rids: List[OrganizationRid], + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[None]: + """ + Removes Organizations from a Project. + :param project_rid: projectRid + :type project_rid: ProjectRid + :param organization_rids: + :type organization_rids: List[OrganizationRid] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[None] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/filesystem/projects/{projectRid}/removeOrganizations", + query_params={ + "preview": preview, + }, + path_params={ + "projectRid": project_rid, + }, + header_params={ + "Content-Type": "application/json", + }, + body={ + "organizationRids": organization_rids, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "organizationRids": List[OrganizationRid], + }, + ), + response_type=None, + request_timeout=request_timeout, + ), ) diff --git a/foundry/v2/filesystem/resource.py b/foundry/v2/filesystem/resource.py index a9539c7e..2ed6f323 100644 --- a/foundry/v2/filesystem/resource.py +++ b/foundry/v2/filesystem/resource.py @@ -26,10 +26,12 @@ from typing_extensions import TypedDict from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo from foundry._core import ResourceIterator +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.core.models._marking_id import MarkingId @@ -51,7 +53,7 @@ class ResourceClient: The API client for the Resource Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -62,6 +64,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _ResourceClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _ResourceClientRaw(auth=auth, hostname=hostname, config=config) self.ResourceRole = ResourceRoleClient(auth=auth, hostname=hostname, config=config) @maybe_ignore_preview @@ -114,7 +120,7 @@ def add_markings( response_type=None, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -156,7 +162,7 @@ def delete( response_type=None, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -198,7 +204,7 @@ def get( response_type=Resource, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -242,7 +248,7 @@ def get_access_requirements( response_type=AccessRequirements, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -283,7 +289,7 @@ def get_by_path( response_type=Resource, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -368,8 +374,9 @@ def markings_page( """ warnings.warn( - "The ResourceClient.markingsPage(...) method has been deprecated. Please use ResourceClient.markings(...) instead.", + "The client.filesystem.Resource.markings_page(...) method has been deprecated. Please use client.filesystem.Resource.markings(...) instead.", DeprecationWarning, + stacklevel=2, ) return self._api_client.call_api( @@ -392,7 +399,7 @@ def markings_page( response_type=ListMarkingsOfResourceResponse, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -434,7 +441,7 @@ def permanently_delete( response_type=None, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -486,7 +493,7 @@ def remove_markings( response_type=None, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -528,4 +535,974 @@ def restore( response_type=None, request_timeout=request_timeout, ), + ).decode() + + +class _ResourceClientRaw: + """ + The API client for the Resource Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def add_markings( + self, + resource_rid: ResourceRid, + *, + marking_ids: List[MarkingId], + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[None]: + """ + Adds a list of Markings to a resource. + :param resource_rid: resourceRid + :type resource_rid: ResourceRid + :param marking_ids: + :type marking_ids: List[MarkingId] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[None] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/filesystem/resources/{resourceRid}/addMarkings", + query_params={ + "preview": preview, + }, + path_params={ + "resourceRid": resource_rid, + }, + header_params={ + "Content-Type": "application/json", + }, + body={ + "markingIds": marking_ids, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "markingIds": List[MarkingId], + }, + ), + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def delete( + self, + resource_rid: ResourceRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[None]: + """ + Move the given resource to the trash. Following this operation, the resource can be restored, using the + `restore` operation, or permanently deleted using the `permanentlyDelete` operation. + + :param resource_rid: resourceRid + :type resource_rid: ResourceRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[None] + """ + + return self._api_client.call_api( + RequestInfo( + method="DELETE", + resource_path="/v2/filesystem/resources/{resourceRid}", + query_params={ + "preview": preview, + }, + path_params={ + "resourceRid": resource_rid, + }, + header_params={}, + body=None, + body_type=None, + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + resource_rid: ResourceRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Resource]: + """ + Get the Resource with the specified rid. + :param resource_rid: resourceRid + :type resource_rid: ResourceRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Resource] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/filesystem/resources/{resourceRid}", + query_params={ + "preview": preview, + }, + path_params={ + "resourceRid": resource_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Resource, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get_access_requirements( + self, + resource_rid: ResourceRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[AccessRequirements]: + """ + Returns a list of access requirements a user needs in order to view a resource. Access requirements are + composed of Organizations and Markings, and can either be applied directly to the resource or inherited. + + :param resource_rid: resourceRid + :type resource_rid: ResourceRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[AccessRequirements] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/filesystem/resources/{resourceRid}/getAccessRequirements", + query_params={ + "preview": preview, + }, + path_params={ + "resourceRid": resource_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=AccessRequirements, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get_by_path( + self, + *, + path: ResourcePath, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Resource]: + """ + Get a Resource by its absolute path. + :param path: path + :type path: ResourcePath + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Resource] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/filesystem/resources/getByPath", + query_params={ + "path": path, + "preview": preview, + }, + path_params={}, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Resource, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def markings( + self, + resource_rid: ResourceRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListMarkingsOfResourceResponse]: + """ + List of Markings directly applied to a resource. The number of Markings on a resource is typically small + so the `pageSize` and `pageToken` parameters are not required. + + :param resource_rid: resourceRid + :type resource_rid: ResourceRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListMarkingsOfResourceResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/filesystem/resources/{resourceRid}/markings", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "resourceRid": resource_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListMarkingsOfResourceResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def markings_page( + self, + resource_rid: ResourceRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListMarkingsOfResourceResponse]: + """ + List of Markings directly applied to a resource. The number of Markings on a resource is typically small + so the `pageSize` and `pageToken` parameters are not required. + + :param resource_rid: resourceRid + :type resource_rid: ResourceRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListMarkingsOfResourceResponse] + """ + + warnings.warn( + "The client.filesystem.Resource.markings_page(...) method has been deprecated. Please use client.filesystem.Resource.markings(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/filesystem/resources/{resourceRid}/markings", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "resourceRid": resource_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListMarkingsOfResourceResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def permanently_delete( + self, + resource_rid: ResourceRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[None]: + """ + Permanently delete the given resource from the trash. If the Resource is not directly trashed, a + `ResourceNotTrashed` error will be thrown. + + :param resource_rid: resourceRid + :type resource_rid: ResourceRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[None] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/filesystem/resources/{resourceRid}/permanentlyDelete", + query_params={ + "preview": preview, + }, + path_params={ + "resourceRid": resource_rid, + }, + header_params={}, + body=None, + body_type=None, + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def remove_markings( + self, + resource_rid: ResourceRid, + *, + marking_ids: List[MarkingId], + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[None]: + """ + Removes Markings from a resource. + :param resource_rid: resourceRid + :type resource_rid: ResourceRid + :param marking_ids: + :type marking_ids: List[MarkingId] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[None] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/filesystem/resources/{resourceRid}/removeMarkings", + query_params={ + "preview": preview, + }, + path_params={ + "resourceRid": resource_rid, + }, + header_params={ + "Content-Type": "application/json", + }, + body={ + "markingIds": marking_ids, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "markingIds": List[MarkingId], + }, + ), + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def restore( + self, + resource_rid: ResourceRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[None]: + """ + Restore the given resource and any directly trashed ancestors from the trash. If the resource is not + trashed, this operation will be ignored. + + :param resource_rid: resourceRid + :type resource_rid: ResourceRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[None] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/filesystem/resources/{resourceRid}/restore", + query_params={ + "preview": preview, + }, + path_params={ + "resourceRid": resource_rid, + }, + header_params={}, + body=None, + body_type=None, + response_type=None, + request_timeout=request_timeout, + ), + ) + + +class _ResourceClientStreaming: + """ + The API client for the Resource Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def add_markings( + self, + resource_rid: ResourceRid, + *, + marking_ids: List[MarkingId], + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[None]: + """ + Adds a list of Markings to a resource. + :param resource_rid: resourceRid + :type resource_rid: ResourceRid + :param marking_ids: + :type marking_ids: List[MarkingId] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[None] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/filesystem/resources/{resourceRid}/addMarkings", + query_params={ + "preview": preview, + }, + path_params={ + "resourceRid": resource_rid, + }, + header_params={ + "Content-Type": "application/json", + }, + body={ + "markingIds": marking_ids, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "markingIds": List[MarkingId], + }, + ), + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def delete( + self, + resource_rid: ResourceRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[None]: + """ + Move the given resource to the trash. Following this operation, the resource can be restored, using the + `restore` operation, or permanently deleted using the `permanentlyDelete` operation. + + :param resource_rid: resourceRid + :type resource_rid: ResourceRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[None] + """ + + return self._api_client.stream_api( + RequestInfo( + method="DELETE", + resource_path="/v2/filesystem/resources/{resourceRid}", + query_params={ + "preview": preview, + }, + path_params={ + "resourceRid": resource_rid, + }, + header_params={}, + body=None, + body_type=None, + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + resource_rid: ResourceRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Resource]: + """ + Get the Resource with the specified rid. + :param resource_rid: resourceRid + :type resource_rid: ResourceRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Resource] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/filesystem/resources/{resourceRid}", + query_params={ + "preview": preview, + }, + path_params={ + "resourceRid": resource_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Resource, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get_access_requirements( + self, + resource_rid: ResourceRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[AccessRequirements]: + """ + Returns a list of access requirements a user needs in order to view a resource. Access requirements are + composed of Organizations and Markings, and can either be applied directly to the resource or inherited. + + :param resource_rid: resourceRid + :type resource_rid: ResourceRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[AccessRequirements] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/filesystem/resources/{resourceRid}/getAccessRequirements", + query_params={ + "preview": preview, + }, + path_params={ + "resourceRid": resource_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=AccessRequirements, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get_by_path( + self, + *, + path: ResourcePath, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Resource]: + """ + Get a Resource by its absolute path. + :param path: path + :type path: ResourcePath + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Resource] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/filesystem/resources/getByPath", + query_params={ + "path": path, + "preview": preview, + }, + path_params={}, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Resource, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def markings( + self, + resource_rid: ResourceRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListMarkingsOfResourceResponse]: + """ + List of Markings directly applied to a resource. The number of Markings on a resource is typically small + so the `pageSize` and `pageToken` parameters are not required. + + :param resource_rid: resourceRid + :type resource_rid: ResourceRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListMarkingsOfResourceResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/filesystem/resources/{resourceRid}/markings", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "resourceRid": resource_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListMarkingsOfResourceResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def markings_page( + self, + resource_rid: ResourceRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListMarkingsOfResourceResponse]: + """ + List of Markings directly applied to a resource. The number of Markings on a resource is typically small + so the `pageSize` and `pageToken` parameters are not required. + + :param resource_rid: resourceRid + :type resource_rid: ResourceRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListMarkingsOfResourceResponse] + """ + + warnings.warn( + "The client.filesystem.Resource.markings_page(...) method has been deprecated. Please use client.filesystem.Resource.markings(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/filesystem/resources/{resourceRid}/markings", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "resourceRid": resource_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListMarkingsOfResourceResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def permanently_delete( + self, + resource_rid: ResourceRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[None]: + """ + Permanently delete the given resource from the trash. If the Resource is not directly trashed, a + `ResourceNotTrashed` error will be thrown. + + :param resource_rid: resourceRid + :type resource_rid: ResourceRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[None] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/filesystem/resources/{resourceRid}/permanentlyDelete", + query_params={ + "preview": preview, + }, + path_params={ + "resourceRid": resource_rid, + }, + header_params={}, + body=None, + body_type=None, + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def remove_markings( + self, + resource_rid: ResourceRid, + *, + marking_ids: List[MarkingId], + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[None]: + """ + Removes Markings from a resource. + :param resource_rid: resourceRid + :type resource_rid: ResourceRid + :param marking_ids: + :type marking_ids: List[MarkingId] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[None] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/filesystem/resources/{resourceRid}/removeMarkings", + query_params={ + "preview": preview, + }, + path_params={ + "resourceRid": resource_rid, + }, + header_params={ + "Content-Type": "application/json", + }, + body={ + "markingIds": marking_ids, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "markingIds": List[MarkingId], + }, + ), + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def restore( + self, + resource_rid: ResourceRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[None]: + """ + Restore the given resource and any directly trashed ancestors from the trash. If the resource is not + trashed, this operation will be ignored. + + :param resource_rid: resourceRid + :type resource_rid: ResourceRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[None] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/filesystem/resources/{resourceRid}/restore", + query_params={ + "preview": preview, + }, + path_params={ + "resourceRid": resource_rid, + }, + header_params={}, + body=None, + body_type=None, + response_type=None, + request_timeout=request_timeout, + ), ) diff --git a/foundry/v2/filesystem/resource_role.py b/foundry/v2/filesystem/resource_role.py index 33cad173..927f31d3 100644 --- a/foundry/v2/filesystem/resource_role.py +++ b/foundry/v2/filesystem/resource_role.py @@ -26,10 +26,12 @@ from typing_extensions import TypedDict from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo from foundry._core import ResourceIterator +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.core.models._page_size import PageSize @@ -48,7 +50,7 @@ class ResourceRoleClient: The API client for the ResourceRole Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -59,6 +61,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _ResourceRoleClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _ResourceRoleClientRaw(auth=auth, hostname=hostname, config=config) @maybe_ignore_preview @pydantic.validate_call @@ -110,7 +116,7 @@ def add( response_type=None, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -200,8 +206,9 @@ def page( """ warnings.warn( - "The ResourceRoleClient.page(...) method has been deprecated. Please use ResourceRoleClient.list(...) instead.", + "The client.filesystem.ResourceRole.page(...) method has been deprecated. Please use client.filesystem.ResourceRole.list(...) instead.", DeprecationWarning, + stacklevel=2, ) return self._api_client.call_api( @@ -225,7 +232,7 @@ def page( response_type=ListResourceRolesResponse, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -277,4 +284,480 @@ def remove( response_type=None, request_timeout=request_timeout, ), + ).decode() + + +class _ResourceRoleClientRaw: + """ + The API client for the ResourceRole Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def add( + self, + resource_rid: ResourceRid, + *, + roles: List[ResourceRoleDict], + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[None]: + """ + + :param resource_rid: resourceRid + :type resource_rid: ResourceRid + :param roles: + :type roles: List[ResourceRoleDict] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[None] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/filesystem/resources/{resourceRid}/roles/add", + query_params={ + "preview": preview, + }, + path_params={ + "resourceRid": resource_rid, + }, + header_params={ + "Content-Type": "application/json", + }, + body={ + "roles": roles, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "roles": List[ResourceRoleDict], + }, + ), + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + resource_rid: ResourceRid, + *, + include_inherited: Optional[bool] = None, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListResourceRolesResponse]: + """ + List the roles on a resource. + + :param resource_rid: resourceRid + :type resource_rid: ResourceRid + :param include_inherited: includeInherited + :type include_inherited: Optional[bool] + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListResourceRolesResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/filesystem/resources/{resourceRid}/roles", + query_params={ + "includeInherited": include_inherited, + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "resourceRid": resource_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListResourceRolesResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + resource_rid: ResourceRid, + *, + include_inherited: Optional[bool] = None, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListResourceRolesResponse]: + """ + List the roles on a resource. + + :param resource_rid: resourceRid + :type resource_rid: ResourceRid + :param include_inherited: includeInherited + :type include_inherited: Optional[bool] + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListResourceRolesResponse] + """ + + warnings.warn( + "The client.filesystem.ResourceRole.page(...) method has been deprecated. Please use client.filesystem.ResourceRole.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/filesystem/resources/{resourceRid}/roles", + query_params={ + "includeInherited": include_inherited, + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "resourceRid": resource_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListResourceRolesResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def remove( + self, + resource_rid: ResourceRid, + *, + roles: List[ResourceRoleDict], + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[None]: + """ + + :param resource_rid: resourceRid + :type resource_rid: ResourceRid + :param roles: + :type roles: List[ResourceRoleDict] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[None] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/filesystem/resources/{resourceRid}/roles/remove", + query_params={ + "preview": preview, + }, + path_params={ + "resourceRid": resource_rid, + }, + header_params={ + "Content-Type": "application/json", + }, + body={ + "roles": roles, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "roles": List[ResourceRoleDict], + }, + ), + response_type=None, + request_timeout=request_timeout, + ), + ) + + +class _ResourceRoleClientStreaming: + """ + The API client for the ResourceRole Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def add( + self, + resource_rid: ResourceRid, + *, + roles: List[ResourceRoleDict], + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[None]: + """ + + :param resource_rid: resourceRid + :type resource_rid: ResourceRid + :param roles: + :type roles: List[ResourceRoleDict] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[None] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/filesystem/resources/{resourceRid}/roles/add", + query_params={ + "preview": preview, + }, + path_params={ + "resourceRid": resource_rid, + }, + header_params={ + "Content-Type": "application/json", + }, + body={ + "roles": roles, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "roles": List[ResourceRoleDict], + }, + ), + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + resource_rid: ResourceRid, + *, + include_inherited: Optional[bool] = None, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListResourceRolesResponse]: + """ + List the roles on a resource. + + :param resource_rid: resourceRid + :type resource_rid: ResourceRid + :param include_inherited: includeInherited + :type include_inherited: Optional[bool] + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListResourceRolesResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/filesystem/resources/{resourceRid}/roles", + query_params={ + "includeInherited": include_inherited, + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "resourceRid": resource_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListResourceRolesResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + resource_rid: ResourceRid, + *, + include_inherited: Optional[bool] = None, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListResourceRolesResponse]: + """ + List the roles on a resource. + + :param resource_rid: resourceRid + :type resource_rid: ResourceRid + :param include_inherited: includeInherited + :type include_inherited: Optional[bool] + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListResourceRolesResponse] + """ + + warnings.warn( + "The client.filesystem.ResourceRole.page(...) method has been deprecated. Please use client.filesystem.ResourceRole.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/filesystem/resources/{resourceRid}/roles", + query_params={ + "includeInherited": include_inherited, + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "resourceRid": resource_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListResourceRolesResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def remove( + self, + resource_rid: ResourceRid, + *, + roles: List[ResourceRoleDict], + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[None]: + """ + + :param resource_rid: resourceRid + :type resource_rid: ResourceRid + :param roles: + :type roles: List[ResourceRoleDict] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[None] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/filesystem/resources/{resourceRid}/roles/remove", + query_params={ + "preview": preview, + }, + path_params={ + "resourceRid": resource_rid, + }, + header_params={ + "Content-Type": "application/json", + }, + body={ + "roles": roles, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "roles": List[ResourceRoleDict], + }, + ), + response_type=None, + request_timeout=request_timeout, + ), ) diff --git a/foundry/v2/functions/client.py b/foundry/v2/functions/client.py index 944501a3..3e57283c 100644 --- a/foundry/v2/functions/client.py +++ b/foundry/v2/functions/client.py @@ -28,7 +28,7 @@ class FunctionsClient: The API client for the Functions Namespace. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ diff --git a/foundry/v2/functions/query.py b/foundry/v2/functions/query.py index 6a6fe44f..1b7b370f 100644 --- a/foundry/v2/functions/query.py +++ b/foundry/v2/functions/query.py @@ -24,9 +24,11 @@ from typing_extensions import TypedDict from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.core.models._preview_mode import PreviewMode @@ -43,7 +45,7 @@ class QueryClient: The API client for the Query Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -54,6 +56,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _QueryClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _QueryClientRaw(auth=auth, hostname=hostname, config=config) @maybe_ignore_preview @pydantic.validate_call @@ -109,7 +115,7 @@ def execute( response_type=ExecuteQueryResponse, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -152,7 +158,7 @@ def get( response_type=Query, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -201,4 +207,336 @@ def get_by_rid( response_type=Query, request_timeout=request_timeout, ), + ).decode() + + +class _QueryClientRaw: + """ + The API client for the Query Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def execute( + self, + query_api_name: QueryApiName, + *, + parameters: Dict[ParameterId, Optional[DataValue]], + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ExecuteQueryResponse]: + """ + Executes a Query using the given parameters. + + Optional parameters do not need to be supplied. + + :param query_api_name: queryApiName + :type query_api_name: QueryApiName + :param parameters: + :type parameters: Dict[ParameterId, Optional[DataValue]] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ExecuteQueryResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/functions/queries/{queryApiName}/execute", + query_params={ + "preview": preview, + }, + path_params={ + "queryApiName": query_api_name, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "parameters": parameters, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "parameters": Dict[ParameterId, Optional[DataValue]], + }, + ), + response_type=ExecuteQueryResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + query_api_name: QueryApiName, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Query]: + """ + Gets a specific query type with the given API name. + + :param query_api_name: queryApiName + :type query_api_name: QueryApiName + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Query] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/functions/queries/{queryApiName}", + query_params={ + "preview": preview, + }, + path_params={ + "queryApiName": query_api_name, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Query, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get_by_rid( + self, + *, + rid: FunctionRid, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Query]: + """ + Gets a specific query type with the given RID. + + :param rid: + :type rid: FunctionRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Query] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/functions/queries/getByRid", + query_params={ + "preview": preview, + }, + path_params={}, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "rid": rid, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "rid": FunctionRid, + }, + ), + response_type=Query, + request_timeout=request_timeout, + ), + ) + + +class _QueryClientStreaming: + """ + The API client for the Query Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def execute( + self, + query_api_name: QueryApiName, + *, + parameters: Dict[ParameterId, Optional[DataValue]], + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ExecuteQueryResponse]: + """ + Executes a Query using the given parameters. + + Optional parameters do not need to be supplied. + + :param query_api_name: queryApiName + :type query_api_name: QueryApiName + :param parameters: + :type parameters: Dict[ParameterId, Optional[DataValue]] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ExecuteQueryResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/functions/queries/{queryApiName}/execute", + query_params={ + "preview": preview, + }, + path_params={ + "queryApiName": query_api_name, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "parameters": parameters, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "parameters": Dict[ParameterId, Optional[DataValue]], + }, + ), + response_type=ExecuteQueryResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + query_api_name: QueryApiName, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Query]: + """ + Gets a specific query type with the given API name. + + :param query_api_name: queryApiName + :type query_api_name: QueryApiName + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Query] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/functions/queries/{queryApiName}", + query_params={ + "preview": preview, + }, + path_params={ + "queryApiName": query_api_name, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Query, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get_by_rid( + self, + *, + rid: FunctionRid, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Query]: + """ + Gets a specific query type with the given RID. + + :param rid: + :type rid: FunctionRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Query] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/functions/queries/getByRid", + query_params={ + "preview": preview, + }, + path_params={}, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "rid": rid, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "rid": FunctionRid, + }, + ), + response_type=Query, + request_timeout=request_timeout, + ), ) diff --git a/foundry/v2/functions/value_type.py b/foundry/v2/functions/value_type.py index fab11044..7638f20c 100644 --- a/foundry/v2/functions/value_type.py +++ b/foundry/v2/functions/value_type.py @@ -23,9 +23,11 @@ from typing_extensions import Annotated from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.core.models._preview_mode import PreviewMode @@ -39,7 +41,7 @@ class ValueTypeClient: The API client for the ValueType Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -50,6 +52,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _ValueTypeClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _ValueTypeClientRaw(auth=auth, hostname=hostname, config=config) self.VersionId = VersionIdClient(auth=auth, hostname=hostname, config=config) @maybe_ignore_preview @@ -93,4 +99,126 @@ def get( response_type=ValueType, request_timeout=request_timeout, ), + ).decode() + + +class _ValueTypeClientRaw: + """ + The API client for the ValueType Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + value_type_rid: ValueTypeRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ValueType]: + """ + Gets a specific value type with the given RID. The latest version is returned. + + :param value_type_rid: valueTypeRid + :type value_type_rid: ValueTypeRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ValueType] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/functions/valueTypes/{valueTypeRid}", + query_params={ + "preview": preview, + }, + path_params={ + "valueTypeRid": value_type_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ValueType, + request_timeout=request_timeout, + ), + ) + + +class _ValueTypeClientStreaming: + """ + The API client for the ValueType Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + value_type_rid: ValueTypeRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ValueType]: + """ + Gets a specific value type with the given RID. The latest version is returned. + + :param value_type_rid: valueTypeRid + :type value_type_rid: ValueTypeRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ValueType] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/functions/valueTypes/{valueTypeRid}", + query_params={ + "preview": preview, + }, + path_params={ + "valueTypeRid": value_type_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ValueType, + request_timeout=request_timeout, + ), ) diff --git a/foundry/v2/functions/version_id.py b/foundry/v2/functions/version_id.py index 02c1215a..81b97658 100644 --- a/foundry/v2/functions/version_id.py +++ b/foundry/v2/functions/version_id.py @@ -23,9 +23,11 @@ from typing_extensions import Annotated from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.core.models._preview_mode import PreviewMode @@ -39,7 +41,7 @@ class VersionIdClient: The API client for the VersionId Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -50,6 +52,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _VersionIdClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _VersionIdClientRaw(auth=auth, hostname=hostname, config=config) @maybe_ignore_preview @pydantic.validate_call @@ -96,4 +102,134 @@ def get( response_type=VersionId, request_timeout=request_timeout, ), + ).decode() + + +class _VersionIdClientRaw: + """ + The API client for the VersionId Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + value_type_rid: ValueTypeRid, + version_id_version_id: ValueTypeVersionId, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[VersionId]: + """ + Gets a specific value type with the given RID. The specified version is returned. + + :param value_type_rid: valueTypeRid + :type value_type_rid: ValueTypeRid + :param version_id_version_id: versionIdVersionId + :type version_id_version_id: ValueTypeVersionId + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[VersionId] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/functions/valueTypes/{valueTypeRid}/versionIds/{versionIdVersionId}", + query_params={ + "preview": preview, + }, + path_params={ + "valueTypeRid": value_type_rid, + "versionIdVersionId": version_id_version_id, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=VersionId, + request_timeout=request_timeout, + ), + ) + + +class _VersionIdClientStreaming: + """ + The API client for the VersionId Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + value_type_rid: ValueTypeRid, + version_id_version_id: ValueTypeVersionId, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[VersionId]: + """ + Gets a specific value type with the given RID. The specified version is returned. + + :param value_type_rid: valueTypeRid + :type value_type_rid: ValueTypeRid + :param version_id_version_id: versionIdVersionId + :type version_id_version_id: ValueTypeVersionId + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[VersionId] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/functions/valueTypes/{valueTypeRid}/versionIds/{versionIdVersionId}", + query_params={ + "preview": preview, + }, + path_params={ + "valueTypeRid": value_type_rid, + "versionIdVersionId": version_id_version_id, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=VersionId, + request_timeout=request_timeout, + ), ) diff --git a/foundry/v2/ontologies/action.py b/foundry/v2/ontologies/action.py index f9fbdbdb..99d815f1 100644 --- a/foundry/v2/ontologies/action.py +++ b/foundry/v2/ontologies/action.py @@ -25,9 +25,11 @@ from typing_extensions import TypedDict from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.ontologies.models._action_type_api_name import ActionTypeApiName @@ -58,7 +60,7 @@ class ActionClient: The API client for the Action Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -69,6 +71,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _ActionClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _ActionClientRaw(auth=auth, hostname=hostname, config=config) @maybe_ignore_preview @pydantic.validate_call @@ -143,7 +149,7 @@ def apply( response_type=SyncApplyActionResponseV2, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -219,4 +225,342 @@ def apply_batch( response_type=BatchApplyActionResponseV2, request_timeout=request_timeout, ), + ).decode() + + +class _ActionClientRaw: + """ + The API client for the Action Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def apply( + self, + ontology: OntologyIdentifier, + action: ActionTypeApiName, + *, + parameters: Dict[ParameterId, Optional[DataValue]], + artifact_repository: Optional[ArtifactRepositoryRid] = None, + options: Optional[ApplyActionRequestOptionsDict] = None, + package_name: Optional[SdkPackageName] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[SyncApplyActionResponseV2]: + """ + Applies an action using the given parameters. + + Changes to the Ontology are eventually consistent and may take some time to be visible. + + Note that [parameter default values](/docs/foundry/action-types/parameters-default-value/) are not currently supported by + this endpoint. + + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-read api:ontologies-write`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param action: action + :type action: ActionTypeApiName + :param parameters: + :type parameters: Dict[ParameterId, Optional[DataValue]] + :param artifact_repository: artifactRepository + :type artifact_repository: Optional[ArtifactRepositoryRid] + :param options: + :type options: Optional[ApplyActionRequestOptionsDict] + :param package_name: packageName + :type package_name: Optional[SdkPackageName] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[SyncApplyActionResponseV2] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/ontologies/{ontology}/actions/{action}/apply", + query_params={ + "artifactRepository": artifact_repository, + "packageName": package_name, + }, + path_params={ + "ontology": ontology, + "action": action, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "options": options, + "parameters": parameters, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "options": Optional[ApplyActionRequestOptionsDict], + "parameters": Dict[ParameterId, Optional[DataValue]], + }, + ), + response_type=SyncApplyActionResponseV2, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def apply_batch( + self, + ontology: OntologyIdentifier, + action: ActionTypeApiName, + *, + requests: List[BatchApplyActionRequestItemDict], + artifact_repository: Optional[ArtifactRepositoryRid] = None, + options: Optional[BatchApplyActionRequestOptionsDict] = None, + package_name: Optional[SdkPackageName] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[BatchApplyActionResponseV2]: + """ + Applies multiple actions (of the same Action Type) using the given parameters. + Changes to the Ontology are eventually consistent and may take some time to be visible. + + Up to 20 actions may be applied in one call. Actions that only modify objects in Object Storage v2 and do not + call Functions may receive a higher limit. + + Note that [notifications](/docs/foundry/action-types/notifications/) are not currently supported by this endpoint. + + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-read api:ontologies-write`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param action: action + :type action: ActionTypeApiName + :param requests: + :type requests: List[BatchApplyActionRequestItemDict] + :param artifact_repository: artifactRepository + :type artifact_repository: Optional[ArtifactRepositoryRid] + :param options: + :type options: Optional[BatchApplyActionRequestOptionsDict] + :param package_name: packageName + :type package_name: Optional[SdkPackageName] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[BatchApplyActionResponseV2] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/ontologies/{ontology}/actions/{action}/applyBatch", + query_params={ + "artifactRepository": artifact_repository, + "packageName": package_name, + }, + path_params={ + "ontology": ontology, + "action": action, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "options": options, + "requests": requests, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "options": Optional[BatchApplyActionRequestOptionsDict], + "requests": List[BatchApplyActionRequestItemDict], + }, + ), + response_type=BatchApplyActionResponseV2, + request_timeout=request_timeout, + ), + ) + + +class _ActionClientStreaming: + """ + The API client for the Action Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def apply( + self, + ontology: OntologyIdentifier, + action: ActionTypeApiName, + *, + parameters: Dict[ParameterId, Optional[DataValue]], + artifact_repository: Optional[ArtifactRepositoryRid] = None, + options: Optional[ApplyActionRequestOptionsDict] = None, + package_name: Optional[SdkPackageName] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[SyncApplyActionResponseV2]: + """ + Applies an action using the given parameters. + + Changes to the Ontology are eventually consistent and may take some time to be visible. + + Note that [parameter default values](/docs/foundry/action-types/parameters-default-value/) are not currently supported by + this endpoint. + + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-read api:ontologies-write`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param action: action + :type action: ActionTypeApiName + :param parameters: + :type parameters: Dict[ParameterId, Optional[DataValue]] + :param artifact_repository: artifactRepository + :type artifact_repository: Optional[ArtifactRepositoryRid] + :param options: + :type options: Optional[ApplyActionRequestOptionsDict] + :param package_name: packageName + :type package_name: Optional[SdkPackageName] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[SyncApplyActionResponseV2] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/ontologies/{ontology}/actions/{action}/apply", + query_params={ + "artifactRepository": artifact_repository, + "packageName": package_name, + }, + path_params={ + "ontology": ontology, + "action": action, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "options": options, + "parameters": parameters, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "options": Optional[ApplyActionRequestOptionsDict], + "parameters": Dict[ParameterId, Optional[DataValue]], + }, + ), + response_type=SyncApplyActionResponseV2, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def apply_batch( + self, + ontology: OntologyIdentifier, + action: ActionTypeApiName, + *, + requests: List[BatchApplyActionRequestItemDict], + artifact_repository: Optional[ArtifactRepositoryRid] = None, + options: Optional[BatchApplyActionRequestOptionsDict] = None, + package_name: Optional[SdkPackageName] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[BatchApplyActionResponseV2]: + """ + Applies multiple actions (of the same Action Type) using the given parameters. + Changes to the Ontology are eventually consistent and may take some time to be visible. + + Up to 20 actions may be applied in one call. Actions that only modify objects in Object Storage v2 and do not + call Functions may receive a higher limit. + + Note that [notifications](/docs/foundry/action-types/notifications/) are not currently supported by this endpoint. + + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-read api:ontologies-write`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param action: action + :type action: ActionTypeApiName + :param requests: + :type requests: List[BatchApplyActionRequestItemDict] + :param artifact_repository: artifactRepository + :type artifact_repository: Optional[ArtifactRepositoryRid] + :param options: + :type options: Optional[BatchApplyActionRequestOptionsDict] + :param package_name: packageName + :type package_name: Optional[SdkPackageName] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[BatchApplyActionResponseV2] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/ontologies/{ontology}/actions/{action}/applyBatch", + query_params={ + "artifactRepository": artifact_repository, + "packageName": package_name, + }, + path_params={ + "ontology": ontology, + "action": action, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "options": options, + "requests": requests, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "options": Optional[BatchApplyActionRequestOptionsDict], + "requests": List[BatchApplyActionRequestItemDict], + }, + ), + response_type=BatchApplyActionResponseV2, + request_timeout=request_timeout, + ), ) diff --git a/foundry/v2/ontologies/action_type.py b/foundry/v2/ontologies/action_type.py index 5e7f412e..ee7ef370 100644 --- a/foundry/v2/ontologies/action_type.py +++ b/foundry/v2/ontologies/action_type.py @@ -24,10 +24,12 @@ from typing_extensions import Annotated from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo from foundry._core import ResourceIterator +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.core.models._page_size import PageSize @@ -45,7 +47,7 @@ class ActionTypeClient: The API client for the ActionTypeV2 Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -56,6 +58,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _ActionTypeClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _ActionTypeClientRaw(auth=auth, hostname=hostname, config=config) @maybe_ignore_preview @pydantic.validate_call @@ -99,7 +105,7 @@ def get( response_type=ActionTypeV2, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -185,8 +191,181 @@ def page( """ warnings.warn( - "The ActionTypeClient.page(...) method has been deprecated. Please use ActionTypeClient.list(...) instead.", + "The client.ontologies.ActionType.page(...) method has been deprecated. Please use client.ontologies.ActionType.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/actionTypes", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={ + "ontology": ontology, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListActionTypesResponseV2, + request_timeout=request_timeout, + ), + ).decode() + + +class _ActionTypeClientRaw: + """ + The API client for the ActionTypeV2 Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + ontology: OntologyIdentifier, + action_type: ActionTypeApiName, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ActionTypeV2]: + """ + Gets a specific action type with the given API name. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param action_type: actionType + :type action_type: ActionTypeApiName + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ActionTypeV2] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/actionTypes/{actionType}", + query_params={}, + path_params={ + "ontology": ontology, + "actionType": action_type, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ActionTypeV2, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + ontology: OntologyIdentifier, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListActionTypesResponseV2]: + """ + Lists the action types for the given Ontology. + + Each page may be smaller than the requested page size. However, it is guaranteed that if there are more + results available, at least one result will be present in the response. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListActionTypesResponseV2] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/actionTypes", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={ + "ontology": ontology, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListActionTypesResponseV2, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + ontology: OntologyIdentifier, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListActionTypesResponseV2]: + """ + Lists the action types for the given Ontology. + + Each page may be smaller than the requested page size. However, it is guaranteed that if there are more + results available, at least one result will be present in the response. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListActionTypesResponseV2] + """ + + warnings.warn( + "The client.ontologies.ActionType.page(...) method has been deprecated. Please use client.ontologies.ActionType.list(...) instead.", DeprecationWarning, + stacklevel=2, ) return self._api_client.call_api( @@ -209,3 +388,175 @@ def page( request_timeout=request_timeout, ), ) + + +class _ActionTypeClientStreaming: + """ + The API client for the ActionTypeV2 Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + ontology: OntologyIdentifier, + action_type: ActionTypeApiName, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ActionTypeV2]: + """ + Gets a specific action type with the given API name. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param action_type: actionType + :type action_type: ActionTypeApiName + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ActionTypeV2] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/actionTypes/{actionType}", + query_params={}, + path_params={ + "ontology": ontology, + "actionType": action_type, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ActionTypeV2, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + ontology: OntologyIdentifier, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListActionTypesResponseV2]: + """ + Lists the action types for the given Ontology. + + Each page may be smaller than the requested page size. However, it is guaranteed that if there are more + results available, at least one result will be present in the response. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListActionTypesResponseV2] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/actionTypes", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={ + "ontology": ontology, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListActionTypesResponseV2, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + ontology: OntologyIdentifier, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListActionTypesResponseV2]: + """ + Lists the action types for the given Ontology. + + Each page may be smaller than the requested page size. However, it is guaranteed that if there are more + results available, at least one result will be present in the response. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListActionTypesResponseV2] + """ + + warnings.warn( + "The client.ontologies.ActionType.page(...) method has been deprecated. Please use client.ontologies.ActionType.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/actionTypes", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={ + "ontology": ontology, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListActionTypesResponseV2, + request_timeout=request_timeout, + ), + ) diff --git a/foundry/v2/ontologies/attachment.py b/foundry/v2/ontologies/attachment.py index d1d1eaa9..ee549220 100644 --- a/foundry/v2/ontologies/attachment.py +++ b/foundry/v2/ontologies/attachment.py @@ -23,13 +23,16 @@ import pydantic from typing_extensions import Annotated +from typing_extensions import deprecated from typing_extensions import overload from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import BinaryStream from foundry._core import Config from foundry._core import RequestInfo +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.core.models._content_length import ContentLength @@ -44,7 +47,7 @@ class AttachmentClient: The API client for the Attachment Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -55,6 +58,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _AttachmentClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _AttachmentClientRaw(auth=auth, hostname=hostname, config=config) @maybe_ignore_preview @pydantic.validate_call @@ -95,9 +102,12 @@ def get( response_type=AttachmentV2, request_timeout=request_timeout, ), - ) + ).decode() @overload + @deprecated( + "Using the `stream` parameter is deprecated. Please use the `with_streaming_response` instead." + ) def read( self, attachment_rid: AttachmentRid, @@ -151,6 +161,9 @@ def read( ... @overload + @deprecated( + "Using the `stream` parameter is deprecated. Please use the `with_streaming_response` instead." + ) def read( self, attachment_rid: AttachmentRid, @@ -207,6 +220,13 @@ def read( :rtype: Union[bytes, BinaryStream] """ + if stream: + warnings.warn( + f"client.ontologies.Attachment.read(..., stream=True, chunk_size={chunk_size}) is deprecated. Please use:\n\nwith client.ontologies.Attachment.with_streaming_response.read(...) as response:\n response.iter_bytes(chunk_size={chunk_size})\n", + DeprecationWarning, + stacklevel=2, + ) + return self._api_client.call_api( RequestInfo( method="GET", @@ -225,7 +245,7 @@ def read( chunk_size=chunk_size, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -282,4 +302,318 @@ def upload( response_type=AttachmentV2, request_timeout=request_timeout, ), + ).decode() + + +class _AttachmentClientRaw: + """ + The API client for the Attachment Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + attachment_rid: AttachmentRid, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[AttachmentV2]: + """ + Get the metadata of an attachment. + + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-read`. + + :param attachment_rid: attachmentRid + :type attachment_rid: AttachmentRid + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[AttachmentV2] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/attachments/{attachmentRid}", + query_params={}, + path_params={ + "attachmentRid": attachment_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=AttachmentV2, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def read( + self, + attachment_rid: AttachmentRid, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[bytes]: + """ + Get the content of an attachment. + + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-read`. + + :param attachment_rid: attachmentRid + :type attachment_rid: AttachmentRid + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[bytes] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/attachments/{attachmentRid}/content", + query_params={}, + path_params={ + "attachmentRid": attachment_rid, + }, + header_params={ + "Accept": "*/*", + }, + body=None, + body_type=None, + response_type=bytes, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def upload( + self, + body: bytes, + *, + content_length: ContentLength, + content_type: ContentType, + filename: Filename, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[AttachmentV2]: + """ + Upload an attachment to use in an action. Any attachment which has not been linked to an object via + an action within one hour after upload will be removed. + Previously mapped attachments which are not connected to any object anymore are also removed on + a biweekly basis. + The body of the request must contain the binary content of the file and the `Content-Type` header must be `application/octet-stream`. + + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-write`. + + :param body: Body of the request + :type body: bytes + :param content_length: Content-Length + :type content_length: ContentLength + :param content_type: Content-Type + :type content_type: ContentType + :param filename: filename + :type filename: Filename + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[AttachmentV2] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/ontologies/attachments/upload", + query_params={ + "filename": filename, + }, + path_params={}, + header_params={ + "Content-Length": content_length, + "Content-Type": content_type, + "Content-Type": "*/*", + "Accept": "application/json", + }, + body=body, + body_type=bytes, + response_type=AttachmentV2, + request_timeout=request_timeout, + ), + ) + + +class _AttachmentClientStreaming: + """ + The API client for the Attachment Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + attachment_rid: AttachmentRid, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[AttachmentV2]: + """ + Get the metadata of an attachment. + + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-read`. + + :param attachment_rid: attachmentRid + :type attachment_rid: AttachmentRid + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[AttachmentV2] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/attachments/{attachmentRid}", + query_params={}, + path_params={ + "attachmentRid": attachment_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=AttachmentV2, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def read( + self, + attachment_rid: AttachmentRid, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[bytes]: + """ + Get the content of an attachment. + + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-read`. + + :param attachment_rid: attachmentRid + :type attachment_rid: AttachmentRid + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[bytes] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/attachments/{attachmentRid}/content", + query_params={}, + path_params={ + "attachmentRid": attachment_rid, + }, + header_params={ + "Accept": "*/*", + }, + body=None, + body_type=None, + response_type=bytes, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def upload( + self, + body: bytes, + *, + content_length: ContentLength, + content_type: ContentType, + filename: Filename, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[AttachmentV2]: + """ + Upload an attachment to use in an action. Any attachment which has not been linked to an object via + an action within one hour after upload will be removed. + Previously mapped attachments which are not connected to any object anymore are also removed on + a biweekly basis. + The body of the request must contain the binary content of the file and the `Content-Type` header must be `application/octet-stream`. + + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-write`. + + :param body: Body of the request + :type body: bytes + :param content_length: Content-Length + :type content_length: ContentLength + :param content_type: Content-Type + :type content_type: ContentType + :param filename: filename + :type filename: Filename + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[AttachmentV2] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/ontologies/attachments/upload", + query_params={ + "filename": filename, + }, + path_params={}, + header_params={ + "Content-Length": content_length, + "Content-Type": content_type, + "Content-Type": "*/*", + "Accept": "application/json", + }, + body=body, + body_type=bytes, + response_type=AttachmentV2, + request_timeout=request_timeout, + ), ) diff --git a/foundry/v2/ontologies/attachment_property.py b/foundry/v2/ontologies/attachment_property.py index bab42d61..fd36417b 100644 --- a/foundry/v2/ontologies/attachment_property.py +++ b/foundry/v2/ontologies/attachment_property.py @@ -23,13 +23,16 @@ import pydantic from typing_extensions import Annotated +from typing_extensions import deprecated from typing_extensions import overload from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import BinaryStream from foundry._core import Config from foundry._core import RequestInfo +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.ontologies.models._artifact_repository_rid import ArtifactRepositoryRid @@ -52,7 +55,7 @@ class AttachmentPropertyClient: The API client for the AttachmentPropertyV2 Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -63,6 +66,12 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _AttachmentPropertyClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _AttachmentPropertyClientRaw( + auth=auth, hostname=hostname, config=config + ) @maybe_ignore_preview @pydantic.validate_call @@ -124,7 +133,7 @@ def get_attachment( response_type=AttachmentMetadataResponse, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -190,9 +199,12 @@ def get_attachment_by_rid( response_type=AttachmentV2, request_timeout=request_timeout, ), - ) + ).decode() @overload + @deprecated( + "Using the `stream` parameter is deprecated. Please use the `with_streaming_response` instead." + ) def read_attachment( self, ontology: OntologyIdentifier, @@ -276,6 +288,9 @@ def read_attachment( ... @overload + @deprecated( + "Using the `stream` parameter is deprecated. Please use the `with_streaming_response` instead." + ) def read_attachment( self, ontology: OntologyIdentifier, @@ -362,6 +377,13 @@ def read_attachment( :rtype: Union[bytes, BinaryStream] """ + if stream: + warnings.warn( + f"client.ontologies.AttachmentProperty.read_attachment(..., stream=True, chunk_size={chunk_size}) is deprecated. Please use:\n\nwith client.ontologies.AttachmentProperty.with_streaming_response.read_attachment(...) as response:\n response.iter_bytes(chunk_size={chunk_size})\n", + DeprecationWarning, + stacklevel=2, + ) + return self._api_client.call_api( RequestInfo( method="GET", @@ -386,9 +408,12 @@ def read_attachment( chunk_size=chunk_size, request_timeout=request_timeout, ), - ) + ).decode() @overload + @deprecated( + "Using the `stream` parameter is deprecated. Please use the `with_streaming_response` instead." + ) def read_attachment_by_rid( self, ontology: OntologyIdentifier, @@ -482,6 +507,9 @@ def read_attachment_by_rid( ... @overload + @deprecated( + "Using the `stream` parameter is deprecated. Please use the `with_streaming_response` instead." + ) def read_attachment_by_rid( self, ontology: OntologyIdentifier, @@ -578,6 +606,13 @@ def read_attachment_by_rid( :rtype: Union[bytes, BinaryStream] """ + if stream: + warnings.warn( + f"client.ontologies.AttachmentProperty.read_attachment_by_rid(..., stream=True, chunk_size={chunk_size}) is deprecated. Please use:\n\nwith client.ontologies.AttachmentProperty.with_streaming_response.read_attachment_by_rid(...) as response:\n response.iter_bytes(chunk_size={chunk_size})\n", + DeprecationWarning, + stacklevel=2, + ) + return self._api_client.call_api( RequestInfo( method="GET", @@ -603,4 +638,556 @@ def read_attachment_by_rid( chunk_size=chunk_size, request_timeout=request_timeout, ), + ).decode() + + +class _AttachmentPropertyClientRaw: + """ + The API client for the AttachmentPropertyV2 Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get_attachment( + self, + ontology: OntologyIdentifier, + object_type: ObjectTypeApiName, + primary_key: PropertyValueEscapedString, + property: PropertyApiName, + *, + artifact_repository: Optional[ArtifactRepositoryRid] = None, + package_name: Optional[SdkPackageName] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[AttachmentMetadataResponse]: + """ + Get the metadata of attachments parented to the given object. + + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param primary_key: primaryKey + :type primary_key: PropertyValueEscapedString + :param property: property + :type property: PropertyApiName + :param artifact_repository: artifactRepository + :type artifact_repository: Optional[ArtifactRepositoryRid] + :param package_name: packageName + :type package_name: Optional[SdkPackageName] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[AttachmentMetadataResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/objects/{objectType}/{primaryKey}/attachments/{property}", + query_params={ + "artifactRepository": artifact_repository, + "packageName": package_name, + }, + path_params={ + "ontology": ontology, + "objectType": object_type, + "primaryKey": primary_key, + "property": property, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=AttachmentMetadataResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get_attachment_by_rid( + self, + ontology: OntologyIdentifier, + object_type: ObjectTypeApiName, + primary_key: PropertyValueEscapedString, + property: PropertyApiName, + attachment_rid: AttachmentRid, + *, + artifact_repository: Optional[ArtifactRepositoryRid] = None, + package_name: Optional[SdkPackageName] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[AttachmentV2]: + """ + Get the metadata of a particular attachment in an attachment list. + + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param primary_key: primaryKey + :type primary_key: PropertyValueEscapedString + :param property: property + :type property: PropertyApiName + :param attachment_rid: attachmentRid + :type attachment_rid: AttachmentRid + :param artifact_repository: artifactRepository + :type artifact_repository: Optional[ArtifactRepositoryRid] + :param package_name: packageName + :type package_name: Optional[SdkPackageName] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[AttachmentV2] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/objects/{objectType}/{primaryKey}/attachments/{property}/{attachmentRid}", + query_params={ + "artifactRepository": artifact_repository, + "packageName": package_name, + }, + path_params={ + "ontology": ontology, + "objectType": object_type, + "primaryKey": primary_key, + "property": property, + "attachmentRid": attachment_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=AttachmentV2, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def read_attachment( + self, + ontology: OntologyIdentifier, + object_type: ObjectTypeApiName, + primary_key: PropertyValueEscapedString, + property: PropertyApiName, + *, + artifact_repository: Optional[ArtifactRepositoryRid] = None, + package_name: Optional[SdkPackageName] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[bytes]: + """ + Get the content of an attachment. + + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param primary_key: primaryKey + :type primary_key: PropertyValueEscapedString + :param property: property + :type property: PropertyApiName + :param artifact_repository: artifactRepository + :type artifact_repository: Optional[ArtifactRepositoryRid] + :param package_name: packageName + :type package_name: Optional[SdkPackageName] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[bytes] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/objects/{objectType}/{primaryKey}/attachments/{property}/content", + query_params={ + "artifactRepository": artifact_repository, + "packageName": package_name, + }, + path_params={ + "ontology": ontology, + "objectType": object_type, + "primaryKey": primary_key, + "property": property, + }, + header_params={ + "Accept": "*/*", + }, + body=None, + body_type=None, + response_type=bytes, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def read_attachment_by_rid( + self, + ontology: OntologyIdentifier, + object_type: ObjectTypeApiName, + primary_key: PropertyValueEscapedString, + property: PropertyApiName, + attachment_rid: AttachmentRid, + *, + artifact_repository: Optional[ArtifactRepositoryRid] = None, + package_name: Optional[SdkPackageName] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[bytes]: + """ + Get the content of an attachment by its RID. + + The RID must exist in the attachment array of the property. + + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param primary_key: primaryKey + :type primary_key: PropertyValueEscapedString + :param property: property + :type property: PropertyApiName + :param attachment_rid: attachmentRid + :type attachment_rid: AttachmentRid + :param artifact_repository: artifactRepository + :type artifact_repository: Optional[ArtifactRepositoryRid] + :param package_name: packageName + :type package_name: Optional[SdkPackageName] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[bytes] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/objects/{objectType}/{primaryKey}/attachments/{property}/{attachmentRid}/content", + query_params={ + "artifactRepository": artifact_repository, + "packageName": package_name, + }, + path_params={ + "ontology": ontology, + "objectType": object_type, + "primaryKey": primary_key, + "property": property, + "attachmentRid": attachment_rid, + }, + header_params={ + "Accept": "*/*", + }, + body=None, + body_type=None, + response_type=bytes, + request_timeout=request_timeout, + ), + ) + + +class _AttachmentPropertyClientStreaming: + """ + The API client for the AttachmentPropertyV2 Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get_attachment( + self, + ontology: OntologyIdentifier, + object_type: ObjectTypeApiName, + primary_key: PropertyValueEscapedString, + property: PropertyApiName, + *, + artifact_repository: Optional[ArtifactRepositoryRid] = None, + package_name: Optional[SdkPackageName] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[AttachmentMetadataResponse]: + """ + Get the metadata of attachments parented to the given object. + + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param primary_key: primaryKey + :type primary_key: PropertyValueEscapedString + :param property: property + :type property: PropertyApiName + :param artifact_repository: artifactRepository + :type artifact_repository: Optional[ArtifactRepositoryRid] + :param package_name: packageName + :type package_name: Optional[SdkPackageName] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[AttachmentMetadataResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/objects/{objectType}/{primaryKey}/attachments/{property}", + query_params={ + "artifactRepository": artifact_repository, + "packageName": package_name, + }, + path_params={ + "ontology": ontology, + "objectType": object_type, + "primaryKey": primary_key, + "property": property, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=AttachmentMetadataResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get_attachment_by_rid( + self, + ontology: OntologyIdentifier, + object_type: ObjectTypeApiName, + primary_key: PropertyValueEscapedString, + property: PropertyApiName, + attachment_rid: AttachmentRid, + *, + artifact_repository: Optional[ArtifactRepositoryRid] = None, + package_name: Optional[SdkPackageName] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[AttachmentV2]: + """ + Get the metadata of a particular attachment in an attachment list. + + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param primary_key: primaryKey + :type primary_key: PropertyValueEscapedString + :param property: property + :type property: PropertyApiName + :param attachment_rid: attachmentRid + :type attachment_rid: AttachmentRid + :param artifact_repository: artifactRepository + :type artifact_repository: Optional[ArtifactRepositoryRid] + :param package_name: packageName + :type package_name: Optional[SdkPackageName] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[AttachmentV2] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/objects/{objectType}/{primaryKey}/attachments/{property}/{attachmentRid}", + query_params={ + "artifactRepository": artifact_repository, + "packageName": package_name, + }, + path_params={ + "ontology": ontology, + "objectType": object_type, + "primaryKey": primary_key, + "property": property, + "attachmentRid": attachment_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=AttachmentV2, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def read_attachment( + self, + ontology: OntologyIdentifier, + object_type: ObjectTypeApiName, + primary_key: PropertyValueEscapedString, + property: PropertyApiName, + *, + artifact_repository: Optional[ArtifactRepositoryRid] = None, + package_name: Optional[SdkPackageName] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[bytes]: + """ + Get the content of an attachment. + + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param primary_key: primaryKey + :type primary_key: PropertyValueEscapedString + :param property: property + :type property: PropertyApiName + :param artifact_repository: artifactRepository + :type artifact_repository: Optional[ArtifactRepositoryRid] + :param package_name: packageName + :type package_name: Optional[SdkPackageName] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[bytes] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/objects/{objectType}/{primaryKey}/attachments/{property}/content", + query_params={ + "artifactRepository": artifact_repository, + "packageName": package_name, + }, + path_params={ + "ontology": ontology, + "objectType": object_type, + "primaryKey": primary_key, + "property": property, + }, + header_params={ + "Accept": "*/*", + }, + body=None, + body_type=None, + response_type=bytes, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def read_attachment_by_rid( + self, + ontology: OntologyIdentifier, + object_type: ObjectTypeApiName, + primary_key: PropertyValueEscapedString, + property: PropertyApiName, + attachment_rid: AttachmentRid, + *, + artifact_repository: Optional[ArtifactRepositoryRid] = None, + package_name: Optional[SdkPackageName] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[bytes]: + """ + Get the content of an attachment by its RID. + + The RID must exist in the attachment array of the property. + + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param primary_key: primaryKey + :type primary_key: PropertyValueEscapedString + :param property: property + :type property: PropertyApiName + :param attachment_rid: attachmentRid + :type attachment_rid: AttachmentRid + :param artifact_repository: artifactRepository + :type artifact_repository: Optional[ArtifactRepositoryRid] + :param package_name: packageName + :type package_name: Optional[SdkPackageName] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[bytes] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/objects/{objectType}/{primaryKey}/attachments/{property}/{attachmentRid}/content", + query_params={ + "artifactRepository": artifact_repository, + "packageName": package_name, + }, + path_params={ + "ontology": ontology, + "objectType": object_type, + "primaryKey": primary_key, + "property": property, + "attachmentRid": attachment_rid, + }, + header_params={ + "Accept": "*/*", + }, + body=None, + body_type=None, + response_type=bytes, + request_timeout=request_timeout, + ), ) diff --git a/foundry/v2/ontologies/client.py b/foundry/v2/ontologies/client.py index 8bc213de..8820fd4e 100644 --- a/foundry/v2/ontologies/client.py +++ b/foundry/v2/ontologies/client.py @@ -36,7 +36,7 @@ class OntologiesClient: The API client for the OntologiesV2 Namespace. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ diff --git a/foundry/v2/ontologies/linked_object.py b/foundry/v2/ontologies/linked_object.py index a2d904ec..1cb0de1d 100644 --- a/foundry/v2/ontologies/linked_object.py +++ b/foundry/v2/ontologies/linked_object.py @@ -25,10 +25,12 @@ from typing_extensions import Annotated from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo from foundry._core import ResourceIterator +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.core.models._page_size import PageSize @@ -54,7 +56,7 @@ class LinkedObjectClient: The API client for the LinkedObjectV2 Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -65,6 +67,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _LinkedObjectClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _LinkedObjectClientRaw(auth=auth, hostname=hostname, config=config) @maybe_ignore_preview @pydantic.validate_call @@ -139,7 +145,7 @@ def get_linked_object( response_type=OntologyObjectV2, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -299,10 +305,197 @@ def page_linked_objects( """ warnings.warn( - "The LinkedObjectClient.pageLinkedObjects(...) method has been deprecated. Please use LinkedObjectClient.listLinkedObjects(...) instead.", + "The client.ontologies.LinkedObject.page_linked_objects(...) method has been deprecated. Please use client.ontologies.LinkedObject.list_linked_objects(...) instead.", DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/objects/{objectType}/{primaryKey}/links/{linkType}", + query_params={ + "artifactRepository": artifact_repository, + "excludeRid": exclude_rid, + "orderBy": order_by, + "packageName": package_name, + "pageSize": page_size, + "pageToken": page_token, + "select": select, + }, + path_params={ + "ontology": ontology, + "objectType": object_type, + "primaryKey": primary_key, + "linkType": link_type, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListLinkedObjectsResponseV2, + request_timeout=request_timeout, + ), + ).decode() + + +class _LinkedObjectClientRaw: + """ + The API client for the LinkedObjectV2 Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get_linked_object( + self, + ontology: OntologyIdentifier, + object_type: ObjectTypeApiName, + primary_key: PropertyValueEscapedString, + link_type: LinkTypeApiName, + linked_object_primary_key: PropertyValueEscapedString, + *, + artifact_repository: Optional[ArtifactRepositoryRid] = None, + exclude_rid: Optional[bool] = None, + package_name: Optional[SdkPackageName] = None, + select: Optional[List[SelectedPropertyApiName]] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[OntologyObjectV2]: + """ + Get a specific linked object that originates from another object. + + If there is no link between the two objects, `LinkedObjectNotFound` is thrown. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param primary_key: primaryKey + :type primary_key: PropertyValueEscapedString + :param link_type: linkType + :type link_type: LinkTypeApiName + :param linked_object_primary_key: linkedObjectPrimaryKey + :type linked_object_primary_key: PropertyValueEscapedString + :param artifact_repository: artifactRepository + :type artifact_repository: Optional[ArtifactRepositoryRid] + :param exclude_rid: excludeRid + :type exclude_rid: Optional[bool] + :param package_name: packageName + :type package_name: Optional[SdkPackageName] + :param select: select + :type select: Optional[List[SelectedPropertyApiName]] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[OntologyObjectV2] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/objects/{objectType}/{primaryKey}/links/{linkType}/{linkedObjectPrimaryKey}", + query_params={ + "artifactRepository": artifact_repository, + "excludeRid": exclude_rid, + "packageName": package_name, + "select": select, + }, + path_params={ + "ontology": ontology, + "objectType": object_type, + "primaryKey": primary_key, + "linkType": link_type, + "linkedObjectPrimaryKey": linked_object_primary_key, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=OntologyObjectV2, + request_timeout=request_timeout, + ), ) + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list_linked_objects( + self, + ontology: OntologyIdentifier, + object_type: ObjectTypeApiName, + primary_key: PropertyValueEscapedString, + link_type: LinkTypeApiName, + *, + artifact_repository: Optional[ArtifactRepositoryRid] = None, + exclude_rid: Optional[bool] = None, + order_by: Optional[OrderBy] = None, + package_name: Optional[SdkPackageName] = None, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + select: Optional[List[SelectedPropertyApiName]] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListLinkedObjectsResponseV2]: + """ + Lists the linked objects for a specific object and the given link type. + + Note that this endpoint does not guarantee consistency. Changes to the data could result in missing or + repeated objects in the response pages. + + For Object Storage V1 backed objects, this endpoint returns a maximum of 10,000 objects. After 10,000 objects have been returned and if more objects + are available, attempting to load another page will result in an `ObjectsExceededLimit` error being returned. There is no limit on Object Storage V2 backed objects. + + Each page may be smaller or larger than the requested page size. However, it + is guaranteed that if there are more results available, at least one result will be present + in the response. + + Note that null value properties will not be returned. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param primary_key: primaryKey + :type primary_key: PropertyValueEscapedString + :param link_type: linkType + :type link_type: LinkTypeApiName + :param artifact_repository: artifactRepository + :type artifact_repository: Optional[ArtifactRepositoryRid] + :param exclude_rid: excludeRid + :type exclude_rid: Optional[bool] + :param order_by: orderBy + :type order_by: Optional[OrderBy] + :param package_name: packageName + :type package_name: Optional[SdkPackageName] + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param select: select + :type select: Optional[List[SelectedPropertyApiName]] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListLinkedObjectsResponseV2] + """ + return self._api_client.call_api( RequestInfo( method="GET", @@ -331,3 +524,387 @@ def page_linked_objects( request_timeout=request_timeout, ), ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page_linked_objects( + self, + ontology: OntologyIdentifier, + object_type: ObjectTypeApiName, + primary_key: PropertyValueEscapedString, + link_type: LinkTypeApiName, + *, + artifact_repository: Optional[ArtifactRepositoryRid] = None, + exclude_rid: Optional[bool] = None, + order_by: Optional[OrderBy] = None, + package_name: Optional[SdkPackageName] = None, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + select: Optional[List[SelectedPropertyApiName]] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListLinkedObjectsResponseV2]: + """ + Lists the linked objects for a specific object and the given link type. + + Note that this endpoint does not guarantee consistency. Changes to the data could result in missing or + repeated objects in the response pages. + + For Object Storage V1 backed objects, this endpoint returns a maximum of 10,000 objects. After 10,000 objects have been returned and if more objects + are available, attempting to load another page will result in an `ObjectsExceededLimit` error being returned. There is no limit on Object Storage V2 backed objects. + + Each page may be smaller or larger than the requested page size. However, it + is guaranteed that if there are more results available, at least one result will be present + in the response. + + Note that null value properties will not be returned. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param primary_key: primaryKey + :type primary_key: PropertyValueEscapedString + :param link_type: linkType + :type link_type: LinkTypeApiName + :param artifact_repository: artifactRepository + :type artifact_repository: Optional[ArtifactRepositoryRid] + :param exclude_rid: excludeRid + :type exclude_rid: Optional[bool] + :param order_by: orderBy + :type order_by: Optional[OrderBy] + :param package_name: packageName + :type package_name: Optional[SdkPackageName] + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param select: select + :type select: Optional[List[SelectedPropertyApiName]] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListLinkedObjectsResponseV2] + """ + + warnings.warn( + "The client.ontologies.LinkedObject.page_linked_objects(...) method has been deprecated. Please use client.ontologies.LinkedObject.list_linked_objects(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/objects/{objectType}/{primaryKey}/links/{linkType}", + query_params={ + "artifactRepository": artifact_repository, + "excludeRid": exclude_rid, + "orderBy": order_by, + "packageName": package_name, + "pageSize": page_size, + "pageToken": page_token, + "select": select, + }, + path_params={ + "ontology": ontology, + "objectType": object_type, + "primaryKey": primary_key, + "linkType": link_type, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListLinkedObjectsResponseV2, + request_timeout=request_timeout, + ), + ) + + +class _LinkedObjectClientStreaming: + """ + The API client for the LinkedObjectV2 Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get_linked_object( + self, + ontology: OntologyIdentifier, + object_type: ObjectTypeApiName, + primary_key: PropertyValueEscapedString, + link_type: LinkTypeApiName, + linked_object_primary_key: PropertyValueEscapedString, + *, + artifact_repository: Optional[ArtifactRepositoryRid] = None, + exclude_rid: Optional[bool] = None, + package_name: Optional[SdkPackageName] = None, + select: Optional[List[SelectedPropertyApiName]] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[OntologyObjectV2]: + """ + Get a specific linked object that originates from another object. + + If there is no link between the two objects, `LinkedObjectNotFound` is thrown. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param primary_key: primaryKey + :type primary_key: PropertyValueEscapedString + :param link_type: linkType + :type link_type: LinkTypeApiName + :param linked_object_primary_key: linkedObjectPrimaryKey + :type linked_object_primary_key: PropertyValueEscapedString + :param artifact_repository: artifactRepository + :type artifact_repository: Optional[ArtifactRepositoryRid] + :param exclude_rid: excludeRid + :type exclude_rid: Optional[bool] + :param package_name: packageName + :type package_name: Optional[SdkPackageName] + :param select: select + :type select: Optional[List[SelectedPropertyApiName]] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[OntologyObjectV2] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/objects/{objectType}/{primaryKey}/links/{linkType}/{linkedObjectPrimaryKey}", + query_params={ + "artifactRepository": artifact_repository, + "excludeRid": exclude_rid, + "packageName": package_name, + "select": select, + }, + path_params={ + "ontology": ontology, + "objectType": object_type, + "primaryKey": primary_key, + "linkType": link_type, + "linkedObjectPrimaryKey": linked_object_primary_key, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=OntologyObjectV2, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list_linked_objects( + self, + ontology: OntologyIdentifier, + object_type: ObjectTypeApiName, + primary_key: PropertyValueEscapedString, + link_type: LinkTypeApiName, + *, + artifact_repository: Optional[ArtifactRepositoryRid] = None, + exclude_rid: Optional[bool] = None, + order_by: Optional[OrderBy] = None, + package_name: Optional[SdkPackageName] = None, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + select: Optional[List[SelectedPropertyApiName]] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListLinkedObjectsResponseV2]: + """ + Lists the linked objects for a specific object and the given link type. + + Note that this endpoint does not guarantee consistency. Changes to the data could result in missing or + repeated objects in the response pages. + + For Object Storage V1 backed objects, this endpoint returns a maximum of 10,000 objects. After 10,000 objects have been returned and if more objects + are available, attempting to load another page will result in an `ObjectsExceededLimit` error being returned. There is no limit on Object Storage V2 backed objects. + + Each page may be smaller or larger than the requested page size. However, it + is guaranteed that if there are more results available, at least one result will be present + in the response. + + Note that null value properties will not be returned. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param primary_key: primaryKey + :type primary_key: PropertyValueEscapedString + :param link_type: linkType + :type link_type: LinkTypeApiName + :param artifact_repository: artifactRepository + :type artifact_repository: Optional[ArtifactRepositoryRid] + :param exclude_rid: excludeRid + :type exclude_rid: Optional[bool] + :param order_by: orderBy + :type order_by: Optional[OrderBy] + :param package_name: packageName + :type package_name: Optional[SdkPackageName] + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param select: select + :type select: Optional[List[SelectedPropertyApiName]] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListLinkedObjectsResponseV2] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/objects/{objectType}/{primaryKey}/links/{linkType}", + query_params={ + "artifactRepository": artifact_repository, + "excludeRid": exclude_rid, + "orderBy": order_by, + "packageName": package_name, + "pageSize": page_size, + "pageToken": page_token, + "select": select, + }, + path_params={ + "ontology": ontology, + "objectType": object_type, + "primaryKey": primary_key, + "linkType": link_type, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListLinkedObjectsResponseV2, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page_linked_objects( + self, + ontology: OntologyIdentifier, + object_type: ObjectTypeApiName, + primary_key: PropertyValueEscapedString, + link_type: LinkTypeApiName, + *, + artifact_repository: Optional[ArtifactRepositoryRid] = None, + exclude_rid: Optional[bool] = None, + order_by: Optional[OrderBy] = None, + package_name: Optional[SdkPackageName] = None, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + select: Optional[List[SelectedPropertyApiName]] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListLinkedObjectsResponseV2]: + """ + Lists the linked objects for a specific object and the given link type. + + Note that this endpoint does not guarantee consistency. Changes to the data could result in missing or + repeated objects in the response pages. + + For Object Storage V1 backed objects, this endpoint returns a maximum of 10,000 objects. After 10,000 objects have been returned and if more objects + are available, attempting to load another page will result in an `ObjectsExceededLimit` error being returned. There is no limit on Object Storage V2 backed objects. + + Each page may be smaller or larger than the requested page size. However, it + is guaranteed that if there are more results available, at least one result will be present + in the response. + + Note that null value properties will not be returned. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param primary_key: primaryKey + :type primary_key: PropertyValueEscapedString + :param link_type: linkType + :type link_type: LinkTypeApiName + :param artifact_repository: artifactRepository + :type artifact_repository: Optional[ArtifactRepositoryRid] + :param exclude_rid: excludeRid + :type exclude_rid: Optional[bool] + :param order_by: orderBy + :type order_by: Optional[OrderBy] + :param package_name: packageName + :type package_name: Optional[SdkPackageName] + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param select: select + :type select: Optional[List[SelectedPropertyApiName]] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListLinkedObjectsResponseV2] + """ + + warnings.warn( + "The client.ontologies.LinkedObject.page_linked_objects(...) method has been deprecated. Please use client.ontologies.LinkedObject.list_linked_objects(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/objects/{objectType}/{primaryKey}/links/{linkType}", + query_params={ + "artifactRepository": artifact_repository, + "excludeRid": exclude_rid, + "orderBy": order_by, + "packageName": package_name, + "pageSize": page_size, + "pageToken": page_token, + "select": select, + }, + path_params={ + "ontology": ontology, + "objectType": object_type, + "primaryKey": primary_key, + "linkType": link_type, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListLinkedObjectsResponseV2, + request_timeout=request_timeout, + ), + ) diff --git a/foundry/v2/ontologies/models/_search_order_by_type.py b/foundry/v2/ontologies/models/_search_order_by_type.py new file mode 100644 index 00000000..fe5f854c --- /dev/null +++ b/foundry/v2/ontologies/models/_search_order_by_type.py @@ -0,0 +1,21 @@ +# Copyright 2024 Palantir Technologies, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +from __future__ import annotations + +from typing import Literal + +SearchOrderByType = Literal["fields", "relevance"] +"""SearchOrderByType""" diff --git a/foundry/v2/ontologies/models/_search_order_by_v2_dict.py b/foundry/v2/ontologies/models/_search_order_by_v2_dict.py index 9f65182e..a9a5c2c9 100644 --- a/foundry/v2/ontologies/models/_search_order_by_v2_dict.py +++ b/foundry/v2/ontologies/models/_search_order_by_v2_dict.py @@ -17,14 +17,18 @@ from typing import List +from typing_extensions import NotRequired from typing_extensions import TypedDict +from foundry.v2.ontologies.models._search_order_by_type import SearchOrderByType from foundry.v2.ontologies.models._search_ordering_v2_dict import SearchOrderingV2Dict class SearchOrderByV2Dict(TypedDict): - """Specifies the ordering of search results by a field and an ordering direction.""" + """Specifies the ordering of search results by a field and an ordering direction or by relevance if scores are required in a nearestNeighbors query. By default `orderType` is set to `fields`.""" __pydantic_config__ = {"extra": "allow"} # type: ignore + orderType: NotRequired[SearchOrderByType] + fields: List[SearchOrderingV2Dict] diff --git a/foundry/v2/ontologies/object_type.py b/foundry/v2/ontologies/object_type.py index b556de46..193b8f80 100644 --- a/foundry/v2/ontologies/object_type.py +++ b/foundry/v2/ontologies/object_type.py @@ -24,10 +24,12 @@ from typing_extensions import Annotated from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo from foundry._core import ResourceIterator +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.core.models._page_size import PageSize @@ -50,7 +52,7 @@ class ObjectTypeClient: The API client for the ObjectTypeV2 Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -61,6 +63,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _ObjectTypeClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _ObjectTypeClientRaw(auth=auth, hostname=hostname, config=config) @maybe_ignore_preview @pydantic.validate_call @@ -104,7 +110,7 @@ def get( response_type=ObjectTypeV2, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -153,7 +159,7 @@ def get_outgoing_link_type( response_type=LinkTypeSideV2, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -295,8 +301,9 @@ def page( """ warnings.warn( - "The ObjectTypeClient.page(...) method has been deprecated. Please use ObjectTypeClient.list(...) instead.", + "The client.ontologies.ObjectType.page(...) method has been deprecated. Please use client.ontologies.ObjectType.list(...) instead.", DeprecationWarning, + stacklevel=2, ) return self._api_client.call_api( @@ -318,7 +325,7 @@ def page( response_type=ListObjectTypesV2Response, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -353,10 +360,229 @@ def page_outgoing_link_types( """ warnings.warn( - "The ObjectTypeClient.pageOutgoingLinkTypes(...) method has been deprecated. Please use ObjectTypeClient.listOutgoingLinkTypes(...) instead.", + "The client.ontologies.ObjectType.page_outgoing_link_types(...) method has been deprecated. Please use client.ontologies.ObjectType.list_outgoing_link_types(...) instead.", DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/objectTypes/{objectType}/outgoingLinkTypes", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={ + "ontology": ontology, + "objectType": object_type, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListOutgoingLinkTypesResponseV2, + request_timeout=request_timeout, + ), + ).decode() + + +class _ObjectTypeClientRaw: + """ + The API client for the ObjectTypeV2 Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + ontology: OntologyIdentifier, + object_type: ObjectTypeApiName, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ObjectTypeV2]: + """ + Gets a specific object type with the given API name. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ObjectTypeV2] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/objectTypes/{objectType}", + query_params={}, + path_params={ + "ontology": ontology, + "objectType": object_type, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ObjectTypeV2, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get_outgoing_link_type( + self, + ontology: OntologyIdentifier, + object_type: ObjectTypeApiName, + link_type: LinkTypeApiName, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[LinkTypeSideV2]: + """ + Get an outgoing link for an object type. + + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param link_type: linkType + :type link_type: LinkTypeApiName + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[LinkTypeSideV2] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/objectTypes/{objectType}/outgoingLinkTypes/{linkType}", + query_params={}, + path_params={ + "ontology": ontology, + "objectType": object_type, + "linkType": link_type, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=LinkTypeSideV2, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + ontology: OntologyIdentifier, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListObjectTypesV2Response]: + """ + Lists the object types for the given Ontology. + + Each page may be smaller or larger than the requested page size. However, it is guaranteed that if there are + more results available, at least one result will be present in the + response. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListObjectTypesV2Response] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/objectTypes", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={ + "ontology": ontology, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListObjectTypesV2Response, + request_timeout=request_timeout, + ), ) + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list_outgoing_link_types( + self, + ontology: OntologyIdentifier, + object_type: ObjectTypeApiName, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListOutgoingLinkTypesResponseV2]: + """ + List the outgoing links for an object type. + + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListOutgoingLinkTypesResponseV2] + """ + return self._api_client.call_api( RequestInfo( method="GET", @@ -378,3 +604,459 @@ def page_outgoing_link_types( request_timeout=request_timeout, ), ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + ontology: OntologyIdentifier, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListObjectTypesV2Response]: + """ + Lists the object types for the given Ontology. + + Each page may be smaller or larger than the requested page size. However, it is guaranteed that if there are + more results available, at least one result will be present in the + response. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListObjectTypesV2Response] + """ + + warnings.warn( + "The client.ontologies.ObjectType.page(...) method has been deprecated. Please use client.ontologies.ObjectType.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/objectTypes", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={ + "ontology": ontology, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListObjectTypesV2Response, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page_outgoing_link_types( + self, + ontology: OntologyIdentifier, + object_type: ObjectTypeApiName, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListOutgoingLinkTypesResponseV2]: + """ + List the outgoing links for an object type. + + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListOutgoingLinkTypesResponseV2] + """ + + warnings.warn( + "The client.ontologies.ObjectType.page_outgoing_link_types(...) method has been deprecated. Please use client.ontologies.ObjectType.list_outgoing_link_types(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/objectTypes/{objectType}/outgoingLinkTypes", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={ + "ontology": ontology, + "objectType": object_type, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListOutgoingLinkTypesResponseV2, + request_timeout=request_timeout, + ), + ) + + +class _ObjectTypeClientStreaming: + """ + The API client for the ObjectTypeV2 Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + ontology: OntologyIdentifier, + object_type: ObjectTypeApiName, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ObjectTypeV2]: + """ + Gets a specific object type with the given API name. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ObjectTypeV2] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/objectTypes/{objectType}", + query_params={}, + path_params={ + "ontology": ontology, + "objectType": object_type, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ObjectTypeV2, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get_outgoing_link_type( + self, + ontology: OntologyIdentifier, + object_type: ObjectTypeApiName, + link_type: LinkTypeApiName, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[LinkTypeSideV2]: + """ + Get an outgoing link for an object type. + + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param link_type: linkType + :type link_type: LinkTypeApiName + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[LinkTypeSideV2] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/objectTypes/{objectType}/outgoingLinkTypes/{linkType}", + query_params={}, + path_params={ + "ontology": ontology, + "objectType": object_type, + "linkType": link_type, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=LinkTypeSideV2, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + ontology: OntologyIdentifier, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListObjectTypesV2Response]: + """ + Lists the object types for the given Ontology. + + Each page may be smaller or larger than the requested page size. However, it is guaranteed that if there are + more results available, at least one result will be present in the + response. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListObjectTypesV2Response] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/objectTypes", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={ + "ontology": ontology, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListObjectTypesV2Response, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list_outgoing_link_types( + self, + ontology: OntologyIdentifier, + object_type: ObjectTypeApiName, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListOutgoingLinkTypesResponseV2]: + """ + List the outgoing links for an object type. + + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListOutgoingLinkTypesResponseV2] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/objectTypes/{objectType}/outgoingLinkTypes", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={ + "ontology": ontology, + "objectType": object_type, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListOutgoingLinkTypesResponseV2, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + ontology: OntologyIdentifier, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListObjectTypesV2Response]: + """ + Lists the object types for the given Ontology. + + Each page may be smaller or larger than the requested page size. However, it is guaranteed that if there are + more results available, at least one result will be present in the + response. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListObjectTypesV2Response] + """ + + warnings.warn( + "The client.ontologies.ObjectType.page(...) method has been deprecated. Please use client.ontologies.ObjectType.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/objectTypes", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={ + "ontology": ontology, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListObjectTypesV2Response, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page_outgoing_link_types( + self, + ontology: OntologyIdentifier, + object_type: ObjectTypeApiName, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListOutgoingLinkTypesResponseV2]: + """ + List the outgoing links for an object type. + + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListOutgoingLinkTypesResponseV2] + """ + + warnings.warn( + "The client.ontologies.ObjectType.page_outgoing_link_types(...) method has been deprecated. Please use client.ontologies.ObjectType.list_outgoing_link_types(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/objectTypes/{objectType}/outgoingLinkTypes", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={ + "ontology": ontology, + "objectType": object_type, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListOutgoingLinkTypesResponseV2, + request_timeout=request_timeout, + ), + ) diff --git a/foundry/v2/ontologies/ontology.py b/foundry/v2/ontologies/ontology.py index cce60dde..2da55a85 100644 --- a/foundry/v2/ontologies/ontology.py +++ b/foundry/v2/ontologies/ontology.py @@ -23,9 +23,11 @@ from typing_extensions import Annotated from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.ontologies.action_type import ActionTypeClient @@ -41,7 +43,7 @@ class OntologyClient: The API client for the OntologyV2 Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -52,6 +54,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _OntologyClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _OntologyClientRaw(auth=auth, hostname=hostname, config=config) self.ActionType = ActionTypeClient(auth=auth, hostname=hostname, config=config) self.ObjectType = ObjectTypeClient(auth=auth, hostname=hostname, config=config) self.QueryType = QueryTypeClient(auth=auth, hostname=hostname, config=config) @@ -94,7 +100,7 @@ def get( response_type=OntologyV2, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -132,4 +138,196 @@ def get_full_metadata( response_type=OntologyFullMetadata, request_timeout=request_timeout, ), + ).decode() + + +class _OntologyClientRaw: + """ + The API client for the OntologyV2 Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + ontology: OntologyIdentifier, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[OntologyV2]: + """ + Gets a specific ontology with the given Ontology RID. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[OntologyV2] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}", + query_params={}, + path_params={ + "ontology": ontology, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=OntologyV2, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get_full_metadata( + self, + ontology: OntologyIdentifier, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[OntologyFullMetadata]: + """ + Get the full Ontology metadata. This includes the objects, links, actions, queries, and interfaces. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[OntologyFullMetadata] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/fullMetadata", + query_params={}, + path_params={ + "ontology": ontology, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=OntologyFullMetadata, + request_timeout=request_timeout, + ), + ) + + +class _OntologyClientStreaming: + """ + The API client for the OntologyV2 Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + ontology: OntologyIdentifier, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[OntologyV2]: + """ + Gets a specific ontology with the given Ontology RID. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[OntologyV2] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}", + query_params={}, + path_params={ + "ontology": ontology, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=OntologyV2, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get_full_metadata( + self, + ontology: OntologyIdentifier, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[OntologyFullMetadata]: + """ + Get the full Ontology metadata. This includes the objects, links, actions, queries, and interfaces. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[OntologyFullMetadata] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/fullMetadata", + query_params={}, + path_params={ + "ontology": ontology, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=OntologyFullMetadata, + request_timeout=request_timeout, + ), ) diff --git a/foundry/v2/ontologies/ontology_interface.py b/foundry/v2/ontologies/ontology_interface.py index c71c55ad..eeda230c 100644 --- a/foundry/v2/ontologies/ontology_interface.py +++ b/foundry/v2/ontologies/ontology_interface.py @@ -26,10 +26,12 @@ from typing_extensions import TypedDict from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo from foundry._core import ResourceIterator +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.core.models._page_size import PageSize @@ -59,7 +61,7 @@ class OntologyInterfaceClient: The API client for the OntologyInterface Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -70,6 +72,12 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _OntologyInterfaceClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _OntologyInterfaceClientRaw( + auth=auth, hostname=hostname, config=config + ) @maybe_ignore_preview @pydantic.validate_call @@ -154,7 +162,7 @@ def aggregate( response_type=AggregateObjectsResponseV2, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -208,7 +216,7 @@ def get( response_type=InterfaceType, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -311,10 +319,229 @@ def page( """ warnings.warn( - "The OntologyInterfaceClient.page(...) method has been deprecated. Please use OntologyInterfaceClient.list(...) instead.", + "The client.ontologies.OntologyInterface.page(...) method has been deprecated. Please use client.ontologies.OntologyInterface.list(...) instead.", DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/interfaceTypes", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "ontology": ontology, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListInterfaceTypesResponse, + request_timeout=request_timeout, + ), + ).decode() + + +class _OntologyInterfaceClientRaw: + """ + The API client for the OntologyInterface Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def aggregate( + self, + ontology: OntologyIdentifier, + interface_type: InterfaceTypeApiName, + *, + aggregation: List[AggregationV2Dict], + group_by: List[AggregationGroupByV2Dict], + accuracy: Optional[AggregationAccuracyRequest] = None, + preview: Optional[PreviewMode] = None, + where: Optional[SearchJsonQueryV2Dict] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[AggregateObjectsResponseV2]: + """ + :::callout{theme=warning title=Warning} + This endpoint will be removed once TS OSDK is updated to use `objectSets/aggregate` with interface object + sets. + ::: + :::callout{theme=warning title=Warning} + This endpoint is in preview and may be modified or removed at any time. + To use this endpoint, add `preview=true` to the request query parameters. + ::: + + Perform functions on object fields in the specified ontology and of the specified interface type. Any + properties specified in the query must be shared property type API names defined on the interface. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param interface_type: interfaceType + :type interface_type: InterfaceTypeApiName + :param aggregation: + :type aggregation: List[AggregationV2Dict] + :param group_by: + :type group_by: List[AggregationGroupByV2Dict] + :param accuracy: + :type accuracy: Optional[AggregationAccuracyRequest] + :param preview: preview + :type preview: Optional[PreviewMode] + :param where: + :type where: Optional[SearchJsonQueryV2Dict] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[AggregateObjectsResponseV2] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/ontologies/{ontology}/interfaces/{interfaceType}/aggregate", + query_params={ + "preview": preview, + }, + path_params={ + "ontology": ontology, + "interfaceType": interface_type, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "aggregation": aggregation, + "where": where, + "groupBy": group_by, + "accuracy": accuracy, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "aggregation": List[AggregationV2Dict], + "where": Optional[SearchJsonQueryV2Dict], + "groupBy": List[AggregationGroupByV2Dict], + "accuracy": Optional[AggregationAccuracyRequest], + }, + ), + response_type=AggregateObjectsResponseV2, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + ontology: OntologyIdentifier, + interface_type: InterfaceTypeApiName, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[InterfaceType]: + """ + :::callout{theme=warning title=Warning} + This endpoint is in preview and may be modified or removed at any time. + To use this endpoint, add `preview=true` to the request query parameters. + ::: + + Gets a specific interface type with the given API name. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param interface_type: interfaceType + :type interface_type: InterfaceTypeApiName + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[InterfaceType] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/interfaceTypes/{interfaceType}", + query_params={ + "preview": preview, + }, + path_params={ + "ontology": ontology, + "interfaceType": interface_type, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=InterfaceType, + request_timeout=request_timeout, + ), ) + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + ontology: OntologyIdentifier, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListInterfaceTypesResponse]: + """ + :::callout{theme=warning title=Warning} + This endpoint is in preview and may be modified or removed at any time. + To use this endpoint, add `preview=true` to the request query parameters. + ::: + + Lists the interface types for the given Ontology. + + Each page may be smaller than the requested page size. However, it is guaranteed that if there are more + results available, at least one result will be present in the response. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListInterfaceTypesResponse] + """ + return self._api_client.call_api( RequestInfo( method="GET", @@ -336,3 +563,355 @@ def page( request_timeout=request_timeout, ), ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + ontology: OntologyIdentifier, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListInterfaceTypesResponse]: + """ + :::callout{theme=warning title=Warning} + This endpoint is in preview and may be modified or removed at any time. + To use this endpoint, add `preview=true` to the request query parameters. + ::: + + Lists the interface types for the given Ontology. + + Each page may be smaller than the requested page size. However, it is guaranteed that if there are more + results available, at least one result will be present in the response. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListInterfaceTypesResponse] + """ + + warnings.warn( + "The client.ontologies.OntologyInterface.page(...) method has been deprecated. Please use client.ontologies.OntologyInterface.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/interfaceTypes", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "ontology": ontology, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListInterfaceTypesResponse, + request_timeout=request_timeout, + ), + ) + + +class _OntologyInterfaceClientStreaming: + """ + The API client for the OntologyInterface Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def aggregate( + self, + ontology: OntologyIdentifier, + interface_type: InterfaceTypeApiName, + *, + aggregation: List[AggregationV2Dict], + group_by: List[AggregationGroupByV2Dict], + accuracy: Optional[AggregationAccuracyRequest] = None, + preview: Optional[PreviewMode] = None, + where: Optional[SearchJsonQueryV2Dict] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[AggregateObjectsResponseV2]: + """ + :::callout{theme=warning title=Warning} + This endpoint will be removed once TS OSDK is updated to use `objectSets/aggregate` with interface object + sets. + ::: + :::callout{theme=warning title=Warning} + This endpoint is in preview and may be modified or removed at any time. + To use this endpoint, add `preview=true` to the request query parameters. + ::: + + Perform functions on object fields in the specified ontology and of the specified interface type. Any + properties specified in the query must be shared property type API names defined on the interface. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param interface_type: interfaceType + :type interface_type: InterfaceTypeApiName + :param aggregation: + :type aggregation: List[AggregationV2Dict] + :param group_by: + :type group_by: List[AggregationGroupByV2Dict] + :param accuracy: + :type accuracy: Optional[AggregationAccuracyRequest] + :param preview: preview + :type preview: Optional[PreviewMode] + :param where: + :type where: Optional[SearchJsonQueryV2Dict] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[AggregateObjectsResponseV2] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/ontologies/{ontology}/interfaces/{interfaceType}/aggregate", + query_params={ + "preview": preview, + }, + path_params={ + "ontology": ontology, + "interfaceType": interface_type, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "aggregation": aggregation, + "where": where, + "groupBy": group_by, + "accuracy": accuracy, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "aggregation": List[AggregationV2Dict], + "where": Optional[SearchJsonQueryV2Dict], + "groupBy": List[AggregationGroupByV2Dict], + "accuracy": Optional[AggregationAccuracyRequest], + }, + ), + response_type=AggregateObjectsResponseV2, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + ontology: OntologyIdentifier, + interface_type: InterfaceTypeApiName, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[InterfaceType]: + """ + :::callout{theme=warning title=Warning} + This endpoint is in preview and may be modified or removed at any time. + To use this endpoint, add `preview=true` to the request query parameters. + ::: + + Gets a specific interface type with the given API name. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param interface_type: interfaceType + :type interface_type: InterfaceTypeApiName + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[InterfaceType] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/interfaceTypes/{interfaceType}", + query_params={ + "preview": preview, + }, + path_params={ + "ontology": ontology, + "interfaceType": interface_type, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=InterfaceType, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + ontology: OntologyIdentifier, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListInterfaceTypesResponse]: + """ + :::callout{theme=warning title=Warning} + This endpoint is in preview and may be modified or removed at any time. + To use this endpoint, add `preview=true` to the request query parameters. + ::: + + Lists the interface types for the given Ontology. + + Each page may be smaller than the requested page size. However, it is guaranteed that if there are more + results available, at least one result will be present in the response. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListInterfaceTypesResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/interfaceTypes", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "ontology": ontology, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListInterfaceTypesResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + ontology: OntologyIdentifier, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListInterfaceTypesResponse]: + """ + :::callout{theme=warning title=Warning} + This endpoint is in preview and may be modified or removed at any time. + To use this endpoint, add `preview=true` to the request query parameters. + ::: + + Lists the interface types for the given Ontology. + + Each page may be smaller than the requested page size. However, it is guaranteed that if there are more + results available, at least one result will be present in the response. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListInterfaceTypesResponse] + """ + + warnings.warn( + "The client.ontologies.OntologyInterface.page(...) method has been deprecated. Please use client.ontologies.OntologyInterface.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/interfaceTypes", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "ontology": ontology, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListInterfaceTypesResponse, + request_timeout=request_timeout, + ), + ) diff --git a/foundry/v2/ontologies/ontology_object.py b/foundry/v2/ontologies/ontology_object.py index a1bb17ac..a7416d55 100644 --- a/foundry/v2/ontologies/ontology_object.py +++ b/foundry/v2/ontologies/ontology_object.py @@ -26,10 +26,12 @@ from typing_extensions import TypedDict from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo from foundry._core import ResourceIterator +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.core.models._page_size import PageSize @@ -67,7 +69,7 @@ class OntologyObjectClient: The API client for the OntologyObjectV2 Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -78,6 +80,12 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _OntologyObjectClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _OntologyObjectClientRaw( + auth=auth, hostname=hostname, config=config + ) @maybe_ignore_preview @pydantic.validate_call @@ -156,7 +164,7 @@ def aggregate( response_type=AggregateObjectsResponseV2, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -209,7 +217,7 @@ def count( response_type=CountObjectsResponseV2, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -274,7 +282,7 @@ def get( response_type=OntologyObjectV2, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -420,8 +428,9 @@ def page( """ warnings.warn( - "The OntologyObjectClient.page(...) method has been deprecated. Please use OntologyObjectClient.list(...) instead.", + "The client.ontologies.OntologyObject.page(...) method has been deprecated. Please use client.ontologies.OntologyObject.list(...) instead.", DeprecationWarning, + stacklevel=2, ) return self._api_client.call_api( @@ -449,7 +458,7 @@ def page( response_type=ListObjectsResponseV2, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -560,4 +569,1008 @@ def search( response_type=SearchObjectsResponseV2, request_timeout=request_timeout, ), + ).decode() + + +class _OntologyObjectClientRaw: + """ + The API client for the OntologyObjectV2 Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def aggregate( + self, + ontology: OntologyIdentifier, + object_type: ObjectTypeApiName, + *, + aggregation: List[AggregationV2Dict], + group_by: List[AggregationGroupByV2Dict], + accuracy: Optional[AggregationAccuracyRequest] = None, + artifact_repository: Optional[ArtifactRepositoryRid] = None, + package_name: Optional[SdkPackageName] = None, + where: Optional[SearchJsonQueryV2Dict] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[AggregateObjectsResponseV2]: + """ + Perform functions on object fields in the specified ontology and object type. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param aggregation: + :type aggregation: List[AggregationV2Dict] + :param group_by: + :type group_by: List[AggregationGroupByV2Dict] + :param accuracy: + :type accuracy: Optional[AggregationAccuracyRequest] + :param artifact_repository: artifactRepository + :type artifact_repository: Optional[ArtifactRepositoryRid] + :param package_name: packageName + :type package_name: Optional[SdkPackageName] + :param where: + :type where: Optional[SearchJsonQueryV2Dict] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[AggregateObjectsResponseV2] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/ontologies/{ontology}/objects/{objectType}/aggregate", + query_params={ + "artifactRepository": artifact_repository, + "packageName": package_name, + }, + path_params={ + "ontology": ontology, + "objectType": object_type, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "aggregation": aggregation, + "where": where, + "groupBy": group_by, + "accuracy": accuracy, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "aggregation": List[AggregationV2Dict], + "where": Optional[SearchJsonQueryV2Dict], + "groupBy": List[AggregationGroupByV2Dict], + "accuracy": Optional[AggregationAccuracyRequest], + }, + ), + response_type=AggregateObjectsResponseV2, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def count( + self, + ontology: OntologyIdentifier, + object_type: ObjectTypeApiName, + *, + artifact_repository: Optional[ArtifactRepositoryRid] = None, + package_name: Optional[SdkPackageName] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[CountObjectsResponseV2]: + """ + Returns a count of the objects of the given object type. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param artifact_repository: artifactRepository + :type artifact_repository: Optional[ArtifactRepositoryRid] + :param package_name: packageName + :type package_name: Optional[SdkPackageName] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[CountObjectsResponseV2] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/ontologies/{ontology}/objects/{objectType}/count", + query_params={ + "artifactRepository": artifact_repository, + "packageName": package_name, + }, + path_params={ + "ontology": ontology, + "objectType": object_type, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=CountObjectsResponseV2, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + ontology: OntologyIdentifier, + object_type: ObjectTypeApiName, + primary_key: PropertyValueEscapedString, + *, + artifact_repository: Optional[ArtifactRepositoryRid] = None, + exclude_rid: Optional[bool] = None, + package_name: Optional[SdkPackageName] = None, + select: Optional[List[SelectedPropertyApiName]] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[OntologyObjectV2]: + """ + Gets a specific object with the given primary key. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param primary_key: primaryKey + :type primary_key: PropertyValueEscapedString + :param artifact_repository: artifactRepository + :type artifact_repository: Optional[ArtifactRepositoryRid] + :param exclude_rid: excludeRid + :type exclude_rid: Optional[bool] + :param package_name: packageName + :type package_name: Optional[SdkPackageName] + :param select: select + :type select: Optional[List[SelectedPropertyApiName]] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[OntologyObjectV2] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/objects/{objectType}/{primaryKey}", + query_params={ + "artifactRepository": artifact_repository, + "excludeRid": exclude_rid, + "packageName": package_name, + "select": select, + }, + path_params={ + "ontology": ontology, + "objectType": object_type, + "primaryKey": primary_key, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=OntologyObjectV2, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + ontology: OntologyIdentifier, + object_type: ObjectTypeApiName, + *, + artifact_repository: Optional[ArtifactRepositoryRid] = None, + exclude_rid: Optional[bool] = None, + order_by: Optional[OrderBy] = None, + package_name: Optional[SdkPackageName] = None, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + select: Optional[List[SelectedPropertyApiName]] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListObjectsResponseV2]: + """ + Lists the objects for the given Ontology and object type. + + Note that this endpoint does not guarantee consistency. Changes to the data could result in missing or + repeated objects in the response pages. + + For Object Storage V1 backed objects, this endpoint returns a maximum of 10,000 objects. After 10,000 objects have been returned and if more objects + are available, attempting to load another page will result in an `ObjectsExceededLimit` error being returned. There is no limit on Object Storage V2 backed objects. + + Each page may be smaller or larger than the requested page size. However, it + is guaranteed that if there are more results available, at least one result will be present + in the response. + + Note that null value properties will not be returned. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param artifact_repository: artifactRepository + :type artifact_repository: Optional[ArtifactRepositoryRid] + :param exclude_rid: excludeRid + :type exclude_rid: Optional[bool] + :param order_by: orderBy + :type order_by: Optional[OrderBy] + :param package_name: packageName + :type package_name: Optional[SdkPackageName] + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param select: select + :type select: Optional[List[SelectedPropertyApiName]] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListObjectsResponseV2] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/objects/{objectType}", + query_params={ + "artifactRepository": artifact_repository, + "excludeRid": exclude_rid, + "orderBy": order_by, + "packageName": package_name, + "pageSize": page_size, + "pageToken": page_token, + "select": select, + }, + path_params={ + "ontology": ontology, + "objectType": object_type, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListObjectsResponseV2, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + ontology: OntologyIdentifier, + object_type: ObjectTypeApiName, + *, + artifact_repository: Optional[ArtifactRepositoryRid] = None, + exclude_rid: Optional[bool] = None, + order_by: Optional[OrderBy] = None, + package_name: Optional[SdkPackageName] = None, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + select: Optional[List[SelectedPropertyApiName]] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListObjectsResponseV2]: + """ + Lists the objects for the given Ontology and object type. + + Note that this endpoint does not guarantee consistency. Changes to the data could result in missing or + repeated objects in the response pages. + + For Object Storage V1 backed objects, this endpoint returns a maximum of 10,000 objects. After 10,000 objects have been returned and if more objects + are available, attempting to load another page will result in an `ObjectsExceededLimit` error being returned. There is no limit on Object Storage V2 backed objects. + + Each page may be smaller or larger than the requested page size. However, it + is guaranteed that if there are more results available, at least one result will be present + in the response. + + Note that null value properties will not be returned. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param artifact_repository: artifactRepository + :type artifact_repository: Optional[ArtifactRepositoryRid] + :param exclude_rid: excludeRid + :type exclude_rid: Optional[bool] + :param order_by: orderBy + :type order_by: Optional[OrderBy] + :param package_name: packageName + :type package_name: Optional[SdkPackageName] + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param select: select + :type select: Optional[List[SelectedPropertyApiName]] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListObjectsResponseV2] + """ + + warnings.warn( + "The client.ontologies.OntologyObject.page(...) method has been deprecated. Please use client.ontologies.OntologyObject.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/objects/{objectType}", + query_params={ + "artifactRepository": artifact_repository, + "excludeRid": exclude_rid, + "orderBy": order_by, + "packageName": package_name, + "pageSize": page_size, + "pageToken": page_token, + "select": select, + }, + path_params={ + "ontology": ontology, + "objectType": object_type, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListObjectsResponseV2, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def search( + self, + ontology: OntologyIdentifier, + object_type: ObjectTypeApiName, + *, + select: List[PropertyApiName], + artifact_repository: Optional[ArtifactRepositoryRid] = None, + exclude_rid: Optional[bool] = None, + order_by: Optional[SearchOrderByV2Dict] = None, + package_name: Optional[SdkPackageName] = None, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + where: Optional[SearchJsonQueryV2Dict] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[SearchObjectsResponseV2]: + """ + Search for objects in the specified ontology and object type. The request body is used + to filter objects based on the specified query. The supported queries are: + + | Query type | Description | Supported Types | + |-----------------------------------------|-------------------------------------------------------------------------------------------------------------------|---------------------------------| + | lt | The provided property is less than the provided value. | number, string, date, timestamp | + | gt | The provided property is greater than the provided value. | number, string, date, timestamp | + | lte | The provided property is less than or equal to the provided value. | number, string, date, timestamp | + | gte | The provided property is greater than or equal to the provided value. | number, string, date, timestamp | + | eq | The provided property is exactly equal to the provided value. | number, string, date, timestamp | + | isNull | The provided property is (or is not) null. | all | + | contains | The provided property contains the provided value. | array | + | not | The sub-query does not match. | N/A (applied on a query) | + | and | All the sub-queries match. | N/A (applied on queries) | + | or | At least one of the sub-queries match. | N/A (applied on queries) | + | startsWith | The provided property starts with the provided term. | string | + | containsAllTermsInOrderPrefixLastTerm | The provided property contains all the terms provided in order. The last term can be a partial prefix match. | string | + | containsAllTermsInOrder | The provided property contains the provided term as a substring. | string | + | containsAnyTerm | The provided property contains at least one of the terms separated by whitespace. | string | + | containsAllTerms | The provided property contains all the terms separated by whitespace. | string | + + Queries can be at most three levels deep. By default, terms are separated by whitespace or punctuation (`?!,:;-[](){}'"~`). Periods (`.`) on their own are ignored. + Partial terms are not matched by terms filters except where explicitly noted. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param select: The API names of the object type properties to include in the response. + :type select: List[PropertyApiName] + :param artifact_repository: artifactRepository + :type artifact_repository: Optional[ArtifactRepositoryRid] + :param exclude_rid: A flag to exclude the retrieval of the `__rid` property. Setting this to true may improve performance of this endpoint for object types in OSV2. + :type exclude_rid: Optional[bool] + :param order_by: + :type order_by: Optional[SearchOrderByV2Dict] + :param package_name: packageName + :type package_name: Optional[SdkPackageName] + :param page_size: + :type page_size: Optional[PageSize] + :param page_token: + :type page_token: Optional[PageToken] + :param where: + :type where: Optional[SearchJsonQueryV2Dict] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[SearchObjectsResponseV2] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/ontologies/{ontology}/objects/{objectType}/search", + query_params={ + "artifactRepository": artifact_repository, + "packageName": package_name, + }, + path_params={ + "ontology": ontology, + "objectType": object_type, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "where": where, + "orderBy": order_by, + "pageSize": page_size, + "pageToken": page_token, + "select": select, + "excludeRid": exclude_rid, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "where": Optional[SearchJsonQueryV2Dict], + "orderBy": Optional[SearchOrderByV2Dict], + "pageSize": Optional[PageSize], + "pageToken": Optional[PageToken], + "select": List[PropertyApiName], + "excludeRid": Optional[bool], + }, + ), + response_type=SearchObjectsResponseV2, + request_timeout=request_timeout, + ), + ) + + +class _OntologyObjectClientStreaming: + """ + The API client for the OntologyObjectV2 Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def aggregate( + self, + ontology: OntologyIdentifier, + object_type: ObjectTypeApiName, + *, + aggregation: List[AggregationV2Dict], + group_by: List[AggregationGroupByV2Dict], + accuracy: Optional[AggregationAccuracyRequest] = None, + artifact_repository: Optional[ArtifactRepositoryRid] = None, + package_name: Optional[SdkPackageName] = None, + where: Optional[SearchJsonQueryV2Dict] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[AggregateObjectsResponseV2]: + """ + Perform functions on object fields in the specified ontology and object type. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param aggregation: + :type aggregation: List[AggregationV2Dict] + :param group_by: + :type group_by: List[AggregationGroupByV2Dict] + :param accuracy: + :type accuracy: Optional[AggregationAccuracyRequest] + :param artifact_repository: artifactRepository + :type artifact_repository: Optional[ArtifactRepositoryRid] + :param package_name: packageName + :type package_name: Optional[SdkPackageName] + :param where: + :type where: Optional[SearchJsonQueryV2Dict] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[AggregateObjectsResponseV2] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/ontologies/{ontology}/objects/{objectType}/aggregate", + query_params={ + "artifactRepository": artifact_repository, + "packageName": package_name, + }, + path_params={ + "ontology": ontology, + "objectType": object_type, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "aggregation": aggregation, + "where": where, + "groupBy": group_by, + "accuracy": accuracy, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "aggregation": List[AggregationV2Dict], + "where": Optional[SearchJsonQueryV2Dict], + "groupBy": List[AggregationGroupByV2Dict], + "accuracy": Optional[AggregationAccuracyRequest], + }, + ), + response_type=AggregateObjectsResponseV2, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def count( + self, + ontology: OntologyIdentifier, + object_type: ObjectTypeApiName, + *, + artifact_repository: Optional[ArtifactRepositoryRid] = None, + package_name: Optional[SdkPackageName] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[CountObjectsResponseV2]: + """ + Returns a count of the objects of the given object type. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param artifact_repository: artifactRepository + :type artifact_repository: Optional[ArtifactRepositoryRid] + :param package_name: packageName + :type package_name: Optional[SdkPackageName] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[CountObjectsResponseV2] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/ontologies/{ontology}/objects/{objectType}/count", + query_params={ + "artifactRepository": artifact_repository, + "packageName": package_name, + }, + path_params={ + "ontology": ontology, + "objectType": object_type, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=CountObjectsResponseV2, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + ontology: OntologyIdentifier, + object_type: ObjectTypeApiName, + primary_key: PropertyValueEscapedString, + *, + artifact_repository: Optional[ArtifactRepositoryRid] = None, + exclude_rid: Optional[bool] = None, + package_name: Optional[SdkPackageName] = None, + select: Optional[List[SelectedPropertyApiName]] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[OntologyObjectV2]: + """ + Gets a specific object with the given primary key. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param primary_key: primaryKey + :type primary_key: PropertyValueEscapedString + :param artifact_repository: artifactRepository + :type artifact_repository: Optional[ArtifactRepositoryRid] + :param exclude_rid: excludeRid + :type exclude_rid: Optional[bool] + :param package_name: packageName + :type package_name: Optional[SdkPackageName] + :param select: select + :type select: Optional[List[SelectedPropertyApiName]] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[OntologyObjectV2] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/objects/{objectType}/{primaryKey}", + query_params={ + "artifactRepository": artifact_repository, + "excludeRid": exclude_rid, + "packageName": package_name, + "select": select, + }, + path_params={ + "ontology": ontology, + "objectType": object_type, + "primaryKey": primary_key, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=OntologyObjectV2, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + ontology: OntologyIdentifier, + object_type: ObjectTypeApiName, + *, + artifact_repository: Optional[ArtifactRepositoryRid] = None, + exclude_rid: Optional[bool] = None, + order_by: Optional[OrderBy] = None, + package_name: Optional[SdkPackageName] = None, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + select: Optional[List[SelectedPropertyApiName]] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListObjectsResponseV2]: + """ + Lists the objects for the given Ontology and object type. + + Note that this endpoint does not guarantee consistency. Changes to the data could result in missing or + repeated objects in the response pages. + + For Object Storage V1 backed objects, this endpoint returns a maximum of 10,000 objects. After 10,000 objects have been returned and if more objects + are available, attempting to load another page will result in an `ObjectsExceededLimit` error being returned. There is no limit on Object Storage V2 backed objects. + + Each page may be smaller or larger than the requested page size. However, it + is guaranteed that if there are more results available, at least one result will be present + in the response. + + Note that null value properties will not be returned. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param artifact_repository: artifactRepository + :type artifact_repository: Optional[ArtifactRepositoryRid] + :param exclude_rid: excludeRid + :type exclude_rid: Optional[bool] + :param order_by: orderBy + :type order_by: Optional[OrderBy] + :param package_name: packageName + :type package_name: Optional[SdkPackageName] + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param select: select + :type select: Optional[List[SelectedPropertyApiName]] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListObjectsResponseV2] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/objects/{objectType}", + query_params={ + "artifactRepository": artifact_repository, + "excludeRid": exclude_rid, + "orderBy": order_by, + "packageName": package_name, + "pageSize": page_size, + "pageToken": page_token, + "select": select, + }, + path_params={ + "ontology": ontology, + "objectType": object_type, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListObjectsResponseV2, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + ontology: OntologyIdentifier, + object_type: ObjectTypeApiName, + *, + artifact_repository: Optional[ArtifactRepositoryRid] = None, + exclude_rid: Optional[bool] = None, + order_by: Optional[OrderBy] = None, + package_name: Optional[SdkPackageName] = None, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + select: Optional[List[SelectedPropertyApiName]] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListObjectsResponseV2]: + """ + Lists the objects for the given Ontology and object type. + + Note that this endpoint does not guarantee consistency. Changes to the data could result in missing or + repeated objects in the response pages. + + For Object Storage V1 backed objects, this endpoint returns a maximum of 10,000 objects. After 10,000 objects have been returned and if more objects + are available, attempting to load another page will result in an `ObjectsExceededLimit` error being returned. There is no limit on Object Storage V2 backed objects. + + Each page may be smaller or larger than the requested page size. However, it + is guaranteed that if there are more results available, at least one result will be present + in the response. + + Note that null value properties will not be returned. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param artifact_repository: artifactRepository + :type artifact_repository: Optional[ArtifactRepositoryRid] + :param exclude_rid: excludeRid + :type exclude_rid: Optional[bool] + :param order_by: orderBy + :type order_by: Optional[OrderBy] + :param package_name: packageName + :type package_name: Optional[SdkPackageName] + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param select: select + :type select: Optional[List[SelectedPropertyApiName]] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListObjectsResponseV2] + """ + + warnings.warn( + "The client.ontologies.OntologyObject.page(...) method has been deprecated. Please use client.ontologies.OntologyObject.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/objects/{objectType}", + query_params={ + "artifactRepository": artifact_repository, + "excludeRid": exclude_rid, + "orderBy": order_by, + "packageName": package_name, + "pageSize": page_size, + "pageToken": page_token, + "select": select, + }, + path_params={ + "ontology": ontology, + "objectType": object_type, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListObjectsResponseV2, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def search( + self, + ontology: OntologyIdentifier, + object_type: ObjectTypeApiName, + *, + select: List[PropertyApiName], + artifact_repository: Optional[ArtifactRepositoryRid] = None, + exclude_rid: Optional[bool] = None, + order_by: Optional[SearchOrderByV2Dict] = None, + package_name: Optional[SdkPackageName] = None, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + where: Optional[SearchJsonQueryV2Dict] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[SearchObjectsResponseV2]: + """ + Search for objects in the specified ontology and object type. The request body is used + to filter objects based on the specified query. The supported queries are: + + | Query type | Description | Supported Types | + |-----------------------------------------|-------------------------------------------------------------------------------------------------------------------|---------------------------------| + | lt | The provided property is less than the provided value. | number, string, date, timestamp | + | gt | The provided property is greater than the provided value. | number, string, date, timestamp | + | lte | The provided property is less than or equal to the provided value. | number, string, date, timestamp | + | gte | The provided property is greater than or equal to the provided value. | number, string, date, timestamp | + | eq | The provided property is exactly equal to the provided value. | number, string, date, timestamp | + | isNull | The provided property is (or is not) null. | all | + | contains | The provided property contains the provided value. | array | + | not | The sub-query does not match. | N/A (applied on a query) | + | and | All the sub-queries match. | N/A (applied on queries) | + | or | At least one of the sub-queries match. | N/A (applied on queries) | + | startsWith | The provided property starts with the provided term. | string | + | containsAllTermsInOrderPrefixLastTerm | The provided property contains all the terms provided in order. The last term can be a partial prefix match. | string | + | containsAllTermsInOrder | The provided property contains the provided term as a substring. | string | + | containsAnyTerm | The provided property contains at least one of the terms separated by whitespace. | string | + | containsAllTerms | The provided property contains all the terms separated by whitespace. | string | + + Queries can be at most three levels deep. By default, terms are separated by whitespace or punctuation (`?!,:;-[](){}'"~`). Periods (`.`) on their own are ignored. + Partial terms are not matched by terms filters except where explicitly noted. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param select: The API names of the object type properties to include in the response. + :type select: List[PropertyApiName] + :param artifact_repository: artifactRepository + :type artifact_repository: Optional[ArtifactRepositoryRid] + :param exclude_rid: A flag to exclude the retrieval of the `__rid` property. Setting this to true may improve performance of this endpoint for object types in OSV2. + :type exclude_rid: Optional[bool] + :param order_by: + :type order_by: Optional[SearchOrderByV2Dict] + :param package_name: packageName + :type package_name: Optional[SdkPackageName] + :param page_size: + :type page_size: Optional[PageSize] + :param page_token: + :type page_token: Optional[PageToken] + :param where: + :type where: Optional[SearchJsonQueryV2Dict] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[SearchObjectsResponseV2] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/ontologies/{ontology}/objects/{objectType}/search", + query_params={ + "artifactRepository": artifact_repository, + "packageName": package_name, + }, + path_params={ + "ontology": ontology, + "objectType": object_type, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "where": where, + "orderBy": order_by, + "pageSize": page_size, + "pageToken": page_token, + "select": select, + "excludeRid": exclude_rid, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "where": Optional[SearchJsonQueryV2Dict], + "orderBy": Optional[SearchOrderByV2Dict], + "pageSize": Optional[PageSize], + "pageToken": Optional[PageToken], + "select": List[PropertyApiName], + "excludeRid": Optional[bool], + }, + ), + response_type=SearchObjectsResponseV2, + request_timeout=request_timeout, + ), ) diff --git a/foundry/v2/ontologies/ontology_object_set.py b/foundry/v2/ontologies/ontology_object_set.py index 980f670b..8263f222 100644 --- a/foundry/v2/ontologies/ontology_object_set.py +++ b/foundry/v2/ontologies/ontology_object_set.py @@ -25,9 +25,11 @@ from typing_extensions import TypedDict from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.core.models._page_size import PageSize @@ -63,7 +65,7 @@ class OntologyObjectSetClient: The API client for the OntologyObjectSet Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -74,6 +76,12 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _OntologyObjectSetClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _OntologyObjectSetClientRaw( + auth=auth, hostname=hostname, config=config + ) @maybe_ignore_preview @pydantic.validate_call @@ -148,7 +156,7 @@ def aggregate( response_type=AggregateObjectsResponseV2, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -200,7 +208,7 @@ def create_temporary( response_type=CreateTemporaryObjectSetResponseV2, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -244,7 +252,7 @@ def get( response_type=ObjectSet, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -334,4 +342,562 @@ def load( response_type=LoadObjectSetResponseV2, request_timeout=request_timeout, ), + ).decode() + + +class _OntologyObjectSetClientRaw: + """ + The API client for the OntologyObjectSet Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def aggregate( + self, + ontology: OntologyIdentifier, + *, + aggregation: List[AggregationV2Dict], + group_by: List[AggregationGroupByV2Dict], + object_set: ObjectSetDict, + accuracy: Optional[AggregationAccuracyRequest] = None, + artifact_repository: Optional[ArtifactRepositoryRid] = None, + package_name: Optional[SdkPackageName] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[AggregateObjectsResponseV2]: + """ + Aggregates the ontology objects present in the `ObjectSet` from the provided object set definition. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param aggregation: + :type aggregation: List[AggregationV2Dict] + :param group_by: + :type group_by: List[AggregationGroupByV2Dict] + :param object_set: + :type object_set: ObjectSetDict + :param accuracy: + :type accuracy: Optional[AggregationAccuracyRequest] + :param artifact_repository: artifactRepository + :type artifact_repository: Optional[ArtifactRepositoryRid] + :param package_name: packageName + :type package_name: Optional[SdkPackageName] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[AggregateObjectsResponseV2] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/ontologies/{ontology}/objectSets/aggregate", + query_params={ + "artifactRepository": artifact_repository, + "packageName": package_name, + }, + path_params={ + "ontology": ontology, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "aggregation": aggregation, + "objectSet": object_set, + "groupBy": group_by, + "accuracy": accuracy, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "aggregation": List[AggregationV2Dict], + "objectSet": ObjectSetDict, + "groupBy": List[AggregationGroupByV2Dict], + "accuracy": Optional[AggregationAccuracyRequest], + }, + ), + response_type=AggregateObjectsResponseV2, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def create_temporary( + self, + ontology: OntologyIdentifier, + *, + object_set: ObjectSetDict, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[CreateTemporaryObjectSetResponseV2]: + """ + Creates a temporary `ObjectSet` from the given definition. + + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-read api:ontologies-write`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param object_set: + :type object_set: ObjectSetDict + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[CreateTemporaryObjectSetResponseV2] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/ontologies/{ontology}/objectSets/createTemporary", + query_params={}, + path_params={ + "ontology": ontology, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "objectSet": object_set, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "objectSet": ObjectSetDict, + }, + ), + response_type=CreateTemporaryObjectSetResponseV2, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + ontology: OntologyIdentifier, + object_set_rid: ObjectSetRid, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ObjectSet]: + """ + Gets the definition of the `ObjectSet` with the given RID. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param object_set_rid: objectSetRid + :type object_set_rid: ObjectSetRid + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ObjectSet] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/objectSets/{objectSetRid}", + query_params={}, + path_params={ + "ontology": ontology, + "objectSetRid": object_set_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ObjectSet, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def load( + self, + ontology: OntologyIdentifier, + *, + object_set: ObjectSetDict, + select: List[SelectedPropertyApiName], + artifact_repository: Optional[ArtifactRepositoryRid] = None, + exclude_rid: Optional[bool] = None, + order_by: Optional[SearchOrderByV2Dict] = None, + package_name: Optional[SdkPackageName] = None, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[LoadObjectSetResponseV2]: + """ + Load the ontology objects present in the `ObjectSet` from the provided object set definition. + + For Object Storage V1 backed objects, this endpoint returns a maximum of 10,000 objects. After 10,000 objects have been returned and if more objects + are available, attempting to load another page will result in an `ObjectsExceededLimit` error being returned. There is no limit on Object Storage V2 backed objects. + + Note that null value properties will not be returned. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param object_set: + :type object_set: ObjectSetDict + :param select: + :type select: List[SelectedPropertyApiName] + :param artifact_repository: artifactRepository + :type artifact_repository: Optional[ArtifactRepositoryRid] + :param exclude_rid: A flag to exclude the retrieval of the `__rid` property. Setting this to true may improve performance of this endpoint for object types in OSV2. + :type exclude_rid: Optional[bool] + :param order_by: + :type order_by: Optional[SearchOrderByV2Dict] + :param package_name: packageName + :type package_name: Optional[SdkPackageName] + :param page_size: + :type page_size: Optional[PageSize] + :param page_token: + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[LoadObjectSetResponseV2] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/ontologies/{ontology}/objectSets/loadObjects", + query_params={ + "artifactRepository": artifact_repository, + "packageName": package_name, + }, + path_params={ + "ontology": ontology, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "objectSet": object_set, + "orderBy": order_by, + "select": select, + "pageToken": page_token, + "pageSize": page_size, + "excludeRid": exclude_rid, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "objectSet": ObjectSetDict, + "orderBy": Optional[SearchOrderByV2Dict], + "select": List[SelectedPropertyApiName], + "pageToken": Optional[PageToken], + "pageSize": Optional[PageSize], + "excludeRid": Optional[bool], + }, + ), + response_type=LoadObjectSetResponseV2, + request_timeout=request_timeout, + ), + ) + + +class _OntologyObjectSetClientStreaming: + """ + The API client for the OntologyObjectSet Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def aggregate( + self, + ontology: OntologyIdentifier, + *, + aggregation: List[AggregationV2Dict], + group_by: List[AggregationGroupByV2Dict], + object_set: ObjectSetDict, + accuracy: Optional[AggregationAccuracyRequest] = None, + artifact_repository: Optional[ArtifactRepositoryRid] = None, + package_name: Optional[SdkPackageName] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[AggregateObjectsResponseV2]: + """ + Aggregates the ontology objects present in the `ObjectSet` from the provided object set definition. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param aggregation: + :type aggregation: List[AggregationV2Dict] + :param group_by: + :type group_by: List[AggregationGroupByV2Dict] + :param object_set: + :type object_set: ObjectSetDict + :param accuracy: + :type accuracy: Optional[AggregationAccuracyRequest] + :param artifact_repository: artifactRepository + :type artifact_repository: Optional[ArtifactRepositoryRid] + :param package_name: packageName + :type package_name: Optional[SdkPackageName] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[AggregateObjectsResponseV2] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/ontologies/{ontology}/objectSets/aggregate", + query_params={ + "artifactRepository": artifact_repository, + "packageName": package_name, + }, + path_params={ + "ontology": ontology, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "aggregation": aggregation, + "objectSet": object_set, + "groupBy": group_by, + "accuracy": accuracy, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "aggregation": List[AggregationV2Dict], + "objectSet": ObjectSetDict, + "groupBy": List[AggregationGroupByV2Dict], + "accuracy": Optional[AggregationAccuracyRequest], + }, + ), + response_type=AggregateObjectsResponseV2, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def create_temporary( + self, + ontology: OntologyIdentifier, + *, + object_set: ObjectSetDict, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[CreateTemporaryObjectSetResponseV2]: + """ + Creates a temporary `ObjectSet` from the given definition. + + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-read api:ontologies-write`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param object_set: + :type object_set: ObjectSetDict + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[CreateTemporaryObjectSetResponseV2] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/ontologies/{ontology}/objectSets/createTemporary", + query_params={}, + path_params={ + "ontology": ontology, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "objectSet": object_set, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "objectSet": ObjectSetDict, + }, + ), + response_type=CreateTemporaryObjectSetResponseV2, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + ontology: OntologyIdentifier, + object_set_rid: ObjectSetRid, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ObjectSet]: + """ + Gets the definition of the `ObjectSet` with the given RID. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param object_set_rid: objectSetRid + :type object_set_rid: ObjectSetRid + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ObjectSet] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/objectSets/{objectSetRid}", + query_params={}, + path_params={ + "ontology": ontology, + "objectSetRid": object_set_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ObjectSet, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def load( + self, + ontology: OntologyIdentifier, + *, + object_set: ObjectSetDict, + select: List[SelectedPropertyApiName], + artifact_repository: Optional[ArtifactRepositoryRid] = None, + exclude_rid: Optional[bool] = None, + order_by: Optional[SearchOrderByV2Dict] = None, + package_name: Optional[SdkPackageName] = None, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[LoadObjectSetResponseV2]: + """ + Load the ontology objects present in the `ObjectSet` from the provided object set definition. + + For Object Storage V1 backed objects, this endpoint returns a maximum of 10,000 objects. After 10,000 objects have been returned and if more objects + are available, attempting to load another page will result in an `ObjectsExceededLimit` error being returned. There is no limit on Object Storage V2 backed objects. + + Note that null value properties will not be returned. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param object_set: + :type object_set: ObjectSetDict + :param select: + :type select: List[SelectedPropertyApiName] + :param artifact_repository: artifactRepository + :type artifact_repository: Optional[ArtifactRepositoryRid] + :param exclude_rid: A flag to exclude the retrieval of the `__rid` property. Setting this to true may improve performance of this endpoint for object types in OSV2. + :type exclude_rid: Optional[bool] + :param order_by: + :type order_by: Optional[SearchOrderByV2Dict] + :param package_name: packageName + :type package_name: Optional[SdkPackageName] + :param page_size: + :type page_size: Optional[PageSize] + :param page_token: + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[LoadObjectSetResponseV2] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/ontologies/{ontology}/objectSets/loadObjects", + query_params={ + "artifactRepository": artifact_repository, + "packageName": package_name, + }, + path_params={ + "ontology": ontology, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "objectSet": object_set, + "orderBy": order_by, + "select": select, + "pageToken": page_token, + "pageSize": page_size, + "excludeRid": exclude_rid, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "objectSet": ObjectSetDict, + "orderBy": Optional[SearchOrderByV2Dict], + "select": List[SelectedPropertyApiName], + "pageToken": Optional[PageToken], + "pageSize": Optional[PageSize], + "excludeRid": Optional[bool], + }, + ), + response_type=LoadObjectSetResponseV2, + request_timeout=request_timeout, + ), ) diff --git a/foundry/v2/ontologies/query.py b/foundry/v2/ontologies/query.py index 0954da51..128a0188 100644 --- a/foundry/v2/ontologies/query.py +++ b/foundry/v2/ontologies/query.py @@ -24,9 +24,11 @@ from typing_extensions import TypedDict from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.ontologies.models._artifact_repository_rid import ArtifactRepositoryRid @@ -43,7 +45,7 @@ class QueryClient: The API client for the Query Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -54,6 +56,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _QueryClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _QueryClientRaw(auth=auth, hostname=hostname, config=config) @maybe_ignore_preview @pydantic.validate_call @@ -120,4 +126,174 @@ def execute( response_type=ExecuteQueryResponse, request_timeout=request_timeout, ), + ).decode() + + +class _QueryClientRaw: + """ + The API client for the Query Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def execute( + self, + ontology: OntologyIdentifier, + query_api_name: QueryApiName, + *, + parameters: Dict[ParameterId, Optional[DataValue]], + artifact_repository: Optional[ArtifactRepositoryRid] = None, + package_name: Optional[SdkPackageName] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ExecuteQueryResponse]: + """ + Executes a Query using the given parameters. + + Optional parameters do not need to be supplied. + + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param query_api_name: queryApiName + :type query_api_name: QueryApiName + :param parameters: + :type parameters: Dict[ParameterId, Optional[DataValue]] + :param artifact_repository: artifactRepository + :type artifact_repository: Optional[ArtifactRepositoryRid] + :param package_name: packageName + :type package_name: Optional[SdkPackageName] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ExecuteQueryResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/ontologies/{ontology}/queries/{queryApiName}/execute", + query_params={ + "artifactRepository": artifact_repository, + "packageName": package_name, + }, + path_params={ + "ontology": ontology, + "queryApiName": query_api_name, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "parameters": parameters, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "parameters": Dict[ParameterId, Optional[DataValue]], + }, + ), + response_type=ExecuteQueryResponse, + request_timeout=request_timeout, + ), + ) + + +class _QueryClientStreaming: + """ + The API client for the Query Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def execute( + self, + ontology: OntologyIdentifier, + query_api_name: QueryApiName, + *, + parameters: Dict[ParameterId, Optional[DataValue]], + artifact_repository: Optional[ArtifactRepositoryRid] = None, + package_name: Optional[SdkPackageName] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ExecuteQueryResponse]: + """ + Executes a Query using the given parameters. + + Optional parameters do not need to be supplied. + + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param query_api_name: queryApiName + :type query_api_name: QueryApiName + :param parameters: + :type parameters: Dict[ParameterId, Optional[DataValue]] + :param artifact_repository: artifactRepository + :type artifact_repository: Optional[ArtifactRepositoryRid] + :param package_name: packageName + :type package_name: Optional[SdkPackageName] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ExecuteQueryResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/ontologies/{ontology}/queries/{queryApiName}/execute", + query_params={ + "artifactRepository": artifact_repository, + "packageName": package_name, + }, + path_params={ + "ontology": ontology, + "queryApiName": query_api_name, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "parameters": parameters, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "parameters": Dict[ParameterId, Optional[DataValue]], + }, + ), + response_type=ExecuteQueryResponse, + request_timeout=request_timeout, + ), ) diff --git a/foundry/v2/ontologies/query_type.py b/foundry/v2/ontologies/query_type.py index f21e364d..429c55d4 100644 --- a/foundry/v2/ontologies/query_type.py +++ b/foundry/v2/ontologies/query_type.py @@ -24,10 +24,12 @@ from typing_extensions import Annotated from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo from foundry._core import ResourceIterator +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.core.models._page_size import PageSize @@ -45,7 +47,7 @@ class QueryTypeClient: The API client for the QueryType Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -56,6 +58,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _QueryTypeClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _QueryTypeClientRaw(auth=auth, hostname=hostname, config=config) @maybe_ignore_preview @pydantic.validate_call @@ -99,7 +105,7 @@ def get( response_type=QueryTypeV2, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -185,8 +191,181 @@ def page( """ warnings.warn( - "The QueryTypeClient.page(...) method has been deprecated. Please use QueryTypeClient.list(...) instead.", + "The client.ontologies.QueryType.page(...) method has been deprecated. Please use client.ontologies.QueryType.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/queryTypes", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={ + "ontology": ontology, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListQueryTypesResponseV2, + request_timeout=request_timeout, + ), + ).decode() + + +class _QueryTypeClientRaw: + """ + The API client for the QueryType Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + ontology: OntologyIdentifier, + query_api_name: QueryApiName, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[QueryTypeV2]: + """ + Gets a specific query type with the given API name. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param query_api_name: queryApiName + :type query_api_name: QueryApiName + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[QueryTypeV2] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/queryTypes/{queryApiName}", + query_params={}, + path_params={ + "ontology": ontology, + "queryApiName": query_api_name, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=QueryTypeV2, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + ontology: OntologyIdentifier, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListQueryTypesResponseV2]: + """ + Lists the query types for the given Ontology. + + Each page may be smaller than the requested page size. However, it is guaranteed that if there are more + results available, at least one result will be present in the response. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListQueryTypesResponseV2] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/queryTypes", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={ + "ontology": ontology, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListQueryTypesResponseV2, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + ontology: OntologyIdentifier, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListQueryTypesResponseV2]: + """ + Lists the query types for the given Ontology. + + Each page may be smaller than the requested page size. However, it is guaranteed that if there are more + results available, at least one result will be present in the response. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListQueryTypesResponseV2] + """ + + warnings.warn( + "The client.ontologies.QueryType.page(...) method has been deprecated. Please use client.ontologies.QueryType.list(...) instead.", DeprecationWarning, + stacklevel=2, ) return self._api_client.call_api( @@ -209,3 +388,175 @@ def page( request_timeout=request_timeout, ), ) + + +class _QueryTypeClientStreaming: + """ + The API client for the QueryType Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + ontology: OntologyIdentifier, + query_api_name: QueryApiName, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[QueryTypeV2]: + """ + Gets a specific query type with the given API name. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param query_api_name: queryApiName + :type query_api_name: QueryApiName + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[QueryTypeV2] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/queryTypes/{queryApiName}", + query_params={}, + path_params={ + "ontology": ontology, + "queryApiName": query_api_name, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=QueryTypeV2, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + ontology: OntologyIdentifier, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListQueryTypesResponseV2]: + """ + Lists the query types for the given Ontology. + + Each page may be smaller than the requested page size. However, it is guaranteed that if there are more + results available, at least one result will be present in the response. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListQueryTypesResponseV2] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/queryTypes", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={ + "ontology": ontology, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListQueryTypesResponseV2, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + ontology: OntologyIdentifier, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListQueryTypesResponseV2]: + """ + Lists the query types for the given Ontology. + + Each page may be smaller than the requested page size. However, it is guaranteed that if there are more + results available, at least one result will be present in the response. + + Third-party applications using this endpoint via OAuth2 must request the following operation scope: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListQueryTypesResponseV2] + """ + + warnings.warn( + "The client.ontologies.QueryType.page(...) method has been deprecated. Please use client.ontologies.QueryType.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/queryTypes", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={ + "ontology": ontology, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListQueryTypesResponseV2, + request_timeout=request_timeout, + ), + ) diff --git a/foundry/v2/ontologies/time_series_property_v2.py b/foundry/v2/ontologies/time_series_property_v2.py index 9543e81c..eb0ec129 100644 --- a/foundry/v2/ontologies/time_series_property_v2.py +++ b/foundry/v2/ontologies/time_series_property_v2.py @@ -24,13 +24,16 @@ import pydantic from typing_extensions import Annotated from typing_extensions import TypedDict +from typing_extensions import deprecated from typing_extensions import overload from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import BinaryStream from foundry._core import Config from foundry._core import RequestInfo +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.ontologies.models._artifact_repository_rid import ArtifactRepositoryRid @@ -50,7 +53,7 @@ class TimeSeriesPropertyV2Client: The API client for the TimeSeriesPropertyV2 Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -61,6 +64,12 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _TimeSeriesPropertyV2ClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _TimeSeriesPropertyV2ClientRaw( + auth=auth, hostname=hostname, config=config + ) @maybe_ignore_preview @pydantic.validate_call @@ -122,7 +131,7 @@ def get_first_point( response_type=TimeSeriesPoint, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -184,9 +193,12 @@ def get_last_point( response_type=TimeSeriesPoint, request_timeout=request_timeout, ), - ) + ).decode() @overload + @deprecated( + "Using the `stream` parameter is deprecated. Please use the `with_streaming_response` instead." + ) def stream_points( self, ontology: OntologyIdentifier, @@ -276,6 +288,9 @@ def stream_points( ... @overload + @deprecated( + "Using the `stream` parameter is deprecated. Please use the `with_streaming_response` instead." + ) def stream_points( self, ontology: OntologyIdentifier, @@ -368,6 +383,13 @@ def stream_points( :rtype: Union[bytes, BinaryStream] """ + if stream: + warnings.warn( + f"client.ontologies.TimeSeriesPropertyV2.stream_points(..., stream=True, chunk_size={chunk_size}) is deprecated. Please use:\n\nwith client.ontologies.TimeSeriesPropertyV2.with_streaming_response.stream_points(...) as response:\n response.iter_bytes(chunk_size={chunk_size})\n", + DeprecationWarning, + stacklevel=2, + ) + return self._api_client.call_api( RequestInfo( method="POST", @@ -400,4 +422,434 @@ def stream_points( chunk_size=chunk_size, request_timeout=request_timeout, ), + ).decode() + + +class _TimeSeriesPropertyV2ClientRaw: + """ + The API client for the TimeSeriesPropertyV2 Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get_first_point( + self, + ontology: OntologyIdentifier, + object_type: ObjectTypeApiName, + primary_key: PropertyValueEscapedString, + property: PropertyApiName, + *, + artifact_repository: Optional[ArtifactRepositoryRid] = None, + package_name: Optional[SdkPackageName] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[TimeSeriesPoint]: + """ + Get the first point of a time series property. + + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param primary_key: primaryKey + :type primary_key: PropertyValueEscapedString + :param property: property + :type property: PropertyApiName + :param artifact_repository: artifactRepository + :type artifact_repository: Optional[ArtifactRepositoryRid] + :param package_name: packageName + :type package_name: Optional[SdkPackageName] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[TimeSeriesPoint] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/objects/{objectType}/{primaryKey}/timeseries/{property}/firstPoint", + query_params={ + "artifactRepository": artifact_repository, + "packageName": package_name, + }, + path_params={ + "ontology": ontology, + "objectType": object_type, + "primaryKey": primary_key, + "property": property, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=TimeSeriesPoint, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get_last_point( + self, + ontology: OntologyIdentifier, + object_type: ObjectTypeApiName, + primary_key: PropertyValueEscapedString, + property: PropertyApiName, + *, + artifact_repository: Optional[ArtifactRepositoryRid] = None, + package_name: Optional[SdkPackageName] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[TimeSeriesPoint]: + """ + Get the last point of a time series property. + + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param primary_key: primaryKey + :type primary_key: PropertyValueEscapedString + :param property: property + :type property: PropertyApiName + :param artifact_repository: artifactRepository + :type artifact_repository: Optional[ArtifactRepositoryRid] + :param package_name: packageName + :type package_name: Optional[SdkPackageName] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[TimeSeriesPoint] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/objects/{objectType}/{primaryKey}/timeseries/{property}/lastPoint", + query_params={ + "artifactRepository": artifact_repository, + "packageName": package_name, + }, + path_params={ + "ontology": ontology, + "objectType": object_type, + "primaryKey": primary_key, + "property": property, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=TimeSeriesPoint, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def stream_points( + self, + ontology: OntologyIdentifier, + object_type: ObjectTypeApiName, + primary_key: PropertyValueEscapedString, + property: PropertyApiName, + *, + artifact_repository: Optional[ArtifactRepositoryRid] = None, + package_name: Optional[SdkPackageName] = None, + range: Optional[TimeRangeDict] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[bytes]: + """ + Stream all of the points of a time series property. + + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param primary_key: primaryKey + :type primary_key: PropertyValueEscapedString + :param property: property + :type property: PropertyApiName + :param artifact_repository: artifactRepository + :type artifact_repository: Optional[ArtifactRepositoryRid] + :param package_name: packageName + :type package_name: Optional[SdkPackageName] + :param range: + :type range: Optional[TimeRangeDict] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[bytes] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/ontologies/{ontology}/objects/{objectType}/{primaryKey}/timeseries/{property}/streamPoints", + query_params={ + "artifactRepository": artifact_repository, + "packageName": package_name, + }, + path_params={ + "ontology": ontology, + "objectType": object_type, + "primaryKey": primary_key, + "property": property, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "*/*", + }, + body={ + "range": range, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "range": Optional[TimeRangeDict], + }, + ), + response_type=bytes, + request_timeout=request_timeout, + ), + ) + + +class _TimeSeriesPropertyV2ClientStreaming: + """ + The API client for the TimeSeriesPropertyV2 Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get_first_point( + self, + ontology: OntologyIdentifier, + object_type: ObjectTypeApiName, + primary_key: PropertyValueEscapedString, + property: PropertyApiName, + *, + artifact_repository: Optional[ArtifactRepositoryRid] = None, + package_name: Optional[SdkPackageName] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[TimeSeriesPoint]: + """ + Get the first point of a time series property. + + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param primary_key: primaryKey + :type primary_key: PropertyValueEscapedString + :param property: property + :type property: PropertyApiName + :param artifact_repository: artifactRepository + :type artifact_repository: Optional[ArtifactRepositoryRid] + :param package_name: packageName + :type package_name: Optional[SdkPackageName] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[TimeSeriesPoint] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/objects/{objectType}/{primaryKey}/timeseries/{property}/firstPoint", + query_params={ + "artifactRepository": artifact_repository, + "packageName": package_name, + }, + path_params={ + "ontology": ontology, + "objectType": object_type, + "primaryKey": primary_key, + "property": property, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=TimeSeriesPoint, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get_last_point( + self, + ontology: OntologyIdentifier, + object_type: ObjectTypeApiName, + primary_key: PropertyValueEscapedString, + property: PropertyApiName, + *, + artifact_repository: Optional[ArtifactRepositoryRid] = None, + package_name: Optional[SdkPackageName] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[TimeSeriesPoint]: + """ + Get the last point of a time series property. + + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param primary_key: primaryKey + :type primary_key: PropertyValueEscapedString + :param property: property + :type property: PropertyApiName + :param artifact_repository: artifactRepository + :type artifact_repository: Optional[ArtifactRepositoryRid] + :param package_name: packageName + :type package_name: Optional[SdkPackageName] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[TimeSeriesPoint] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/ontologies/{ontology}/objects/{objectType}/{primaryKey}/timeseries/{property}/lastPoint", + query_params={ + "artifactRepository": artifact_repository, + "packageName": package_name, + }, + path_params={ + "ontology": ontology, + "objectType": object_type, + "primaryKey": primary_key, + "property": property, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=TimeSeriesPoint, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def stream_points( + self, + ontology: OntologyIdentifier, + object_type: ObjectTypeApiName, + primary_key: PropertyValueEscapedString, + property: PropertyApiName, + *, + artifact_repository: Optional[ArtifactRepositoryRid] = None, + package_name: Optional[SdkPackageName] = None, + range: Optional[TimeRangeDict] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[bytes]: + """ + Stream all of the points of a time series property. + + Third-party applications using this endpoint via OAuth2 must request the + following operation scopes: `api:ontologies-read`. + + :param ontology: ontology + :type ontology: OntologyIdentifier + :param object_type: objectType + :type object_type: ObjectTypeApiName + :param primary_key: primaryKey + :type primary_key: PropertyValueEscapedString + :param property: property + :type property: PropertyApiName + :param artifact_repository: artifactRepository + :type artifact_repository: Optional[ArtifactRepositoryRid] + :param package_name: packageName + :type package_name: Optional[SdkPackageName] + :param range: + :type range: Optional[TimeRangeDict] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[bytes] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/ontologies/{ontology}/objects/{objectType}/{primaryKey}/timeseries/{property}/streamPoints", + query_params={ + "artifactRepository": artifact_repository, + "packageName": package_name, + }, + path_params={ + "ontology": ontology, + "objectType": object_type, + "primaryKey": primary_key, + "property": property, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "*/*", + }, + body={ + "range": range, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "range": Optional[TimeRangeDict], + }, + ), + response_type=bytes, + request_timeout=request_timeout, + ), ) diff --git a/foundry/v2/orchestration/build.py b/foundry/v2/orchestration/build.py index e4bb4150..e6a4a883 100644 --- a/foundry/v2/orchestration/build.py +++ b/foundry/v2/orchestration/build.py @@ -26,9 +26,11 @@ from typing_extensions import TypedDict from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.core.models._page_size import PageSize @@ -66,7 +68,7 @@ class BuildClient: The API client for the Build Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -77,6 +79,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _BuildClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _BuildClientRaw(auth=auth, hostname=hostname, config=config) @maybe_ignore_preview @pydantic.validate_call @@ -117,7 +123,7 @@ def cancel( response_type=None, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -200,7 +206,7 @@ def create( response_type=Build, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -242,7 +248,7 @@ def get( response_type=Build, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -287,7 +293,7 @@ def get_batch( response_type=GetBuildsBatchResponse, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -350,4 +356,588 @@ def search( response_type=SearchBuildsResponse, request_timeout=request_timeout, ), + ).decode() + + +class _BuildClientRaw: + """ + The API client for the Build Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def cancel( + self, + build_rid: BuildRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[None]: + """ + Request a cancellation for all unfinished jobs in a build. The build's status will not update immediately. This endpoint is asynchronous and a success response indicates that the cancellation request has been acknowledged and the build is expected to be canceled soon. If the build has already finished or finishes shortly after the request and before the cancellation, the build will not change. + + :param build_rid: buildRid + :type build_rid: BuildRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[None] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/orchestration/builds/{buildRid}/cancel", + query_params={ + "preview": preview, + }, + path_params={ + "buildRid": build_rid, + }, + header_params={}, + body=None, + body_type=None, + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def create( + self, + *, + fallback_branches: FallbackBranches, + target: BuildTargetDict, + abort_on_failure: Optional[AbortOnFailure] = None, + branch_name: Optional[BranchName] = None, + force_build: Optional[ForceBuild] = None, + notifications_enabled: Optional[NotificationsEnabled] = None, + preview: Optional[PreviewMode] = None, + retry_backoff_duration: Optional[RetryBackoffDurationDict] = None, + retry_count: Optional[RetryCount] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Build]: + """ + + :param fallback_branches: + :type fallback_branches: FallbackBranches + :param target: The targets of the schedule. + :type target: BuildTargetDict + :param abort_on_failure: + :type abort_on_failure: Optional[AbortOnFailure] + :param branch_name: The target branch the build should run on. + :type branch_name: Optional[BranchName] + :param force_build: + :type force_build: Optional[ForceBuild] + :param notifications_enabled: The notification will be sent to the user that has most recently edited the schedule. No notification will be sent if the schedule has `scopeMode` set to `ProjectScope`. + :type notifications_enabled: Optional[NotificationsEnabled] + :param preview: preview + :type preview: Optional[PreviewMode] + :param retry_backoff_duration: + :type retry_backoff_duration: Optional[RetryBackoffDurationDict] + :param retry_count: The number of retry attempts for failed jobs. + :type retry_count: Optional[RetryCount] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Build] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/orchestration/builds/create", + query_params={ + "preview": preview, + }, + path_params={}, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "target": target, + "branchName": branch_name, + "fallbackBranches": fallback_branches, + "forceBuild": force_build, + "retryCount": retry_count, + "retryBackoffDuration": retry_backoff_duration, + "abortOnFailure": abort_on_failure, + "notificationsEnabled": notifications_enabled, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "target": BuildTargetDict, + "branchName": Optional[BranchName], + "fallbackBranches": FallbackBranches, + "forceBuild": Optional[ForceBuild], + "retryCount": Optional[RetryCount], + "retryBackoffDuration": Optional[RetryBackoffDurationDict], + "abortOnFailure": Optional[AbortOnFailure], + "notificationsEnabled": Optional[NotificationsEnabled], + }, + ), + response_type=Build, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + build_rid: BuildRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Build]: + """ + Get the Build with the specified rid. + :param build_rid: buildRid + :type build_rid: BuildRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Build] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/orchestration/builds/{buildRid}", + query_params={ + "preview": preview, + }, + path_params={ + "buildRid": build_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Build, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get_batch( + self, + body: Annotated[List[GetBuildsBatchRequestElementDict], Len(min_length=1, max_length=100)], + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[GetBuildsBatchResponse]: + """ + Execute multiple get requests on Build. + + The maximum batch size for this endpoint is 100. + :param body: Body of the request + :type body: Annotated[List[GetBuildsBatchRequestElementDict], Len(min_length=1, max_length=100)] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[GetBuildsBatchResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/orchestration/builds/getBatch", + query_params={ + "preview": preview, + }, + path_params={}, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body=body, + body_type=Annotated[ + List[GetBuildsBatchRequestElementDict], Len(min_length=1, max_length=100) + ], + response_type=GetBuildsBatchResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def search( + self, + *, + where: SearchBuildsFilterDict, + order_by: Optional[SearchBuildsOrderByDict] = None, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[SearchBuildsResponse]: + """ + Search for Builds. + :param where: + :type where: SearchBuildsFilterDict + :param order_by: + :type order_by: Optional[SearchBuildsOrderByDict] + :param page_size: The page size for the search request. If no value is provided, a default of `100` will be used. + :type page_size: Optional[PageSize] + :param page_token: + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[SearchBuildsResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/orchestration/builds/search", + query_params={ + "preview": preview, + }, + path_params={}, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "where": where, + "orderBy": order_by, + "pageToken": page_token, + "pageSize": page_size, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "where": SearchBuildsFilterDict, + "orderBy": Optional[SearchBuildsOrderByDict], + "pageToken": Optional[PageToken], + "pageSize": Optional[PageSize], + }, + ), + response_type=SearchBuildsResponse, + request_timeout=request_timeout, + ), + ) + + +class _BuildClientStreaming: + """ + The API client for the Build Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def cancel( + self, + build_rid: BuildRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[None]: + """ + Request a cancellation for all unfinished jobs in a build. The build's status will not update immediately. This endpoint is asynchronous and a success response indicates that the cancellation request has been acknowledged and the build is expected to be canceled soon. If the build has already finished or finishes shortly after the request and before the cancellation, the build will not change. + + :param build_rid: buildRid + :type build_rid: BuildRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[None] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/orchestration/builds/{buildRid}/cancel", + query_params={ + "preview": preview, + }, + path_params={ + "buildRid": build_rid, + }, + header_params={}, + body=None, + body_type=None, + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def create( + self, + *, + fallback_branches: FallbackBranches, + target: BuildTargetDict, + abort_on_failure: Optional[AbortOnFailure] = None, + branch_name: Optional[BranchName] = None, + force_build: Optional[ForceBuild] = None, + notifications_enabled: Optional[NotificationsEnabled] = None, + preview: Optional[PreviewMode] = None, + retry_backoff_duration: Optional[RetryBackoffDurationDict] = None, + retry_count: Optional[RetryCount] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Build]: + """ + + :param fallback_branches: + :type fallback_branches: FallbackBranches + :param target: The targets of the schedule. + :type target: BuildTargetDict + :param abort_on_failure: + :type abort_on_failure: Optional[AbortOnFailure] + :param branch_name: The target branch the build should run on. + :type branch_name: Optional[BranchName] + :param force_build: + :type force_build: Optional[ForceBuild] + :param notifications_enabled: The notification will be sent to the user that has most recently edited the schedule. No notification will be sent if the schedule has `scopeMode` set to `ProjectScope`. + :type notifications_enabled: Optional[NotificationsEnabled] + :param preview: preview + :type preview: Optional[PreviewMode] + :param retry_backoff_duration: + :type retry_backoff_duration: Optional[RetryBackoffDurationDict] + :param retry_count: The number of retry attempts for failed jobs. + :type retry_count: Optional[RetryCount] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Build] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/orchestration/builds/create", + query_params={ + "preview": preview, + }, + path_params={}, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "target": target, + "branchName": branch_name, + "fallbackBranches": fallback_branches, + "forceBuild": force_build, + "retryCount": retry_count, + "retryBackoffDuration": retry_backoff_duration, + "abortOnFailure": abort_on_failure, + "notificationsEnabled": notifications_enabled, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "target": BuildTargetDict, + "branchName": Optional[BranchName], + "fallbackBranches": FallbackBranches, + "forceBuild": Optional[ForceBuild], + "retryCount": Optional[RetryCount], + "retryBackoffDuration": Optional[RetryBackoffDurationDict], + "abortOnFailure": Optional[AbortOnFailure], + "notificationsEnabled": Optional[NotificationsEnabled], + }, + ), + response_type=Build, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + build_rid: BuildRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Build]: + """ + Get the Build with the specified rid. + :param build_rid: buildRid + :type build_rid: BuildRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Build] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/orchestration/builds/{buildRid}", + query_params={ + "preview": preview, + }, + path_params={ + "buildRid": build_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Build, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get_batch( + self, + body: Annotated[List[GetBuildsBatchRequestElementDict], Len(min_length=1, max_length=100)], + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[GetBuildsBatchResponse]: + """ + Execute multiple get requests on Build. + + The maximum batch size for this endpoint is 100. + :param body: Body of the request + :type body: Annotated[List[GetBuildsBatchRequestElementDict], Len(min_length=1, max_length=100)] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[GetBuildsBatchResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/orchestration/builds/getBatch", + query_params={ + "preview": preview, + }, + path_params={}, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body=body, + body_type=Annotated[ + List[GetBuildsBatchRequestElementDict], Len(min_length=1, max_length=100) + ], + response_type=GetBuildsBatchResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def search( + self, + *, + where: SearchBuildsFilterDict, + order_by: Optional[SearchBuildsOrderByDict] = None, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[SearchBuildsResponse]: + """ + Search for Builds. + :param where: + :type where: SearchBuildsFilterDict + :param order_by: + :type order_by: Optional[SearchBuildsOrderByDict] + :param page_size: The page size for the search request. If no value is provided, a default of `100` will be used. + :type page_size: Optional[PageSize] + :param page_token: + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[SearchBuildsResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/orchestration/builds/search", + query_params={ + "preview": preview, + }, + path_params={}, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "where": where, + "orderBy": order_by, + "pageToken": page_token, + "pageSize": page_size, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "where": SearchBuildsFilterDict, + "orderBy": Optional[SearchBuildsOrderByDict], + "pageToken": Optional[PageToken], + "pageSize": Optional[PageSize], + }, + ), + response_type=SearchBuildsResponse, + request_timeout=request_timeout, + ), ) diff --git a/foundry/v2/orchestration/client.py b/foundry/v2/orchestration/client.py index 956e3b51..7c3a63e3 100644 --- a/foundry/v2/orchestration/client.py +++ b/foundry/v2/orchestration/client.py @@ -29,7 +29,7 @@ class OrchestrationClient: The API client for the Orchestration Namespace. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ diff --git a/foundry/v2/orchestration/schedule.py b/foundry/v2/orchestration/schedule.py index daa8191a..8d4b1f8c 100644 --- a/foundry/v2/orchestration/schedule.py +++ b/foundry/v2/orchestration/schedule.py @@ -25,10 +25,12 @@ from typing_extensions import TypedDict from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo from foundry._core import ResourceIterator +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.core.models._page_size import PageSize @@ -60,7 +62,7 @@ class ScheduleClient: The API client for the Schedule Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -71,6 +73,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _ScheduleClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _ScheduleClientRaw(auth=auth, hostname=hostname, config=config) @maybe_ignore_preview @pydantic.validate_call @@ -138,7 +144,7 @@ def create( response_type=Schedule, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -178,7 +184,7 @@ def delete( response_type=None, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -220,7 +226,7 @@ def get( response_type=Schedule, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -260,7 +266,7 @@ def pause( response_type=None, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -333,7 +339,7 @@ def replace( response_type=Schedule, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -375,7 +381,7 @@ def run( response_type=ScheduleRun, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -458,8 +464,9 @@ def runs_page( """ warnings.warn( - "The ScheduleClient.runsPage(...) method has been deprecated. Please use ScheduleClient.runs(...) instead.", + "The client.orchestration.Schedule.runs_page(...) method has been deprecated. Please use client.orchestration.Schedule.runs(...) instead.", DeprecationWarning, + stacklevel=2, ) return self._api_client.call_api( @@ -482,7 +489,7 @@ def runs_page( response_type=ListRunsOfScheduleResponse, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -522,4 +529,946 @@ def unpause( response_type=None, request_timeout=request_timeout, ), + ).decode() + + +class _ScheduleClientRaw: + """ + The API client for the Schedule Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def create( + self, + *, + action: CreateScheduleRequestActionDict, + description: Optional[str] = None, + display_name: Optional[str] = None, + preview: Optional[PreviewMode] = None, + scope_mode: Optional[CreateScheduleRequestScopeModeDict] = None, + trigger: Optional[TriggerDict] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Schedule]: + """ + Creates a new Schedule. + :param action: + :type action: CreateScheduleRequestActionDict + :param description: + :type description: Optional[str] + :param display_name: + :type display_name: Optional[str] + :param preview: preview + :type preview: Optional[PreviewMode] + :param scope_mode: + :type scope_mode: Optional[CreateScheduleRequestScopeModeDict] + :param trigger: The schedule trigger. If the requesting user does not have permission to see the trigger, this will be empty. + :type trigger: Optional[TriggerDict] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Schedule] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/orchestration/schedules", + query_params={ + "preview": preview, + }, + path_params={}, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "displayName": display_name, + "description": description, + "action": action, + "trigger": trigger, + "scopeMode": scope_mode, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "displayName": Optional[str], + "description": Optional[str], + "action": CreateScheduleRequestActionDict, + "trigger": Optional[TriggerDict], + "scopeMode": Optional[CreateScheduleRequestScopeModeDict], + }, + ), + response_type=Schedule, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def delete( + self, + schedule_rid: ScheduleRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[None]: + """ + Delete the Schedule with the specified rid. + :param schedule_rid: scheduleRid + :type schedule_rid: ScheduleRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[None] + """ + + return self._api_client.call_api( + RequestInfo( + method="DELETE", + resource_path="/v2/orchestration/schedules/{scheduleRid}", + query_params={ + "preview": preview, + }, + path_params={ + "scheduleRid": schedule_rid, + }, + header_params={}, + body=None, + body_type=None, + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + schedule_rid: ScheduleRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Schedule]: + """ + Get the Schedule with the specified rid. + :param schedule_rid: scheduleRid + :type schedule_rid: ScheduleRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Schedule] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/orchestration/schedules/{scheduleRid}", + query_params={ + "preview": preview, + }, + path_params={ + "scheduleRid": schedule_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Schedule, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def pause( + self, + schedule_rid: ScheduleRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[None]: + """ + + :param schedule_rid: scheduleRid + :type schedule_rid: ScheduleRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[None] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/orchestration/schedules/{scheduleRid}/pause", + query_params={ + "preview": preview, + }, + path_params={ + "scheduleRid": schedule_rid, + }, + header_params={}, + body=None, + body_type=None, + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def replace( + self, + schedule_rid: ScheduleRid, + *, + action: ReplaceScheduleRequestActionDict, + description: Optional[str] = None, + display_name: Optional[str] = None, + preview: Optional[PreviewMode] = None, + scope_mode: Optional[ReplaceScheduleRequestScopeModeDict] = None, + trigger: Optional[TriggerDict] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Schedule]: + """ + Replace the Schedule with the specified rid. + :param schedule_rid: scheduleRid + :type schedule_rid: ScheduleRid + :param action: + :type action: ReplaceScheduleRequestActionDict + :param description: + :type description: Optional[str] + :param display_name: + :type display_name: Optional[str] + :param preview: preview + :type preview: Optional[PreviewMode] + :param scope_mode: + :type scope_mode: Optional[ReplaceScheduleRequestScopeModeDict] + :param trigger: The schedule trigger. If the requesting user does not have permission to see the trigger, this will be empty. + :type trigger: Optional[TriggerDict] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Schedule] + """ + + return self._api_client.call_api( + RequestInfo( + method="PUT", + resource_path="/v2/orchestration/schedules/{scheduleRid}", + query_params={ + "preview": preview, + }, + path_params={ + "scheduleRid": schedule_rid, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "displayName": display_name, + "description": description, + "action": action, + "trigger": trigger, + "scopeMode": scope_mode, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "displayName": Optional[str], + "description": Optional[str], + "action": ReplaceScheduleRequestActionDict, + "trigger": Optional[TriggerDict], + "scopeMode": Optional[ReplaceScheduleRequestScopeModeDict], + }, + ), + response_type=Schedule, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def run( + self, + schedule_rid: ScheduleRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ScheduleRun]: + """ + + :param schedule_rid: scheduleRid + :type schedule_rid: ScheduleRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ScheduleRun] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/orchestration/schedules/{scheduleRid}/run", + query_params={ + "preview": preview, + }, + path_params={ + "scheduleRid": schedule_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ScheduleRun, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def runs( + self, + schedule_rid: ScheduleRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListRunsOfScheduleResponse]: + """ + Get the most recent runs of a Schedule. If no page size is provided, a page size of 100 will be used. + + :param schedule_rid: scheduleRid + :type schedule_rid: ScheduleRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListRunsOfScheduleResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/orchestration/schedules/{scheduleRid}/runs", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "scheduleRid": schedule_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListRunsOfScheduleResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def runs_page( + self, + schedule_rid: ScheduleRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListRunsOfScheduleResponse]: + """ + Get the most recent runs of a Schedule. If no page size is provided, a page size of 100 will be used. + + :param schedule_rid: scheduleRid + :type schedule_rid: ScheduleRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListRunsOfScheduleResponse] + """ + + warnings.warn( + "The client.orchestration.Schedule.runs_page(...) method has been deprecated. Please use client.orchestration.Schedule.runs(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/orchestration/schedules/{scheduleRid}/runs", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "scheduleRid": schedule_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListRunsOfScheduleResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def unpause( + self, + schedule_rid: ScheduleRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[None]: + """ + + :param schedule_rid: scheduleRid + :type schedule_rid: ScheduleRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[None] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/orchestration/schedules/{scheduleRid}/unpause", + query_params={ + "preview": preview, + }, + path_params={ + "scheduleRid": schedule_rid, + }, + header_params={}, + body=None, + body_type=None, + response_type=None, + request_timeout=request_timeout, + ), + ) + + +class _ScheduleClientStreaming: + """ + The API client for the Schedule Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def create( + self, + *, + action: CreateScheduleRequestActionDict, + description: Optional[str] = None, + display_name: Optional[str] = None, + preview: Optional[PreviewMode] = None, + scope_mode: Optional[CreateScheduleRequestScopeModeDict] = None, + trigger: Optional[TriggerDict] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Schedule]: + """ + Creates a new Schedule. + :param action: + :type action: CreateScheduleRequestActionDict + :param description: + :type description: Optional[str] + :param display_name: + :type display_name: Optional[str] + :param preview: preview + :type preview: Optional[PreviewMode] + :param scope_mode: + :type scope_mode: Optional[CreateScheduleRequestScopeModeDict] + :param trigger: The schedule trigger. If the requesting user does not have permission to see the trigger, this will be empty. + :type trigger: Optional[TriggerDict] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Schedule] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/orchestration/schedules", + query_params={ + "preview": preview, + }, + path_params={}, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "displayName": display_name, + "description": description, + "action": action, + "trigger": trigger, + "scopeMode": scope_mode, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "displayName": Optional[str], + "description": Optional[str], + "action": CreateScheduleRequestActionDict, + "trigger": Optional[TriggerDict], + "scopeMode": Optional[CreateScheduleRequestScopeModeDict], + }, + ), + response_type=Schedule, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def delete( + self, + schedule_rid: ScheduleRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[None]: + """ + Delete the Schedule with the specified rid. + :param schedule_rid: scheduleRid + :type schedule_rid: ScheduleRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[None] + """ + + return self._api_client.stream_api( + RequestInfo( + method="DELETE", + resource_path="/v2/orchestration/schedules/{scheduleRid}", + query_params={ + "preview": preview, + }, + path_params={ + "scheduleRid": schedule_rid, + }, + header_params={}, + body=None, + body_type=None, + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + schedule_rid: ScheduleRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Schedule]: + """ + Get the Schedule with the specified rid. + :param schedule_rid: scheduleRid + :type schedule_rid: ScheduleRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Schedule] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/orchestration/schedules/{scheduleRid}", + query_params={ + "preview": preview, + }, + path_params={ + "scheduleRid": schedule_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Schedule, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def pause( + self, + schedule_rid: ScheduleRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[None]: + """ + + :param schedule_rid: scheduleRid + :type schedule_rid: ScheduleRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[None] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/orchestration/schedules/{scheduleRid}/pause", + query_params={ + "preview": preview, + }, + path_params={ + "scheduleRid": schedule_rid, + }, + header_params={}, + body=None, + body_type=None, + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def replace( + self, + schedule_rid: ScheduleRid, + *, + action: ReplaceScheduleRequestActionDict, + description: Optional[str] = None, + display_name: Optional[str] = None, + preview: Optional[PreviewMode] = None, + scope_mode: Optional[ReplaceScheduleRequestScopeModeDict] = None, + trigger: Optional[TriggerDict] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Schedule]: + """ + Replace the Schedule with the specified rid. + :param schedule_rid: scheduleRid + :type schedule_rid: ScheduleRid + :param action: + :type action: ReplaceScheduleRequestActionDict + :param description: + :type description: Optional[str] + :param display_name: + :type display_name: Optional[str] + :param preview: preview + :type preview: Optional[PreviewMode] + :param scope_mode: + :type scope_mode: Optional[ReplaceScheduleRequestScopeModeDict] + :param trigger: The schedule trigger. If the requesting user does not have permission to see the trigger, this will be empty. + :type trigger: Optional[TriggerDict] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Schedule] + """ + + return self._api_client.stream_api( + RequestInfo( + method="PUT", + resource_path="/v2/orchestration/schedules/{scheduleRid}", + query_params={ + "preview": preview, + }, + path_params={ + "scheduleRid": schedule_rid, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "displayName": display_name, + "description": description, + "action": action, + "trigger": trigger, + "scopeMode": scope_mode, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "displayName": Optional[str], + "description": Optional[str], + "action": ReplaceScheduleRequestActionDict, + "trigger": Optional[TriggerDict], + "scopeMode": Optional[ReplaceScheduleRequestScopeModeDict], + }, + ), + response_type=Schedule, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def run( + self, + schedule_rid: ScheduleRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ScheduleRun]: + """ + + :param schedule_rid: scheduleRid + :type schedule_rid: ScheduleRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ScheduleRun] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/orchestration/schedules/{scheduleRid}/run", + query_params={ + "preview": preview, + }, + path_params={ + "scheduleRid": schedule_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ScheduleRun, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def runs( + self, + schedule_rid: ScheduleRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListRunsOfScheduleResponse]: + """ + Get the most recent runs of a Schedule. If no page size is provided, a page size of 100 will be used. + + :param schedule_rid: scheduleRid + :type schedule_rid: ScheduleRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListRunsOfScheduleResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/orchestration/schedules/{scheduleRid}/runs", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "scheduleRid": schedule_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListRunsOfScheduleResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def runs_page( + self, + schedule_rid: ScheduleRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListRunsOfScheduleResponse]: + """ + Get the most recent runs of a Schedule. If no page size is provided, a page size of 100 will be used. + + :param schedule_rid: scheduleRid + :type schedule_rid: ScheduleRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListRunsOfScheduleResponse] + """ + + warnings.warn( + "The client.orchestration.Schedule.runs_page(...) method has been deprecated. Please use client.orchestration.Schedule.runs(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/orchestration/schedules/{scheduleRid}/runs", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + "preview": preview, + }, + path_params={ + "scheduleRid": schedule_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListRunsOfScheduleResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def unpause( + self, + schedule_rid: ScheduleRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[None]: + """ + + :param schedule_rid: scheduleRid + :type schedule_rid: ScheduleRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[None] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/orchestration/schedules/{scheduleRid}/unpause", + query_params={ + "preview": preview, + }, + path_params={ + "scheduleRid": schedule_rid, + }, + header_params={}, + body=None, + body_type=None, + response_type=None, + request_timeout=request_timeout, + ), ) diff --git a/foundry/v2/orchestration/schedule_version.py b/foundry/v2/orchestration/schedule_version.py index 458a3ccf..95e06b4f 100644 --- a/foundry/v2/orchestration/schedule_version.py +++ b/foundry/v2/orchestration/schedule_version.py @@ -23,9 +23,11 @@ from typing_extensions import Annotated from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.core.models._preview_mode import PreviewMode @@ -39,7 +41,7 @@ class ScheduleVersionClient: The API client for the ScheduleVersion Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -50,6 +52,12 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _ScheduleVersionClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _ScheduleVersionClientRaw( + auth=auth, hostname=hostname, config=config + ) @maybe_ignore_preview @pydantic.validate_call @@ -91,7 +99,7 @@ def get( response_type=ScheduleVersion, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -133,4 +141,208 @@ def schedule( response_type=Schedule, request_timeout=request_timeout, ), + ).decode() + + +class _ScheduleVersionClientRaw: + """ + The API client for the ScheduleVersion Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + schedule_version_rid: ScheduleVersionRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ScheduleVersion]: + """ + Get the ScheduleVersion with the specified rid. + :param schedule_version_rid: scheduleVersionRid + :type schedule_version_rid: ScheduleVersionRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ScheduleVersion] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/orchestration/scheduleVersions/{scheduleVersionRid}", + query_params={ + "preview": preview, + }, + path_params={ + "scheduleVersionRid": schedule_version_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ScheduleVersion, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def schedule( + self, + schedule_version_rid: ScheduleVersionRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Schedule]: + """ + + :param schedule_version_rid: scheduleVersionRid + :type schedule_version_rid: ScheduleVersionRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Schedule] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/orchestration/scheduleVersions/{scheduleVersionRid}/schedule", + query_params={ + "preview": preview, + }, + path_params={ + "scheduleVersionRid": schedule_version_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Schedule, + request_timeout=request_timeout, + ), + ) + + +class _ScheduleVersionClientStreaming: + """ + The API client for the ScheduleVersion Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + schedule_version_rid: ScheduleVersionRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ScheduleVersion]: + """ + Get the ScheduleVersion with the specified rid. + :param schedule_version_rid: scheduleVersionRid + :type schedule_version_rid: ScheduleVersionRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ScheduleVersion] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/orchestration/scheduleVersions/{scheduleVersionRid}", + query_params={ + "preview": preview, + }, + path_params={ + "scheduleVersionRid": schedule_version_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ScheduleVersion, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def schedule( + self, + schedule_version_rid: ScheduleVersionRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Schedule]: + """ + + :param schedule_version_rid: scheduleVersionRid + :type schedule_version_rid: ScheduleVersionRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Schedule] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/orchestration/scheduleVersions/{scheduleVersionRid}/schedule", + query_params={ + "preview": preview, + }, + path_params={ + "scheduleVersionRid": schedule_version_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Schedule, + request_timeout=request_timeout, + ), ) diff --git a/foundry/v2/streams/client.py b/foundry/v2/streams/client.py index cbf7be45..9c9bc0fb 100644 --- a/foundry/v2/streams/client.py +++ b/foundry/v2/streams/client.py @@ -27,7 +27,7 @@ class StreamsClient: The API client for the Streams Namespace. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ diff --git a/foundry/v2/streams/dataset.py b/foundry/v2/streams/dataset.py index e452a9d5..0181222d 100644 --- a/foundry/v2/streams/dataset.py +++ b/foundry/v2/streams/dataset.py @@ -24,9 +24,11 @@ from typing_extensions import TypedDict from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.core.models._preview_mode import PreviewMode @@ -46,7 +48,7 @@ class DatasetClient: The API client for the Dataset Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -57,6 +59,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _DatasetClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _DatasetClientRaw(auth=auth, hostname=hostname, config=config) self.Stream = StreamClient(auth=auth, hostname=hostname, config=config) @maybe_ignore_preview @@ -138,4 +144,202 @@ def create( response_type=Dataset, request_timeout=request_timeout, ), + ).decode() + + +class _DatasetClientRaw: + """ + The API client for the Dataset Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def create( + self, + *, + name: DatasetName, + parent_folder_rid: FolderRid, + schema: StreamSchemaDict, + branch_name: Optional[BranchName] = None, + compressed: Optional[Compressed] = None, + partitions_count: Optional[PartitionsCount] = None, + preview: Optional[PreviewMode] = None, + stream_type: Optional[StreamType] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Dataset]: + """ + Creates a streaming dataset with a stream on the specified branch, or if no branch is specified, on the + default branch ('master' for most enrollments). For more information on streaming datasets, refer to the + [streams](/docs/foundry/data-integration/streams/) user documentation. + + :param name: + :type name: DatasetName + :param parent_folder_rid: + :type parent_folder_rid: FolderRid + :param schema: The Foundry schema to apply to the new stream. + :type schema: StreamSchemaDict + :param branch_name: The branch to create the initial stream on. If not specified, the default branch will be used ('master' for most enrollments). + :type branch_name: Optional[BranchName] + :param compressed: Whether or not compression is enabled for the stream. Defaults to false. + :type compressed: Optional[Compressed] + :param partitions_count: The number of partitions for the Foundry stream. Generally, each partition can handle about 5 mb/s of data, so for higher volume streams, more partitions are recommended. If not specified, 1 partition is used. This value cannot be changed later. + :type partitions_count: Optional[PartitionsCount] + :param preview: preview + :type preview: Optional[PreviewMode] + :param stream_type: A conceptual representation of the expected shape of the data for a stream. HIGH_THROUGHPUT and LOW_LATENCY are not compatible with each other. Defaults to LOW_LATENCY. + :type stream_type: Optional[StreamType] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Dataset] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/streams/datasets/create", + query_params={ + "preview": preview, + }, + path_params={}, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "name": name, + "parentFolderRid": parent_folder_rid, + "schema": schema, + "branchName": branch_name, + "partitionsCount": partitions_count, + "streamType": stream_type, + "compressed": compressed, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "name": DatasetName, + "parentFolderRid": FolderRid, + "schema": StreamSchemaDict, + "branchName": Optional[BranchName], + "partitionsCount": Optional[PartitionsCount], + "streamType": Optional[StreamType], + "compressed": Optional[Compressed], + }, + ), + response_type=Dataset, + request_timeout=request_timeout, + ), + ) + + +class _DatasetClientStreaming: + """ + The API client for the Dataset Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def create( + self, + *, + name: DatasetName, + parent_folder_rid: FolderRid, + schema: StreamSchemaDict, + branch_name: Optional[BranchName] = None, + compressed: Optional[Compressed] = None, + partitions_count: Optional[PartitionsCount] = None, + preview: Optional[PreviewMode] = None, + stream_type: Optional[StreamType] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Dataset]: + """ + Creates a streaming dataset with a stream on the specified branch, or if no branch is specified, on the + default branch ('master' for most enrollments). For more information on streaming datasets, refer to the + [streams](/docs/foundry/data-integration/streams/) user documentation. + + :param name: + :type name: DatasetName + :param parent_folder_rid: + :type parent_folder_rid: FolderRid + :param schema: The Foundry schema to apply to the new stream. + :type schema: StreamSchemaDict + :param branch_name: The branch to create the initial stream on. If not specified, the default branch will be used ('master' for most enrollments). + :type branch_name: Optional[BranchName] + :param compressed: Whether or not compression is enabled for the stream. Defaults to false. + :type compressed: Optional[Compressed] + :param partitions_count: The number of partitions for the Foundry stream. Generally, each partition can handle about 5 mb/s of data, so for higher volume streams, more partitions are recommended. If not specified, 1 partition is used. This value cannot be changed later. + :type partitions_count: Optional[PartitionsCount] + :param preview: preview + :type preview: Optional[PreviewMode] + :param stream_type: A conceptual representation of the expected shape of the data for a stream. HIGH_THROUGHPUT and LOW_LATENCY are not compatible with each other. Defaults to LOW_LATENCY. + :type stream_type: Optional[StreamType] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Dataset] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/streams/datasets/create", + query_params={ + "preview": preview, + }, + path_params={}, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "name": name, + "parentFolderRid": parent_folder_rid, + "schema": schema, + "branchName": branch_name, + "partitionsCount": partitions_count, + "streamType": stream_type, + "compressed": compressed, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "name": DatasetName, + "parentFolderRid": FolderRid, + "schema": StreamSchemaDict, + "branchName": Optional[BranchName], + "partitionsCount": Optional[PartitionsCount], + "streamType": Optional[StreamType], + "compressed": Optional[Compressed], + }, + ), + response_type=Dataset, + request_timeout=request_timeout, + ), ) diff --git a/foundry/v2/streams/stream.py b/foundry/v2/streams/stream.py index 4be035d2..f2cab4e1 100644 --- a/foundry/v2/streams/stream.py +++ b/foundry/v2/streams/stream.py @@ -25,9 +25,11 @@ from typing_extensions import TypedDict from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.core.models._preview_mode import PreviewMode @@ -50,7 +52,7 @@ class StreamClient: The API client for the Stream Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -61,6 +63,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _StreamClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _StreamClientRaw(auth=auth, hostname=hostname, config=config) @maybe_ignore_preview @pydantic.validate_call @@ -134,7 +140,7 @@ def create( response_type=Stream, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -182,7 +188,7 @@ def get( response_type=Stream, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -236,7 +242,7 @@ def publish_binary_record( response_type=None, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -299,7 +305,7 @@ def publish_record( response_type=None, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -362,7 +368,7 @@ def publish_records( response_type=None, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -441,4 +447,802 @@ def reset( response_type=Stream, request_timeout=request_timeout, ), + ).decode() + + +class _StreamClientRaw: + """ + The API client for the Stream Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def create( + self, + dataset_rid: DatasetRid, + *, + branch_name: BranchName, + schema: CreateStreamRequestStreamSchemaDict, + compressed: Optional[Compressed] = None, + partitions_count: Optional[PartitionsCount] = None, + preview: Optional[PreviewMode] = None, + stream_type: Optional[StreamType] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Stream]: + """ + Creates a new branch on the backing streaming dataset, and creates a new stream on that branch. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param branch_name: + :type branch_name: BranchName + :param schema: The Foundry schema for this stream. + :type schema: CreateStreamRequestStreamSchemaDict + :param compressed: Whether or not compression is enabled for the stream. Defaults to false. + :type compressed: Optional[Compressed] + :param partitions_count: The number of partitions for the Foundry stream. Defaults to 1. Generally, each partition can handle about 5 mb/s of data, so for higher volume streams, more partitions are recommended. + :type partitions_count: Optional[PartitionsCount] + :param preview: preview + :type preview: Optional[PreviewMode] + :param stream_type: A conceptual representation of the expected shape of the data for a stream. HIGH_THROUGHPUT and LOW_LATENCY are not compatible with each other. Defaults to LOW_LATENCY. + :type stream_type: Optional[StreamType] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Stream] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/streams/datasets/{datasetRid}/streams", + query_params={ + "preview": preview, + }, + path_params={ + "datasetRid": dataset_rid, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "schema": schema, + "partitionsCount": partitions_count, + "streamType": stream_type, + "branchName": branch_name, + "compressed": compressed, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "schema": CreateStreamRequestStreamSchemaDict, + "partitionsCount": Optional[PartitionsCount], + "streamType": Optional[StreamType], + "branchName": BranchName, + "compressed": Optional[Compressed], + }, + ), + response_type=Stream, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + dataset_rid: DatasetRid, + stream_branch_name: BranchName, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Stream]: + """ + Get a stream by its branch name. If the branch does not exist, there is no stream on that branch, or the + user does not have permission to access the stream, a 404 error will be returned. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param stream_branch_name: streamBranchName + :type stream_branch_name: BranchName + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Stream] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/streams/datasets/{datasetRid}/streams/{streamBranchName}", + query_params={ + "preview": preview, + }, + path_params={ + "datasetRid": dataset_rid, + "streamBranchName": stream_branch_name, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Stream, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def publish_binary_record( + self, + dataset_rid: DatasetRid, + stream_branch_name: BranchName, + body: bytes, + *, + preview: Optional[PreviewMode] = None, + view_rid: Optional[ViewRid] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[None]: + """ + Publish a single binary record to the stream. The stream's schema must be a single binary field. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param stream_branch_name: streamBranchName + :type stream_branch_name: BranchName + :param body: The binary record to publish to the stream + :type body: bytes + :param preview: preview + :type preview: Optional[PreviewMode] + :param view_rid: viewRid + :type view_rid: Optional[ViewRid] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[None] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/highScale/streams/datasets/{datasetRid}/streams/{streamBranchName}/publishBinaryRecord", + query_params={ + "preview": preview, + "viewRid": view_rid, + }, + path_params={ + "datasetRid": dataset_rid, + "streamBranchName": stream_branch_name, + }, + header_params={ + "Content-Type": "application/octet-stream", + }, + body=body, + body_type=bytes, + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def publish_record( + self, + dataset_rid: DatasetRid, + stream_branch_name: BranchName, + *, + record: Record, + preview: Optional[PreviewMode] = None, + view_rid: Optional[ViewRid] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[None]: + """ + Publish a single record to the stream. The record will be validated against the stream's schema, and + rejected if it is invalid. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param stream_branch_name: streamBranchName + :type stream_branch_name: BranchName + :param record: The record to publish to the stream + :type record: Record + :param preview: preview + :type preview: Optional[PreviewMode] + :param view_rid: If provided, this endpoint will only write to the stream corresponding to the specified view rid. If not provided, this endpoint will write the latest stream on the branch. Providing this value is an advanced configuration, to be used when additional control over the underlying streaming data structures is needed. + :type view_rid: Optional[ViewRid] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[None] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/highScale/streams/datasets/{datasetRid}/streams/{streamBranchName}/publishRecord", + query_params={ + "preview": preview, + }, + path_params={ + "datasetRid": dataset_rid, + "streamBranchName": stream_branch_name, + }, + header_params={ + "Content-Type": "application/json", + }, + body={ + "record": record, + "viewRid": view_rid, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "record": Record, + "viewRid": Optional[ViewRid], + }, + ), + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def publish_records( + self, + dataset_rid: DatasetRid, + stream_branch_name: BranchName, + *, + records: List[Record], + preview: Optional[PreviewMode] = None, + view_rid: Optional[ViewRid] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[None]: + """ + Publish a batch of records to the stream. The records will be validated against the stream's schema, and + the batch will be rejected if one or more of the records are invalid. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param stream_branch_name: streamBranchName + :type stream_branch_name: BranchName + :param records: The records to publish to the stream + :type records: List[Record] + :param preview: preview + :type preview: Optional[PreviewMode] + :param view_rid: If provided, this endpoint will only write to the stream corresponding to the specified view rid. If not provided, this endpoint will write to the latest stream on the branch. Providing this value is an advanced configuration, to be used when additional control over the underlying streaming data structures is needed. + :type view_rid: Optional[ViewRid] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[None] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/highScale/streams/datasets/{datasetRid}/streams/{streamBranchName}/publishRecords", + query_params={ + "preview": preview, + }, + path_params={ + "datasetRid": dataset_rid, + "streamBranchName": stream_branch_name, + }, + header_params={ + "Content-Type": "application/json", + }, + body={ + "records": records, + "viewRid": view_rid, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "records": List[Record], + "viewRid": Optional[ViewRid], + }, + ), + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def reset( + self, + dataset_rid: DatasetRid, + stream_branch_name: BranchName, + *, + compressed: Optional[Compressed] = None, + partitions_count: Optional[PartitionsCount] = None, + preview: Optional[PreviewMode] = None, + schema: Optional[StreamSchemaDict] = None, + stream_type: Optional[StreamType] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Stream]: + """ + Reset the stream on the given dataset branch, clearing the existing records and allowing new configurations + to be applied. + + To change the stream settings without clearing the records, update the stream settings in-platform. + + This will create a new stream view (as seen by the change of the `viewRid` on the branch), + which will be the new stream view that will be written to for the branch. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param stream_branch_name: streamBranchName + :type stream_branch_name: BranchName + :param compressed: Whether or not compression is enabled for the stream. If omitted, the compression setting of the existing stream on the branch will be used. + :type compressed: Optional[Compressed] + :param partitions_count: The number of partitions for the Foundry stream. Generally, each partition can handle about 5 mb/s of data, so for higher volume streams, more partitions are recommended. If omitted, the partitions count of the existing stream on the branch will be used. + :type partitions_count: Optional[PartitionsCount] + :param preview: preview + :type preview: Optional[PreviewMode] + :param schema: The Foundry schema to apply to the new stream. If omitted, the schema of the existing stream on the branch will be used. + :type schema: Optional[StreamSchemaDict] + :param stream_type: A conceptual representation of the expected shape of the data for a stream. HIGH_THROUGHPUT and LOW_LATENCY are not compatible with each other. Defaults to LOW_LATENCY. If omitted, the stream type of the existing stream on the branch will be used. + :type stream_type: Optional[StreamType] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Stream] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/streams/datasets/{datasetRid}/streams/{streamBranchName}/reset", + query_params={ + "preview": preview, + }, + path_params={ + "datasetRid": dataset_rid, + "streamBranchName": stream_branch_name, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "schema": schema, + "partitionsCount": partitions_count, + "streamType": stream_type, + "compressed": compressed, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "schema": Optional[StreamSchemaDict], + "partitionsCount": Optional[PartitionsCount], + "streamType": Optional[StreamType], + "compressed": Optional[Compressed], + }, + ), + response_type=Stream, + request_timeout=request_timeout, + ), + ) + + +class _StreamClientStreaming: + """ + The API client for the Stream Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def create( + self, + dataset_rid: DatasetRid, + *, + branch_name: BranchName, + schema: CreateStreamRequestStreamSchemaDict, + compressed: Optional[Compressed] = None, + partitions_count: Optional[PartitionsCount] = None, + preview: Optional[PreviewMode] = None, + stream_type: Optional[StreamType] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Stream]: + """ + Creates a new branch on the backing streaming dataset, and creates a new stream on that branch. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param branch_name: + :type branch_name: BranchName + :param schema: The Foundry schema for this stream. + :type schema: CreateStreamRequestStreamSchemaDict + :param compressed: Whether or not compression is enabled for the stream. Defaults to false. + :type compressed: Optional[Compressed] + :param partitions_count: The number of partitions for the Foundry stream. Defaults to 1. Generally, each partition can handle about 5 mb/s of data, so for higher volume streams, more partitions are recommended. + :type partitions_count: Optional[PartitionsCount] + :param preview: preview + :type preview: Optional[PreviewMode] + :param stream_type: A conceptual representation of the expected shape of the data for a stream. HIGH_THROUGHPUT and LOW_LATENCY are not compatible with each other. Defaults to LOW_LATENCY. + :type stream_type: Optional[StreamType] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Stream] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/streams/datasets/{datasetRid}/streams", + query_params={ + "preview": preview, + }, + path_params={ + "datasetRid": dataset_rid, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "schema": schema, + "partitionsCount": partitions_count, + "streamType": stream_type, + "branchName": branch_name, + "compressed": compressed, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "schema": CreateStreamRequestStreamSchemaDict, + "partitionsCount": Optional[PartitionsCount], + "streamType": Optional[StreamType], + "branchName": BranchName, + "compressed": Optional[Compressed], + }, + ), + response_type=Stream, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + dataset_rid: DatasetRid, + stream_branch_name: BranchName, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Stream]: + """ + Get a stream by its branch name. If the branch does not exist, there is no stream on that branch, or the + user does not have permission to access the stream, a 404 error will be returned. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param stream_branch_name: streamBranchName + :type stream_branch_name: BranchName + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Stream] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/streams/datasets/{datasetRid}/streams/{streamBranchName}", + query_params={ + "preview": preview, + }, + path_params={ + "datasetRid": dataset_rid, + "streamBranchName": stream_branch_name, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Stream, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def publish_binary_record( + self, + dataset_rid: DatasetRid, + stream_branch_name: BranchName, + body: bytes, + *, + preview: Optional[PreviewMode] = None, + view_rid: Optional[ViewRid] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[None]: + """ + Publish a single binary record to the stream. The stream's schema must be a single binary field. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param stream_branch_name: streamBranchName + :type stream_branch_name: BranchName + :param body: The binary record to publish to the stream + :type body: bytes + :param preview: preview + :type preview: Optional[PreviewMode] + :param view_rid: viewRid + :type view_rid: Optional[ViewRid] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[None] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/highScale/streams/datasets/{datasetRid}/streams/{streamBranchName}/publishBinaryRecord", + query_params={ + "preview": preview, + "viewRid": view_rid, + }, + path_params={ + "datasetRid": dataset_rid, + "streamBranchName": stream_branch_name, + }, + header_params={ + "Content-Type": "application/octet-stream", + }, + body=body, + body_type=bytes, + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def publish_record( + self, + dataset_rid: DatasetRid, + stream_branch_name: BranchName, + *, + record: Record, + preview: Optional[PreviewMode] = None, + view_rid: Optional[ViewRid] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[None]: + """ + Publish a single record to the stream. The record will be validated against the stream's schema, and + rejected if it is invalid. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param stream_branch_name: streamBranchName + :type stream_branch_name: BranchName + :param record: The record to publish to the stream + :type record: Record + :param preview: preview + :type preview: Optional[PreviewMode] + :param view_rid: If provided, this endpoint will only write to the stream corresponding to the specified view rid. If not provided, this endpoint will write the latest stream on the branch. Providing this value is an advanced configuration, to be used when additional control over the underlying streaming data structures is needed. + :type view_rid: Optional[ViewRid] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[None] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/highScale/streams/datasets/{datasetRid}/streams/{streamBranchName}/publishRecord", + query_params={ + "preview": preview, + }, + path_params={ + "datasetRid": dataset_rid, + "streamBranchName": stream_branch_name, + }, + header_params={ + "Content-Type": "application/json", + }, + body={ + "record": record, + "viewRid": view_rid, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "record": Record, + "viewRid": Optional[ViewRid], + }, + ), + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def publish_records( + self, + dataset_rid: DatasetRid, + stream_branch_name: BranchName, + *, + records: List[Record], + preview: Optional[PreviewMode] = None, + view_rid: Optional[ViewRid] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[None]: + """ + Publish a batch of records to the stream. The records will be validated against the stream's schema, and + the batch will be rejected if one or more of the records are invalid. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param stream_branch_name: streamBranchName + :type stream_branch_name: BranchName + :param records: The records to publish to the stream + :type records: List[Record] + :param preview: preview + :type preview: Optional[PreviewMode] + :param view_rid: If provided, this endpoint will only write to the stream corresponding to the specified view rid. If not provided, this endpoint will write to the latest stream on the branch. Providing this value is an advanced configuration, to be used when additional control over the underlying streaming data structures is needed. + :type view_rid: Optional[ViewRid] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[None] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/highScale/streams/datasets/{datasetRid}/streams/{streamBranchName}/publishRecords", + query_params={ + "preview": preview, + }, + path_params={ + "datasetRid": dataset_rid, + "streamBranchName": stream_branch_name, + }, + header_params={ + "Content-Type": "application/json", + }, + body={ + "records": records, + "viewRid": view_rid, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "records": List[Record], + "viewRid": Optional[ViewRid], + }, + ), + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def reset( + self, + dataset_rid: DatasetRid, + stream_branch_name: BranchName, + *, + compressed: Optional[Compressed] = None, + partitions_count: Optional[PartitionsCount] = None, + preview: Optional[PreviewMode] = None, + schema: Optional[StreamSchemaDict] = None, + stream_type: Optional[StreamType] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Stream]: + """ + Reset the stream on the given dataset branch, clearing the existing records and allowing new configurations + to be applied. + + To change the stream settings without clearing the records, update the stream settings in-platform. + + This will create a new stream view (as seen by the change of the `viewRid` on the branch), + which will be the new stream view that will be written to for the branch. + + :param dataset_rid: datasetRid + :type dataset_rid: DatasetRid + :param stream_branch_name: streamBranchName + :type stream_branch_name: BranchName + :param compressed: Whether or not compression is enabled for the stream. If omitted, the compression setting of the existing stream on the branch will be used. + :type compressed: Optional[Compressed] + :param partitions_count: The number of partitions for the Foundry stream. Generally, each partition can handle about 5 mb/s of data, so for higher volume streams, more partitions are recommended. If omitted, the partitions count of the existing stream on the branch will be used. + :type partitions_count: Optional[PartitionsCount] + :param preview: preview + :type preview: Optional[PreviewMode] + :param schema: The Foundry schema to apply to the new stream. If omitted, the schema of the existing stream on the branch will be used. + :type schema: Optional[StreamSchemaDict] + :param stream_type: A conceptual representation of the expected shape of the data for a stream. HIGH_THROUGHPUT and LOW_LATENCY are not compatible with each other. Defaults to LOW_LATENCY. If omitted, the stream type of the existing stream on the branch will be used. + :type stream_type: Optional[StreamType] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Stream] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/streams/datasets/{datasetRid}/streams/{streamBranchName}/reset", + query_params={ + "preview": preview, + }, + path_params={ + "datasetRid": dataset_rid, + "streamBranchName": stream_branch_name, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "schema": schema, + "partitionsCount": partitions_count, + "streamType": stream_type, + "compressed": compressed, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "schema": Optional[StreamSchemaDict], + "partitionsCount": Optional[PartitionsCount], + "streamType": Optional[StreamType], + "compressed": Optional[Compressed], + }, + ), + response_type=Stream, + request_timeout=request_timeout, + ), ) diff --git a/foundry/v2/third_party_applications/client.py b/foundry/v2/third_party_applications/client.py index 30e74854..57bd9f52 100644 --- a/foundry/v2/third_party_applications/client.py +++ b/foundry/v2/third_party_applications/client.py @@ -29,7 +29,7 @@ class ThirdPartyApplicationsClient: The API client for the ThirdPartyApplications Namespace. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ diff --git a/foundry/v2/third_party_applications/third_party_application.py b/foundry/v2/third_party_applications/third_party_application.py index a257eb8d..ec6e87c7 100644 --- a/foundry/v2/third_party_applications/third_party_application.py +++ b/foundry/v2/third_party_applications/third_party_application.py @@ -23,9 +23,11 @@ from typing_extensions import Annotated from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.core.models._preview_mode import PreviewMode @@ -43,7 +45,7 @@ class ThirdPartyApplicationClient: The API client for the ThirdPartyApplication Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -54,6 +56,12 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _ThirdPartyApplicationClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _ThirdPartyApplicationClientRaw( + auth=auth, hostname=hostname, config=config + ) self.Website = WebsiteClient(auth=auth, hostname=hostname, config=config) @maybe_ignore_preview @@ -96,4 +104,124 @@ def get( response_type=ThirdPartyApplication, request_timeout=request_timeout, ), + ).decode() + + +class _ThirdPartyApplicationClientRaw: + """ + The API client for the ThirdPartyApplication Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + third_party_application_rid: ThirdPartyApplicationRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ThirdPartyApplication]: + """ + Get the ThirdPartyApplication with the specified rid. + :param third_party_application_rid: thirdPartyApplicationRid + :type third_party_application_rid: ThirdPartyApplicationRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ThirdPartyApplication] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/thirdPartyApplications/{thirdPartyApplicationRid}", + query_params={ + "preview": preview, + }, + path_params={ + "thirdPartyApplicationRid": third_party_application_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ThirdPartyApplication, + request_timeout=request_timeout, + ), + ) + + +class _ThirdPartyApplicationClientStreaming: + """ + The API client for the ThirdPartyApplication Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + third_party_application_rid: ThirdPartyApplicationRid, + *, + preview: Optional[PreviewMode] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ThirdPartyApplication]: + """ + Get the ThirdPartyApplication with the specified rid. + :param third_party_application_rid: thirdPartyApplicationRid + :type third_party_application_rid: ThirdPartyApplicationRid + :param preview: preview + :type preview: Optional[PreviewMode] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ThirdPartyApplication] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/thirdPartyApplications/{thirdPartyApplicationRid}", + query_params={ + "preview": preview, + }, + path_params={ + "thirdPartyApplicationRid": third_party_application_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ThirdPartyApplication, + request_timeout=request_timeout, + ), ) diff --git a/foundry/v2/third_party_applications/version.py b/foundry/v2/third_party_applications/version.py index f72f7958..c97db081 100644 --- a/foundry/v2/third_party_applications/version.py +++ b/foundry/v2/third_party_applications/version.py @@ -24,10 +24,12 @@ from typing_extensions import Annotated from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo from foundry._core import ResourceIterator +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.core.models._page_size import PageSize @@ -48,7 +50,7 @@ class VersionClient: The API client for the Version Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -59,6 +61,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _VersionClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _VersionClientRaw(auth=auth, hostname=hostname, config=config) @maybe_ignore_preview @pydantic.validate_call @@ -97,7 +103,7 @@ def delete( response_type=None, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -138,7 +144,7 @@ def get( response_type=Version, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -216,8 +222,9 @@ def page( """ warnings.warn( - "The VersionClient.page(...) method has been deprecated. Please use VersionClient.list(...) instead.", + "The client.third_party_applications.Version.page(...) method has been deprecated. Please use client.third_party_applications.Version.list(...) instead.", DeprecationWarning, + stacklevel=2, ) return self._api_client.call_api( @@ -239,7 +246,7 @@ def page( response_type=ListVersionsResponse, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -285,7 +292,7 @@ def upload( response_type=Version, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -340,4 +347,606 @@ def upload_snapshot( response_type=Version, request_timeout=request_timeout, ), + ).decode() + + +class _VersionClientRaw: + """ + The API client for the Version Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def delete( + self, + third_party_application_rid: ThirdPartyApplicationRid, + version_version: VersionVersion, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[None]: + """ + Delete the Version with the specified version. + :param third_party_application_rid: thirdPartyApplicationRid + :type third_party_application_rid: ThirdPartyApplicationRid + :param version_version: versionVersion + :type version_version: VersionVersion + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[None] + """ + + return self._api_client.call_api( + RequestInfo( + method="DELETE", + resource_path="/v2/thirdPartyApplications/{thirdPartyApplicationRid}/website/versions/{versionVersion}", + query_params={}, + path_params={ + "thirdPartyApplicationRid": third_party_application_rid, + "versionVersion": version_version, + }, + header_params={}, + body=None, + body_type=None, + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + third_party_application_rid: ThirdPartyApplicationRid, + version_version: VersionVersion, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Version]: + """ + Get the Version with the specified version. + :param third_party_application_rid: thirdPartyApplicationRid + :type third_party_application_rid: ThirdPartyApplicationRid + :param version_version: versionVersion + :type version_version: VersionVersion + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Version] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/thirdPartyApplications/{thirdPartyApplicationRid}/website/versions/{versionVersion}", + query_params={}, + path_params={ + "thirdPartyApplicationRid": third_party_application_rid, + "versionVersion": version_version, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Version, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + third_party_application_rid: ThirdPartyApplicationRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListVersionsResponse]: + """ + Lists all Versions. + + This is a paged endpoint. Each page may be smaller or larger than the requested page size. However, it is guaranteed that if there are more results available, the `nextPageToken` field will be populated. To get the next page, make the same request again, but set the value of the `pageToken` query parameter to be value of the `nextPageToken` value of the previous response. If there is no `nextPageToken` field in the response, you are on the last page. + :param third_party_application_rid: thirdPartyApplicationRid + :type third_party_application_rid: ThirdPartyApplicationRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListVersionsResponse] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/thirdPartyApplications/{thirdPartyApplicationRid}/website/versions", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={ + "thirdPartyApplicationRid": third_party_application_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListVersionsResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + third_party_application_rid: ThirdPartyApplicationRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[ListVersionsResponse]: + """ + Lists all Versions. + + This is a paged endpoint. Each page may be smaller or larger than the requested page size. However, it is guaranteed that if there are more results available, the `nextPageToken` field will be populated. To get the next page, make the same request again, but set the value of the `pageToken` query parameter to be value of the `nextPageToken` value of the previous response. If there is no `nextPageToken` field in the response, you are on the last page. + :param third_party_application_rid: thirdPartyApplicationRid + :type third_party_application_rid: ThirdPartyApplicationRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[ListVersionsResponse] + """ + + warnings.warn( + "The client.third_party_applications.Version.page(...) method has been deprecated. Please use client.third_party_applications.Version.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/thirdPartyApplications/{thirdPartyApplicationRid}/website/versions", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={ + "thirdPartyApplicationRid": third_party_application_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListVersionsResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def upload( + self, + third_party_application_rid: ThirdPartyApplicationRid, + body: bytes, + *, + version: VersionVersion, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Version]: + """ + Upload a new version of the Website. + :param third_party_application_rid: thirdPartyApplicationRid + :type third_party_application_rid: ThirdPartyApplicationRid + :param body: The zip file that contains the contents of your application. For more information, refer to the [documentation](/docs/foundry/ontology-sdk/deploy-osdk-application-on-foundry/) user documentation. + :type body: bytes + :param version: version + :type version: VersionVersion + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Version] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/thirdPartyApplications/{thirdPartyApplicationRid}/website/versions/upload", + query_params={ + "version": version, + }, + path_params={ + "thirdPartyApplicationRid": third_party_application_rid, + }, + header_params={ + "Content-Type": "application/octet-stream", + "Accept": "application/json", + }, + body=body, + body_type=bytes, + response_type=Version, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def upload_snapshot( + self, + third_party_application_rid: ThirdPartyApplicationRid, + body: bytes, + *, + version: VersionVersion, + preview: Optional[PreviewMode] = None, + snapshot_identifier: Optional[str] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Version]: + """ + Upload a snapshot version of the Website. Snapshot versions are automatically deleted after two days. + + :param third_party_application_rid: thirdPartyApplicationRid + :type third_party_application_rid: ThirdPartyApplicationRid + :param body: The zip file that contains the contents of your application. For more information, refer to the [documentation](/docs/foundry/ontology-sdk/deploy-osdk-application-on-foundry/) user documentation. + :type body: bytes + :param version: version + :type version: VersionVersion + :param preview: preview + :type preview: Optional[PreviewMode] + :param snapshot_identifier: snapshotIdentifier + :type snapshot_identifier: Optional[str] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Version] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/thirdPartyApplications/{thirdPartyApplicationRid}/website/versions/uploadSnapshot", + query_params={ + "version": version, + "preview": preview, + "snapshotIdentifier": snapshot_identifier, + }, + path_params={ + "thirdPartyApplicationRid": third_party_application_rid, + }, + header_params={ + "Content-Type": "application/octet-stream", + "Accept": "application/json", + }, + body=body, + body_type=bytes, + response_type=Version, + request_timeout=request_timeout, + ), + ) + + +class _VersionClientStreaming: + """ + The API client for the Version Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def delete( + self, + third_party_application_rid: ThirdPartyApplicationRid, + version_version: VersionVersion, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[None]: + """ + Delete the Version with the specified version. + :param third_party_application_rid: thirdPartyApplicationRid + :type third_party_application_rid: ThirdPartyApplicationRid + :param version_version: versionVersion + :type version_version: VersionVersion + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[None] + """ + + return self._api_client.stream_api( + RequestInfo( + method="DELETE", + resource_path="/v2/thirdPartyApplications/{thirdPartyApplicationRid}/website/versions/{versionVersion}", + query_params={}, + path_params={ + "thirdPartyApplicationRid": third_party_application_rid, + "versionVersion": version_version, + }, + header_params={}, + body=None, + body_type=None, + response_type=None, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + third_party_application_rid: ThirdPartyApplicationRid, + version_version: VersionVersion, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Version]: + """ + Get the Version with the specified version. + :param third_party_application_rid: thirdPartyApplicationRid + :type third_party_application_rid: ThirdPartyApplicationRid + :param version_version: versionVersion + :type version_version: VersionVersion + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Version] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/thirdPartyApplications/{thirdPartyApplicationRid}/website/versions/{versionVersion}", + query_params={}, + path_params={ + "thirdPartyApplicationRid": third_party_application_rid, + "versionVersion": version_version, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Version, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def list( + self, + third_party_application_rid: ThirdPartyApplicationRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListVersionsResponse]: + """ + Lists all Versions. + + This is a paged endpoint. Each page may be smaller or larger than the requested page size. However, it is guaranteed that if there are more results available, the `nextPageToken` field will be populated. To get the next page, make the same request again, but set the value of the `pageToken` query parameter to be value of the `nextPageToken` value of the previous response. If there is no `nextPageToken` field in the response, you are on the last page. + :param third_party_application_rid: thirdPartyApplicationRid + :type third_party_application_rid: ThirdPartyApplicationRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListVersionsResponse] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/thirdPartyApplications/{thirdPartyApplicationRid}/website/versions", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={ + "thirdPartyApplicationRid": third_party_application_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListVersionsResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def page( + self, + third_party_application_rid: ThirdPartyApplicationRid, + *, + page_size: Optional[PageSize] = None, + page_token: Optional[PageToken] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[ListVersionsResponse]: + """ + Lists all Versions. + + This is a paged endpoint. Each page may be smaller or larger than the requested page size. However, it is guaranteed that if there are more results available, the `nextPageToken` field will be populated. To get the next page, make the same request again, but set the value of the `pageToken` query parameter to be value of the `nextPageToken` value of the previous response. If there is no `nextPageToken` field in the response, you are on the last page. + :param third_party_application_rid: thirdPartyApplicationRid + :type third_party_application_rid: ThirdPartyApplicationRid + :param page_size: pageSize + :type page_size: Optional[PageSize] + :param page_token: pageToken + :type page_token: Optional[PageToken] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[ListVersionsResponse] + """ + + warnings.warn( + "The client.third_party_applications.Version.page(...) method has been deprecated. Please use client.third_party_applications.Version.list(...) instead.", + DeprecationWarning, + stacklevel=2, + ) + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/thirdPartyApplications/{thirdPartyApplicationRid}/website/versions", + query_params={ + "pageSize": page_size, + "pageToken": page_token, + }, + path_params={ + "thirdPartyApplicationRid": third_party_application_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=ListVersionsResponse, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def upload( + self, + third_party_application_rid: ThirdPartyApplicationRid, + body: bytes, + *, + version: VersionVersion, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Version]: + """ + Upload a new version of the Website. + :param third_party_application_rid: thirdPartyApplicationRid + :type third_party_application_rid: ThirdPartyApplicationRid + :param body: The zip file that contains the contents of your application. For more information, refer to the [documentation](/docs/foundry/ontology-sdk/deploy-osdk-application-on-foundry/) user documentation. + :type body: bytes + :param version: version + :type version: VersionVersion + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Version] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/thirdPartyApplications/{thirdPartyApplicationRid}/website/versions/upload", + query_params={ + "version": version, + }, + path_params={ + "thirdPartyApplicationRid": third_party_application_rid, + }, + header_params={ + "Content-Type": "application/octet-stream", + "Accept": "application/json", + }, + body=body, + body_type=bytes, + response_type=Version, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def upload_snapshot( + self, + third_party_application_rid: ThirdPartyApplicationRid, + body: bytes, + *, + version: VersionVersion, + preview: Optional[PreviewMode] = None, + snapshot_identifier: Optional[str] = None, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Version]: + """ + Upload a snapshot version of the Website. Snapshot versions are automatically deleted after two days. + + :param third_party_application_rid: thirdPartyApplicationRid + :type third_party_application_rid: ThirdPartyApplicationRid + :param body: The zip file that contains the contents of your application. For more information, refer to the [documentation](/docs/foundry/ontology-sdk/deploy-osdk-application-on-foundry/) user documentation. + :type body: bytes + :param version: version + :type version: VersionVersion + :param preview: preview + :type preview: Optional[PreviewMode] + :param snapshot_identifier: snapshotIdentifier + :type snapshot_identifier: Optional[str] + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Version] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/thirdPartyApplications/{thirdPartyApplicationRid}/website/versions/uploadSnapshot", + query_params={ + "version": version, + "preview": preview, + "snapshotIdentifier": snapshot_identifier, + }, + path_params={ + "thirdPartyApplicationRid": third_party_application_rid, + }, + header_params={ + "Content-Type": "application/octet-stream", + "Accept": "application/json", + }, + body=body, + body_type=bytes, + response_type=Version, + request_timeout=request_timeout, + ), ) diff --git a/foundry/v2/third_party_applications/website.py b/foundry/v2/third_party_applications/website.py index 6d533b0c..8f7ec3ab 100644 --- a/foundry/v2/third_party_applications/website.py +++ b/foundry/v2/third_party_applications/website.py @@ -24,9 +24,11 @@ from typing_extensions import TypedDict from foundry._core import ApiClient +from foundry._core import ApiResponse from foundry._core import Auth from foundry._core import Config from foundry._core import RequestInfo +from foundry._core import StreamingContextManager from foundry._core.utils import maybe_ignore_preview from foundry._errors import handle_unexpected from foundry.v2.third_party_applications.models._third_party_application_rid import ( @@ -42,7 +44,7 @@ class WebsiteClient: The API client for the Website Resource. :param auth: Your auth configuration. - :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. :param config: Optionally specify the configuration for the HTTP session. """ @@ -53,6 +55,10 @@ def __init__( config: Optional[Config] = None, ): self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + self.with_streaming_response = _WebsiteClientStreaming( + auth=auth, hostname=hostname, config=config + ) + self.with_raw_response = _WebsiteClientRaw(auth=auth, hostname=hostname, config=config) self.Version = VersionClient(auth=auth, hostname=hostname, config=config) @maybe_ignore_preview @@ -101,7 +107,7 @@ def deploy( response_type=Website, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -138,7 +144,7 @@ def get( response_type=Website, request_timeout=request_timeout, ), - ) + ).decode() @maybe_ignore_preview @pydantic.validate_call @@ -175,4 +181,284 @@ def undeploy( response_type=Website, request_timeout=request_timeout, ), + ).decode() + + +class _WebsiteClientRaw: + """ + The API client for the Website Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def deploy( + self, + third_party_application_rid: ThirdPartyApplicationRid, + *, + version: VersionVersion, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Website]: + """ + Deploy a version of the Website. + :param third_party_application_rid: thirdPartyApplicationRid + :type third_party_application_rid: ThirdPartyApplicationRid + :param version: + :type version: VersionVersion + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Website] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/thirdPartyApplications/{thirdPartyApplicationRid}/website/deploy", + query_params={}, + path_params={ + "thirdPartyApplicationRid": third_party_application_rid, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "version": version, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "version": VersionVersion, + }, + ), + response_type=Website, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + third_party_application_rid: ThirdPartyApplicationRid, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Website]: + """ + Get the Website. + :param third_party_application_rid: thirdPartyApplicationRid + :type third_party_application_rid: ThirdPartyApplicationRid + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Website] + """ + + return self._api_client.call_api( + RequestInfo( + method="GET", + resource_path="/v2/thirdPartyApplications/{thirdPartyApplicationRid}/website", + query_params={}, + path_params={ + "thirdPartyApplicationRid": third_party_application_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Website, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def undeploy( + self, + third_party_application_rid: ThirdPartyApplicationRid, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> ApiResponse[Website]: + """ + Remove the currently deployed version of the Website. + :param third_party_application_rid: thirdPartyApplicationRid + :type third_party_application_rid: ThirdPartyApplicationRid + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: ApiResponse[Website] + """ + + return self._api_client.call_api( + RequestInfo( + method="POST", + resource_path="/v2/thirdPartyApplications/{thirdPartyApplicationRid}/website/undeploy", + query_params={}, + path_params={ + "thirdPartyApplicationRid": third_party_application_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Website, + request_timeout=request_timeout, + ), + ) + + +class _WebsiteClientStreaming: + """ + The API client for the Website Resource. + + :param auth: Your auth configuration. + :param hostname: Your Foundry hostname (for example, "myfoundry.palantirfoundry.com"). This can also include your API gateway service URI. + :param config: Optionally specify the configuration for the HTTP session. + """ + + def __init__( + self, + auth: Auth, + hostname: str, + config: Optional[Config] = None, + ): + self._api_client = ApiClient(auth=auth, hostname=hostname, config=config) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def deploy( + self, + third_party_application_rid: ThirdPartyApplicationRid, + *, + version: VersionVersion, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Website]: + """ + Deploy a version of the Website. + :param third_party_application_rid: thirdPartyApplicationRid + :type third_party_application_rid: ThirdPartyApplicationRid + :param version: + :type version: VersionVersion + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Website] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/thirdPartyApplications/{thirdPartyApplicationRid}/website/deploy", + query_params={}, + path_params={ + "thirdPartyApplicationRid": third_party_application_rid, + }, + header_params={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + body={ + "version": version, + }, + body_type=TypedDict( + "Body", + { # type: ignore + "version": VersionVersion, + }, + ), + response_type=Website, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def get( + self, + third_party_application_rid: ThirdPartyApplicationRid, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Website]: + """ + Get the Website. + :param third_party_application_rid: thirdPartyApplicationRid + :type third_party_application_rid: ThirdPartyApplicationRid + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Website] + """ + + return self._api_client.stream_api( + RequestInfo( + method="GET", + resource_path="/v2/thirdPartyApplications/{thirdPartyApplicationRid}/website", + query_params={}, + path_params={ + "thirdPartyApplicationRid": third_party_application_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Website, + request_timeout=request_timeout, + ), + ) + + @maybe_ignore_preview + @pydantic.validate_call + @handle_unexpected + def undeploy( + self, + third_party_application_rid: ThirdPartyApplicationRid, + *, + request_timeout: Optional[Annotated[pydantic.StrictInt, pydantic.Field(gt=0)]] = None, + ) -> StreamingContextManager[Website]: + """ + Remove the currently deployed version of the Website. + :param third_party_application_rid: thirdPartyApplicationRid + :type third_party_application_rid: ThirdPartyApplicationRid + :param request_timeout: timeout setting for this request in seconds. + :type request_timeout: Optional[int] + :return: Returns the result object. + :rtype: StreamingContextManager[Website] + """ + + return self._api_client.stream_api( + RequestInfo( + method="POST", + resource_path="/v2/thirdPartyApplications/{thirdPartyApplicationRid}/website/undeploy", + query_params={}, + path_params={ + "thirdPartyApplicationRid": third_party_application_rid, + }, + header_params={ + "Accept": "application/json", + }, + body=None, + body_type=None, + response_type=Website, + request_timeout=request_timeout, + ), ) diff --git a/tests/auth/test_confidential_client.py b/tests/auth/test_confidential_client.py index c42e771d..ba4565ef 100644 --- a/tests/auth/test_confidential_client.py +++ b/tests/auth/test_confidential_client.py @@ -64,6 +64,21 @@ async def test_confidential_client_sign_in_as_service_user(): unstub() +def test_confidential_client_url(): + assert ( + ConfidentialClientAuth(client_id="", client_secret="", hostname="https://a.b.c.com").url + == "a.b.c.com" + ) + assert ( + ConfidentialClientAuth(client_id="", client_secret="", hostname="http://a.b.c.com").url + == "a.b.c.com" + ) + assert ( + ConfidentialClientAuth(client_id="", client_secret="", hostname="a.b.c.com/").url + == "a.b.c.com" + ) + + def test_confidential_client_get_token(): auth = ConfidentialClientAuth( client_id="client_id", client_secret="client_secret", hostname="https://a.b.c.com" diff --git a/tests/auth/test_public_client.py b/tests/auth/test_public_client.py index 281fd7c1..e5b851e6 100644 --- a/tests/auth/test_public_client.py +++ b/tests/auth/test_public_client.py @@ -82,6 +82,18 @@ async def test_public_client_set_token(): unstub() +def test_public_client_url(): + assert ( + PublicClientAuth(client_id="", redirect_url="", hostname="https://a.b.c.com").url + == "a.b.c.com" + ) + assert ( + PublicClientAuth(client_id="", redirect_url="", hostname="http://a.b.c.com").url + == "a.b.c.com" + ) + assert PublicClientAuth(client_id="", redirect_url="", hostname="a.b.c.com/").url == "a.b.c.com" + + def test_public_client_get_token(): auth = PublicClientAuth( client_id="client_id", diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 00000000..7d29adc2 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,36 @@ +# Copyright 2024 Palantir Technologies, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +import subprocess +import time + +import pytest + +PORT = 8123 + + +@pytest.fixture(scope="session", autouse=True) +def fastapi_server(): + # Start the server + process = subprocess.Popen( + ["uvicorn", "tests.server:app", "--host", "127.0.0.1", "--port", str(PORT)] + ) + time.sleep(2) # Wait a moment for the server to start + + yield + + # Teardown: Stop the server + process.terminate() + process.wait() diff --git a/tests/server.py b/tests/server.py new file mode 100644 index 00000000..8805bb8c --- /dev/null +++ b/tests/server.py @@ -0,0 +1,56 @@ +# Copyright 2024 Palantir Technologies, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +import time + +from fastapi import APIRouter +from fastapi import FastAPI +from fastapi.responses import StreamingResponse +from pydantic import BaseModel + +app = FastAPI() +router = APIRouter() + + +class FooBar(BaseModel): + foo: str + bar: int + + +@router.get("/foo/bar", response_model=FooBar) +def foo_bar() -> FooBar: + return FooBar(foo="foo", bar=2) + + +@router.get("/foo/timeout", response_model=FooBar) +def timeout() -> FooBar: + time.sleep(10) + return FooBar(foo="foo", bar=2) + + +@router.get("/foo/stream") +def stream() -> StreamingResponse: + content = "foo\nbar\nbaz" + + def generate_data(): + lines = content.split("\n") + for i, line in enumerate(lines): + is_final_line = i == len(lines) - 1 + yield line if is_final_line else line + "\n" + + return StreamingResponse(generate_data(), media_type="text/plain") + + +app.include_router(router, prefix="/api") diff --git a/tests/test_api_client.py b/tests/test_api_client.py index 53404163..79491bef 100644 --- a/tests/test_api_client.py +++ b/tests/test_api_client.py @@ -18,6 +18,7 @@ import warnings from typing import Any from typing import Dict +from typing import Literal from typing import Optional from typing import cast from unittest.mock import ANY @@ -26,13 +27,27 @@ import pytest import requests +from foundry import BadRequestError +from foundry import ConnectionError +from foundry import InternalServerError +from foundry import NotFoundError from foundry import PalantirRPCException +from foundry import PermissionDeniedError +from foundry import ProxyError +from foundry import RateLimitError +from foundry import ReadTimeout +from foundry import SSLError +from foundry import StreamConsumedError +from foundry import UnauthorizedError +from foundry import UnprocessableEntityError from foundry import UserTokenAuth from foundry import __version__ from foundry._core import ApiClient from foundry._core import RequestInfo from foundry._core.config import Config +HOSTNAME = "localhost:8123" + class AttrDict(Dict[str, Any]): def __init__(self, *args: Any, **kwargs: Any): @@ -66,20 +81,56 @@ def assert_called_with(client: ApiClient, **kwargs): ) -def create_client(config: Optional[Config] = None): - client = ApiClient(auth=UserTokenAuth(token="bar"), hostname="foo", config=config) +def _throw(exception: Exception): + def wrapper(*_args, **_kwargs): + raise exception + + return wrapper + + +def create_mock_client(config: Optional[Config] = None, hostname=HOSTNAME): + client = ApiClient(auth=UserTokenAuth(token="bar"), hostname=hostname, config=config) client._session.request = Mock(return_value=AttrDict(status_code=200, headers={})) return client +def create_client( + config: Optional[Config] = None, + hostname=HOSTNAME, + scheme: Literal["https", "http"] = "http", +): + config = config or Config() + config.scheme = scheme + return ApiClient(auth=UserTokenAuth(token="bar"), hostname=hostname, config=config) + + +def test_client_hostname(): + assert ( + ApiClient( + auth=UserTokenAuth(token="bar"), hostname="https://a.b.c.com", config=None + )._hostname + == "a.b.c.com" + ) + assert ( + ApiClient( + auth=UserTokenAuth(token="bar"), hostname="http://a.b.c.com", config=None + )._hostname + == "a.b.c.com" + ) + assert ( + ApiClient(auth=UserTokenAuth(token="bar"), hostname="a.b.c.com/", config=None)._hostname + == "a.b.c.com" + ) + + def test_can_override_session_using_deprecated_method(): - client = create_client() + client = create_mock_client() assert isinstance(client.session._session, requests.Session) client.session._session.headers["Foo"] = "Bar" def test_accessing_session_emits_warnings(): - client = create_client() + client = create_mock_client() with warnings.catch_warnings(record=True) as w: client.session assert len(w) == 1 @@ -87,7 +138,7 @@ def test_accessing_session_emits_warnings(): def test_default_headers(): """Test that the user agent is set correctly.""" - client = create_client() + client = create_mock_client() assert client._session.headers == { "Accept-Encoding": "gzip, deflate", "Accept": "*/*", @@ -96,7 +147,7 @@ def test_default_headers(): } """Test that additional headers can be added.""" - client = create_client(Config(default_headers={"Foo": "Bar"})) + client = create_mock_client(Config(default_headers={"Foo": "Bar"})) assert client._session.headers == { "Accept-Encoding": "gzip, deflate", "Accept": "*/*", @@ -107,19 +158,21 @@ def test_default_headers(): def test_authorization_header(): - client = create_client() + client = create_mock_client() client.call_api(RequestInfo.with_defaults("GET", "/foo/bar")) # Ensure the bearer token gets added to the headers assert_called_with(client, headers={"Authorization": "Bearer bar"}) def test_proxies(): - client = create_client(Config(proxies={"https": "https://foo.bar", "http": "http://foo.bar"})) + client = create_mock_client( + Config(proxies={"https": "https://foo.bar", "http": "http://foo.bar"}) + ) assert client._session.proxies == {"https": "https://foo.bar", "http": "http://foo.bar"} def test_timeout(): - client = create_client(config=Config(timeout=60)) + client = create_mock_client(config=Config(timeout=60)) client.call_api(RequestInfo.with_defaults("GET", "/foo/bar", request_timeout=None)) assert_called_with(client, timeout=60) @@ -129,30 +182,30 @@ def test_timeout(): def test_verify(): - client = create_client() + client = create_mock_client() assert client._session.verify == True - client = create_client(Config(verify=False)) + client = create_mock_client(Config(verify=False)) assert client._session.verify == False def test_default_params(): - client = create_client(Config(default_params={"foo": "bar"})) + client = create_mock_client(Config(default_params={"foo": "bar"})) assert client._session.params == {"foo": "bar"} def test_scheme(): - client = create_client() + client = create_mock_client() client.call_api(RequestInfo.with_defaults("GET", "/foo/bar", request_timeout=30)) - assert_called_with(client, url="https://foo/api/foo/bar") + assert_called_with(client, url="https://localhost:8123/api/foo/bar") - client = create_client(Config(scheme="http")) + client = create_mock_client(Config(scheme="http")) client.call_api(RequestInfo.with_defaults("GET", "/foo/bar", request_timeout=30)) - assert_called_with(client, url="http://foo/api/foo/bar") + assert_called_with(client, url="http://localhost:8123/api/foo/bar") def test_path_encoding(): - client = create_client() + client = create_mock_client() client.call_api( RequestInfo.with_defaults( @@ -162,12 +215,12 @@ def test_path_encoding(): ) ) - assert_called_with(client, url="https://foo/api/files/%2Fmy%2Ffile.txt") + assert_called_with(client, url="https://localhost:8123/api/files/%2Fmy%2Ffile.txt") def test_shared_connection_pool(): - client1 = create_client() - client2 = create_client() + client1 = create_mock_client() + client2 = create_mock_client() session1 = client1._session session2 = client2._session @@ -183,7 +236,7 @@ def test_shared_connection_pool(): def call_api_helper( status_code: int, data: str, - headers: Dict[str, str], + headers: Dict[str, str] = {}, ): client = ApiClient(auth=UserTokenAuth(token="bar"), hostname="foo") @@ -213,7 +266,7 @@ def call_api_helper( def test_call_api_400(): - with pytest.raises(PalantirRPCException) as info: + with pytest.raises(BadRequestError) as info: call_api_helper(status_code=400, data=EXAMPLE_ERROR, headers={"Header": "A"}) assert info.value.name == "ERROR_NAME" @@ -221,21 +274,97 @@ def test_call_api_400(): assert info.value.parameters == {} -def test_call_api_403(): - with pytest.raises(PalantirRPCException): - call_api_helper(status_code=403, data=EXAMPLE_ERROR, headers={"Ha": "Ha"}) +def test_401_error(): + with pytest.raises(UnauthorizedError): + call_api_helper(status_code=401, data=EXAMPLE_ERROR) -def test_call_api_404(): - with pytest.raises(PalantirRPCException): - call_api_helper(status_code=404, data=EXAMPLE_ERROR, headers={"Ha": "Ha"}) +def test_403_error(): + with pytest.raises(PermissionDeniedError): + call_api_helper(status_code=403, data=EXAMPLE_ERROR) + + +def test_404_error(): + with pytest.raises(NotFoundError): + call_api_helper(status_code=404, data=EXAMPLE_ERROR) + + +def test_422_error(): + with pytest.raises(UnprocessableEntityError): + call_api_helper(status_code=422, data=EXAMPLE_ERROR) + + +def test_429_error(): + with pytest.raises(RateLimitError): + call_api_helper(status_code=429, data=EXAMPLE_ERROR) def test_call_api_500(): - with pytest.raises(PalantirRPCException): - call_api_helper(status_code=500, data=EXAMPLE_ERROR, headers={"Ha": "Ha"}) + with pytest.raises(InternalServerError): + call_api_helper(status_code=500, data=EXAMPLE_ERROR) -def test_call_api_333(): +def test_call_api_599(): + with pytest.raises(InternalServerError): + call_api_helper(status_code=599, data=EXAMPLE_ERROR) + + +def test_call_api_600(): with pytest.raises(PalantirRPCException): - call_api_helper(status_code=333, data=EXAMPLE_ERROR, headers={"Ha": "Ha"}) + call_api_helper(status_code=600, data=EXAMPLE_ERROR) + + +def test_cannot_cause_invalid_url_error(): + client = create_client() + request_info = RequestInfo.with_defaults("GET", "/foo/{bar}", path_params={"bar": "|https://"}) + + # This confirms that the path parameters are encoded since "|https://" in a URL is invalid + # The encoded path doesn't exist so we get back a 404 error + with pytest.raises(NotFoundError): + client.call_api(request_info) + + +def test_connect_timeout(): + client = create_client(hostname="thishostdoesnotexist.invalid", config=Config(timeout=0.5)) + request_info = RequestInfo.with_defaults("GET", "/foo/bar") + + with pytest.raises(ConnectionError): + client.call_api(request_info) + + +def test_read_timeout(): + client = create_client(config=Config(timeout=0.5)) + request_info = RequestInfo.with_defaults("GET", "/foo/timeout") + + with pytest.raises(ReadTimeout): + client.call_api(request_info) + + +def test_stream_consumed_error(): + client = create_client() + request_info = RequestInfo.with_defaults("GET", "/foo/stream", stream=True) + + with client.stream_api(request_info) as response: + for _ in response.iter_bytes(): + pass + + with pytest.raises(StreamConsumedError): + for _ in response.iter_bytes(): + pass + + +def test_proxy_error(): + client = create_client() + request_info = RequestInfo.with_defaults("GET", "/foo/bar") + client._session.proxies = {"http": "http://invalid-proxy-url"} + + with pytest.raises(ProxyError): + client.call_api(request_info) + + +def test_ssl_error(): + client = create_client(scheme="https", config=Config(timeout=1)) + request_info = RequestInfo.with_defaults("GET", "localhost:8123") + + with pytest.raises(SSLError): + client.call_api(request_info) diff --git a/tests/test_exception.py b/tests/test_exception.py index 2ad79e73..a38b340f 100644 --- a/tests/test_exception.py +++ b/tests/test_exception.py @@ -13,16 +13,40 @@ # limitations under the License. +import inspect import json import re +import sys +from types import ModuleType +from typing import List +from typing import Type +import pydantic import pytest +from foundry import _errors from foundry._errors.palantir_rpc_exception import PalantirRPCException +from foundry._errors.sdk_internal_error import PalantirException from foundry._errors.sdk_internal_error import SDKInternalError from foundry._errors.sdk_internal_error import handle_unexpected +def find_exception_subclasses(module: ModuleType) -> List[Type[Exception]]: + exception_subclasses = [] + + # Get all members of the module + members = inspect.getmembers(module) + + for name, obj in members: + # Check if the member is a class + if inspect.isclass(obj): + # Check if the class is a subclass of Exception + if issubclass(obj, Exception): + exception_subclasses.append(obj) + + return exception_subclasses + + def test_sdk_internal_error(): with pytest.raises(SDKInternalError) as error: raise SDKInternalError("test") @@ -56,19 +80,29 @@ def raises_unknown_exception(): assert error.value.msg == "test" -def test_handle_unexpected_ignores_known_exception(): +def test_all_errors_subclass_palantir_exception(): + classes = find_exception_subclasses(_errors) + assert len(classes) >= 5 # sanity check we are finding the classes + for klass in find_exception_subclasses(_errors): + assert issubclass(klass, PalantirException) + + +def test_handle_unexpected_ignores_palantir_exception(): @handle_unexpected def raises_known_exception(): - raise PalantirRPCException({"errorName": "", "parameters": "", "errorInstanceId": ""}) + raise PalantirException("Foo") - with pytest.raises(PalantirRPCException) as error: + with pytest.raises(PalantirException): raises_known_exception() - assert str(error.value) == json.dumps( - { - "errorInstanceId": "", - "errorName": "", - "parameters": "", - }, - indent=4, - ) + +def test_handle_unexpected_ignores_validation_error(): + class Model(pydantic.BaseModel): + foo: str + + @handle_unexpected + def raises_known_exception(): + Model.model_validate({"foo": 123}) + + with pytest.raises(pydantic.ValidationError): + raises_known_exception() diff --git a/tests/test_utils.py b/tests/test_utils.py index eb8a9509..9824ad93 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -7,6 +7,7 @@ from foundry._core.utils import RID from foundry._core.utils import UUID from foundry._core.utils import Long +from foundry._core.utils import clean_hostname from foundry._core.utils import maybe_ignore_preview from foundry._core.utils import remove_prefixes @@ -17,6 +18,13 @@ def test_remove_prefixes(): assert remove_prefixes("example.com", ["https://", "http://"]) == "example.com" +def test_clean_hostname(): + assert clean_hostname("http://example.com") == "example.com" + assert clean_hostname("https://example.com") == "example.com" + assert clean_hostname("example.com/") == "example.com" + assert clean_hostname("example.com") == "example.com" + + def test_no_warning_when_preview_not_passed(): @maybe_ignore_preview def my_func_without_preview(preview: bool = False):