# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. from __future__ import annotations from typing import Optional import httpx from .files import ( FilesResource, AsyncFilesResource, FilesResourceWithRawResponse, AsyncFilesResourceWithRawResponse, FilesResourceWithStreamingResponse, AsyncFilesResourceWithStreamingResponse, ) from ...types import dataset_list_params, dataset_create_params, dataset_update_params from ..._types import Body, Omit, Query, Headers, NoneType, NotGiven, omit, not_given from ..._utils import path_template, maybe_transform, async_maybe_transform from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource from ..._response import ( to_raw_response_wrapper, to_streamed_response_wrapper, async_to_raw_response_wrapper, async_to_streamed_response_wrapper, ) from ...pagination import SyncCursorIDPage, AsyncCursorIDPage from ..._base_client import AsyncPaginator, make_request_options from ...types.dataset import Dataset __all__ = ["DatasetsResource", "AsyncDatasetsResource"] class DatasetsResource(SyncAPIResource): @cached_property def files(self) -> FilesResource: return FilesResource(self._client) @cached_property def with_raw_response(self) -> DatasetsResourceWithRawResponse: """ This property can be used as a prefix for any HTTP method call to return the raw response object instead of the parsed content. For more information, see https://www.github.com/cartesia-ai/cartesia-python#accessing-raw-response-data-eg-headers """ return DatasetsResourceWithRawResponse(self) @cached_property def with_streaming_response(self) -> DatasetsResourceWithStreamingResponse: """ An alternative to `.with_raw_response` that doesn't eagerly read the response body. For more information, see https://www.github.com/cartesia-ai/cartesia-python#with_streaming_response """ return DatasetsResourceWithStreamingResponse(self) def create( self, *, description: str, name: str, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> Dataset: """ Create a new dataset Args: description: Optional description for the dataset name: Name for the new dataset extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ return self._post( "/datasets/", body=maybe_transform( { "description": description, "name": name, }, dataset_create_params.DatasetCreateParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=Dataset, ) def retrieve( self, id: str, *, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> Dataset: """ Retrieve a specific dataset by ID Args: extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not id: raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") return self._get( path_template("/datasets/{id}", id=id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=Dataset, ) def update( self, id: str, *, description: str, name: str, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> None: """ Update an existing dataset Args: description: New description for the dataset name: New name for the dataset extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not id: raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return self._patch( path_template("/datasets/{id}", id=id), body=maybe_transform( { "description": description, "name": name, }, dataset_update_params.DatasetUpdateParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=NoneType, ) def list( self, *, ending_before: Optional[str] | Omit = omit, limit: Optional[int] | Omit = omit, starting_after: Optional[str] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> SyncCursorIDPage[Dataset]: """Paginated list of datasets Args: ending_before: A cursor to use in pagination. `ending_before` is a Dataset ID that defines your place in the list. For example, if you make a /datasets request and receive 20 objects, starting with `dataset_abc123`, your subsequent call can include `ending_before=dataset_abc123` to fetch the previous page of the list. limit: The number of Datasets to return per page, ranging between 1 and 100. starting_after: A cursor to use in pagination. `starting_after` is a Dataset ID that defines your place in the list. For example, if you make a /datasets request and receive 20 objects, ending with `dataset_abc123`, your subsequent call can include `starting_after=dataset_abc123` to fetch the next page of the list. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ return self._get_api_list( "/datasets/", page=SyncCursorIDPage[Dataset], options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout, query=maybe_transform( { "ending_before": ending_before, "limit": limit, "starting_after": starting_after, }, dataset_list_params.DatasetListParams, ), ), model=Dataset, ) def delete( self, id: str, *, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> None: """ Delete a dataset Args: extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not id: raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return self._delete( path_template("/datasets/{id}", id=id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=NoneType, ) class AsyncDatasetsResource(AsyncAPIResource): @cached_property def files(self) -> AsyncFilesResource: return AsyncFilesResource(self._client) @cached_property def with_raw_response(self) -> AsyncDatasetsResourceWithRawResponse: """ This property can be used as a prefix for any HTTP method call to return the raw response object instead of the parsed content. For more information, see https://www.github.com/cartesia-ai/cartesia-python#accessing-raw-response-data-eg-headers """ return AsyncDatasetsResourceWithRawResponse(self) @cached_property def with_streaming_response(self) -> AsyncDatasetsResourceWithStreamingResponse: """ An alternative to `.with_raw_response` that doesn't eagerly read the response body. For more information, see https://www.github.com/cartesia-ai/cartesia-python#with_streaming_response """ return AsyncDatasetsResourceWithStreamingResponse(self) async def create( self, *, description: str, name: str, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> Dataset: """ Create a new dataset Args: description: Optional description for the dataset name: Name for the new dataset extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ return await self._post( "/datasets/", body=await async_maybe_transform( { "description": description, "name": name, }, dataset_create_params.DatasetCreateParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=Dataset, ) async def retrieve( self, id: str, *, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> Dataset: """ Retrieve a specific dataset by ID Args: extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not id: raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") return await self._get( path_template("/datasets/{id}", id=id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=Dataset, ) async def update( self, id: str, *, description: str, name: str, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> None: """ Update an existing dataset Args: description: New description for the dataset name: New name for the dataset extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not id: raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return await self._patch( path_template("/datasets/{id}", id=id), body=await async_maybe_transform( { "description": description, "name": name, }, dataset_update_params.DatasetUpdateParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=NoneType, ) def list( self, *, ending_before: Optional[str] | Omit = omit, limit: Optional[int] | Omit = omit, starting_after: Optional[str] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> AsyncPaginator[Dataset, AsyncCursorIDPage[Dataset]]: """Paginated list of datasets Args: ending_before: A cursor to use in pagination. `ending_before` is a Dataset ID that defines your place in the list. For example, if you make a /datasets request and receive 20 objects, starting with `dataset_abc123`, your subsequent call can include `ending_before=dataset_abc123` to fetch the previous page of the list. limit: The number of Datasets to return per page, ranging between 1 and 100. starting_after: A cursor to use in pagination. `starting_after` is a Dataset ID that defines your place in the list. For example, if you make a /datasets request and receive 20 objects, ending with `dataset_abc123`, your subsequent call can include `starting_after=dataset_abc123` to fetch the next page of the list. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ return self._get_api_list( "/datasets/", page=AsyncCursorIDPage[Dataset], options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout, query=maybe_transform( { "ending_before": ending_before, "limit": limit, "starting_after": starting_after, }, dataset_list_params.DatasetListParams, ), ), model=Dataset, ) async def delete( self, id: str, *, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> None: """ Delete a dataset Args: extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not id: raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return await self._delete( path_template("/datasets/{id}", id=id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=NoneType, ) class DatasetsResourceWithRawResponse: def __init__(self, datasets: DatasetsResource) -> None: self._datasets = datasets self.create = to_raw_response_wrapper( datasets.create, ) self.retrieve = to_raw_response_wrapper( datasets.retrieve, ) self.update = to_raw_response_wrapper( datasets.update, ) self.list = to_raw_response_wrapper( datasets.list, ) self.delete = to_raw_response_wrapper( datasets.delete, ) @cached_property def files(self) -> FilesResourceWithRawResponse: return FilesResourceWithRawResponse(self._datasets.files) class AsyncDatasetsResourceWithRawResponse: def __init__(self, datasets: AsyncDatasetsResource) -> None: self._datasets = datasets self.create = async_to_raw_response_wrapper( datasets.create, ) self.retrieve = async_to_raw_response_wrapper( datasets.retrieve, ) self.update = async_to_raw_response_wrapper( datasets.update, ) self.list = async_to_raw_response_wrapper( datasets.list, ) self.delete = async_to_raw_response_wrapper( datasets.delete, ) @cached_property def files(self) -> AsyncFilesResourceWithRawResponse: return AsyncFilesResourceWithRawResponse(self._datasets.files) class DatasetsResourceWithStreamingResponse: def __init__(self, datasets: DatasetsResource) -> None: self._datasets = datasets self.create = to_streamed_response_wrapper( datasets.create, ) self.retrieve = to_streamed_response_wrapper( datasets.retrieve, ) self.update = to_streamed_response_wrapper( datasets.update, ) self.list = to_streamed_response_wrapper( datasets.list, ) self.delete = to_streamed_response_wrapper( datasets.delete, ) @cached_property def files(self) -> FilesResourceWithStreamingResponse: return FilesResourceWithStreamingResponse(self._datasets.files) class AsyncDatasetsResourceWithStreamingResponse: def __init__(self, datasets: AsyncDatasetsResource) -> None: self._datasets = datasets self.create = async_to_streamed_response_wrapper( datasets.create, ) self.retrieve = async_to_streamed_response_wrapper( datasets.retrieve, ) self.update = async_to_streamed_response_wrapper( datasets.update, ) self.list = async_to_streamed_response_wrapper( datasets.list, ) self.delete = async_to_streamed_response_wrapper( datasets.delete, ) @cached_property def files(self) -> AsyncFilesResourceWithStreamingResponse: return AsyncFilesResourceWithStreamingResponse(self._datasets.files)