diff --git a/.stats.yml b/.stats.yml index de479128..af63a6f7 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1 +1 @@ -configured_endpoints: 9 +configured_endpoints: 10 diff --git a/api.md b/api.md index f9e3456e..83a58532 100644 --- a/api.md +++ b/api.md @@ -87,3 +87,17 @@ from openlayer.types.inference_pipelines import TestResultListResponse Methods: - client.inference_pipelines.test_results.list(inference_pipeline_id, \*\*params) -> TestResultListResponse + +# Storage + +## PresignedURL + +Types: + +```python +from openlayer.types.storage import PresignedURLCreateResponse +``` + +Methods: + +- client.storage.presigned_url.create(\*\*params) -> PresignedURLCreateResponse diff --git a/src/openlayer/_client.py b/src/openlayer/_client.py index 4188cb39..008dee8a 100644 --- a/src/openlayer/_client.py +++ b/src/openlayer/_client.py @@ -50,6 +50,7 @@ class Openlayer(SyncAPIClient): projects: resources.ProjectsResource commits: resources.CommitsResource inference_pipelines: resources.InferencePipelinesResource + storage: resources.StorageResource with_raw_response: OpenlayerWithRawResponse with_streaming_response: OpenlayerWithStreamedResponse @@ -106,6 +107,7 @@ def __init__( self.projects = resources.ProjectsResource(self) self.commits = resources.CommitsResource(self) self.inference_pipelines = resources.InferencePipelinesResource(self) + self.storage = resources.StorageResource(self) self.with_raw_response = OpenlayerWithRawResponse(self) self.with_streaming_response = OpenlayerWithStreamedResponse(self) @@ -231,6 +233,7 @@ class AsyncOpenlayer(AsyncAPIClient): projects: resources.AsyncProjectsResource commits: resources.AsyncCommitsResource inference_pipelines: resources.AsyncInferencePipelinesResource + storage: resources.AsyncStorageResource with_raw_response: AsyncOpenlayerWithRawResponse with_streaming_response: AsyncOpenlayerWithStreamedResponse @@ -287,6 +290,7 @@ def __init__( self.projects = resources.AsyncProjectsResource(self) self.commits = resources.AsyncCommitsResource(self) self.inference_pipelines = resources.AsyncInferencePipelinesResource(self) + self.storage = resources.AsyncStorageResource(self) self.with_raw_response = AsyncOpenlayerWithRawResponse(self) self.with_streaming_response = AsyncOpenlayerWithStreamedResponse(self) @@ -413,6 +417,7 @@ def __init__(self, client: Openlayer) -> None: self.projects = resources.ProjectsResourceWithRawResponse(client.projects) self.commits = resources.CommitsResourceWithRawResponse(client.commits) self.inference_pipelines = resources.InferencePipelinesResourceWithRawResponse(client.inference_pipelines) + self.storage = resources.StorageResourceWithRawResponse(client.storage) class AsyncOpenlayerWithRawResponse: @@ -420,6 +425,7 @@ def __init__(self, client: AsyncOpenlayer) -> None: self.projects = resources.AsyncProjectsResourceWithRawResponse(client.projects) self.commits = resources.AsyncCommitsResourceWithRawResponse(client.commits) self.inference_pipelines = resources.AsyncInferencePipelinesResourceWithRawResponse(client.inference_pipelines) + self.storage = resources.AsyncStorageResourceWithRawResponse(client.storage) class OpenlayerWithStreamedResponse: @@ -427,6 +433,7 @@ def __init__(self, client: Openlayer) -> None: self.projects = resources.ProjectsResourceWithStreamingResponse(client.projects) self.commits = resources.CommitsResourceWithStreamingResponse(client.commits) self.inference_pipelines = resources.InferencePipelinesResourceWithStreamingResponse(client.inference_pipelines) + self.storage = resources.StorageResourceWithStreamingResponse(client.storage) class AsyncOpenlayerWithStreamedResponse: @@ -436,6 +443,7 @@ def __init__(self, client: AsyncOpenlayer) -> None: self.inference_pipelines = resources.AsyncInferencePipelinesResourceWithStreamingResponse( client.inference_pipelines ) + self.storage = resources.AsyncStorageResourceWithStreamingResponse(client.storage) Client = Openlayer diff --git a/src/openlayer/resources/__init__.py b/src/openlayer/resources/__init__.py index 28cab671..22b4e14c 100644 --- a/src/openlayer/resources/__init__.py +++ b/src/openlayer/resources/__init__.py @@ -8,6 +8,14 @@ CommitsResourceWithStreamingResponse, AsyncCommitsResourceWithStreamingResponse, ) +from .storage import ( + StorageResource, + AsyncStorageResource, + StorageResourceWithRawResponse, + AsyncStorageResourceWithRawResponse, + StorageResourceWithStreamingResponse, + AsyncStorageResourceWithStreamingResponse, +) from .projects import ( ProjectsResource, AsyncProjectsResource, @@ -44,4 +52,10 @@ "AsyncInferencePipelinesResourceWithRawResponse", "InferencePipelinesResourceWithStreamingResponse", "AsyncInferencePipelinesResourceWithStreamingResponse", + "StorageResource", + "AsyncStorageResource", + "StorageResourceWithRawResponse", + "AsyncStorageResourceWithRawResponse", + "StorageResourceWithStreamingResponse", + "AsyncStorageResourceWithStreamingResponse", ] diff --git a/src/openlayer/resources/storage/__init__.py b/src/openlayer/resources/storage/__init__.py new file mode 100644 index 00000000..5de9b8e8 --- /dev/null +++ b/src/openlayer/resources/storage/__init__.py @@ -0,0 +1,33 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from .storage import ( + StorageResource, + AsyncStorageResource, + StorageResourceWithRawResponse, + AsyncStorageResourceWithRawResponse, + StorageResourceWithStreamingResponse, + AsyncStorageResourceWithStreamingResponse, +) +from .presigned_url import ( + PresignedURLResource, + AsyncPresignedURLResource, + PresignedURLResourceWithRawResponse, + AsyncPresignedURLResourceWithRawResponse, + PresignedURLResourceWithStreamingResponse, + AsyncPresignedURLResourceWithStreamingResponse, +) + +__all__ = [ + "PresignedURLResource", + "AsyncPresignedURLResource", + "PresignedURLResourceWithRawResponse", + "AsyncPresignedURLResourceWithRawResponse", + "PresignedURLResourceWithStreamingResponse", + "AsyncPresignedURLResourceWithStreamingResponse", + "StorageResource", + "AsyncStorageResource", + "StorageResourceWithRawResponse", + "AsyncStorageResourceWithRawResponse", + "StorageResourceWithStreamingResponse", + "AsyncStorageResourceWithStreamingResponse", +] diff --git a/src/openlayer/resources/storage/presigned_url.py b/src/openlayer/resources/storage/presigned_url.py new file mode 100644 index 00000000..ad2990e5 --- /dev/null +++ b/src/openlayer/resources/storage/presigned_url.py @@ -0,0 +1,158 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +import httpx + +from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven +from ..._utils import ( + 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 ..._base_client import make_request_options +from ...types.storage import presigned_url_create_params +from ...types.storage.presigned_url_create_response import PresignedURLCreateResponse + +__all__ = ["PresignedURLResource", "AsyncPresignedURLResource"] + + +class PresignedURLResource(SyncAPIResource): + @cached_property + def with_raw_response(self) -> PresignedURLResourceWithRawResponse: + return PresignedURLResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> PresignedURLResourceWithStreamingResponse: + return PresignedURLResourceWithStreamingResponse(self) + + def create( + self, + *, + object_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, + ) -> PresignedURLCreateResponse: + """ + Retrieve a presigned url to post storage artifacts. + + Args: + object_name: The name of the object. + + 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( + "/storage/presigned-url", + options=make_request_options( + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, + query=maybe_transform( + {"object_name": object_name}, presigned_url_create_params.PresignedURLCreateParams + ), + ), + cast_to=PresignedURLCreateResponse, + ) + + +class AsyncPresignedURLResource(AsyncAPIResource): + @cached_property + def with_raw_response(self) -> AsyncPresignedURLResourceWithRawResponse: + return AsyncPresignedURLResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> AsyncPresignedURLResourceWithStreamingResponse: + return AsyncPresignedURLResourceWithStreamingResponse(self) + + async def create( + self, + *, + object_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, + ) -> PresignedURLCreateResponse: + """ + Retrieve a presigned url to post storage artifacts. + + Args: + object_name: The name of the object. + + 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( + "/storage/presigned-url", + options=make_request_options( + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, + query=await async_maybe_transform( + {"object_name": object_name}, presigned_url_create_params.PresignedURLCreateParams + ), + ), + cast_to=PresignedURLCreateResponse, + ) + + +class PresignedURLResourceWithRawResponse: + def __init__(self, presigned_url: PresignedURLResource) -> None: + self._presigned_url = presigned_url + + self.create = to_raw_response_wrapper( + presigned_url.create, + ) + + +class AsyncPresignedURLResourceWithRawResponse: + def __init__(self, presigned_url: AsyncPresignedURLResource) -> None: + self._presigned_url = presigned_url + + self.create = async_to_raw_response_wrapper( + presigned_url.create, + ) + + +class PresignedURLResourceWithStreamingResponse: + def __init__(self, presigned_url: PresignedURLResource) -> None: + self._presigned_url = presigned_url + + self.create = to_streamed_response_wrapper( + presigned_url.create, + ) + + +class AsyncPresignedURLResourceWithStreamingResponse: + def __init__(self, presigned_url: AsyncPresignedURLResource) -> None: + self._presigned_url = presigned_url + + self.create = async_to_streamed_response_wrapper( + presigned_url.create, + ) diff --git a/src/openlayer/resources/storage/storage.py b/src/openlayer/resources/storage/storage.py new file mode 100644 index 00000000..935bdc43 --- /dev/null +++ b/src/openlayer/resources/storage/storage.py @@ -0,0 +1,80 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from ..._compat import cached_property +from ..._resource import SyncAPIResource, AsyncAPIResource +from .presigned_url import ( + PresignedURLResource, + AsyncPresignedURLResource, + PresignedURLResourceWithRawResponse, + AsyncPresignedURLResourceWithRawResponse, + PresignedURLResourceWithStreamingResponse, + AsyncPresignedURLResourceWithStreamingResponse, +) + +__all__ = ["StorageResource", "AsyncStorageResource"] + + +class StorageResource(SyncAPIResource): + @cached_property + def presigned_url(self) -> PresignedURLResource: + return PresignedURLResource(self._client) + + @cached_property + def with_raw_response(self) -> StorageResourceWithRawResponse: + return StorageResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> StorageResourceWithStreamingResponse: + return StorageResourceWithStreamingResponse(self) + + +class AsyncStorageResource(AsyncAPIResource): + @cached_property + def presigned_url(self) -> AsyncPresignedURLResource: + return AsyncPresignedURLResource(self._client) + + @cached_property + def with_raw_response(self) -> AsyncStorageResourceWithRawResponse: + return AsyncStorageResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> AsyncStorageResourceWithStreamingResponse: + return AsyncStorageResourceWithStreamingResponse(self) + + +class StorageResourceWithRawResponse: + def __init__(self, storage: StorageResource) -> None: + self._storage = storage + + @cached_property + def presigned_url(self) -> PresignedURLResourceWithRawResponse: + return PresignedURLResourceWithRawResponse(self._storage.presigned_url) + + +class AsyncStorageResourceWithRawResponse: + def __init__(self, storage: AsyncStorageResource) -> None: + self._storage = storage + + @cached_property + def presigned_url(self) -> AsyncPresignedURLResourceWithRawResponse: + return AsyncPresignedURLResourceWithRawResponse(self._storage.presigned_url) + + +class StorageResourceWithStreamingResponse: + def __init__(self, storage: StorageResource) -> None: + self._storage = storage + + @cached_property + def presigned_url(self) -> PresignedURLResourceWithStreamingResponse: + return PresignedURLResourceWithStreamingResponse(self._storage.presigned_url) + + +class AsyncStorageResourceWithStreamingResponse: + def __init__(self, storage: AsyncStorageResource) -> None: + self._storage = storage + + @cached_property + def presigned_url(self) -> AsyncPresignedURLResourceWithStreamingResponse: + return AsyncPresignedURLResourceWithStreamingResponse(self._storage.presigned_url) diff --git a/src/openlayer/types/storage/__init__.py b/src/openlayer/types/storage/__init__.py new file mode 100644 index 00000000..1e6151a5 --- /dev/null +++ b/src/openlayer/types/storage/__init__.py @@ -0,0 +1,6 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from .presigned_url_create_params import PresignedURLCreateParams as PresignedURLCreateParams +from .presigned_url_create_response import PresignedURLCreateResponse as PresignedURLCreateResponse diff --git a/src/openlayer/types/storage/presigned_url_create_params.py b/src/openlayer/types/storage/presigned_url_create_params.py new file mode 100644 index 00000000..78af8cb5 --- /dev/null +++ b/src/openlayer/types/storage/presigned_url_create_params.py @@ -0,0 +1,14 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing_extensions import Required, Annotated, TypedDict + +from ..._utils import PropertyInfo + +__all__ = ["PresignedURLCreateParams"] + + +class PresignedURLCreateParams(TypedDict, total=False): + object_name: Required[Annotated[str, PropertyInfo(alias="objectName")]] + """The name of the object.""" diff --git a/src/openlayer/types/storage/presigned_url_create_response.py b/src/openlayer/types/storage/presigned_url_create_response.py new file mode 100644 index 00000000..71791bbf --- /dev/null +++ b/src/openlayer/types/storage/presigned_url_create_response.py @@ -0,0 +1,20 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing import Optional + +from pydantic import Field as FieldInfo + +from ..._models import BaseModel + +__all__ = ["PresignedURLCreateResponse"] + + +class PresignedURLCreateResponse(BaseModel): + storage_uri: str = FieldInfo(alias="storageUri") + """The storage URI to send back to the backend after the upload was completed.""" + + url: str + """The presigned url.""" + + fields: Optional[object] = None + """Fields to include in the body of the upload. Only needed by s3.""" diff --git a/tests/api_resources/storage/__init__.py b/tests/api_resources/storage/__init__.py new file mode 100644 index 00000000..fd8019a9 --- /dev/null +++ b/tests/api_resources/storage/__init__.py @@ -0,0 +1 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. diff --git a/tests/api_resources/storage/test_presigned_url.py b/tests/api_resources/storage/test_presigned_url.py new file mode 100644 index 00000000..defedbfd --- /dev/null +++ b/tests/api_resources/storage/test_presigned_url.py @@ -0,0 +1,84 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +import os +from typing import Any, cast + +import pytest + +from openlayer import Openlayer, AsyncOpenlayer +from tests.utils import assert_matches_type +from openlayer.types.storage import PresignedURLCreateResponse + +base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") + + +class TestPresignedURL: + parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) + + @parametrize + def test_method_create(self, client: Openlayer) -> None: + presigned_url = client.storage.presigned_url.create( + object_name="objectName", + ) + assert_matches_type(PresignedURLCreateResponse, presigned_url, path=["response"]) + + @parametrize + def test_raw_response_create(self, client: Openlayer) -> None: + response = client.storage.presigned_url.with_raw_response.create( + object_name="objectName", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + presigned_url = response.parse() + assert_matches_type(PresignedURLCreateResponse, presigned_url, path=["response"]) + + @parametrize + def test_streaming_response_create(self, client: Openlayer) -> None: + with client.storage.presigned_url.with_streaming_response.create( + object_name="objectName", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + presigned_url = response.parse() + assert_matches_type(PresignedURLCreateResponse, presigned_url, path=["response"]) + + assert cast(Any, response.is_closed) is True + + +class TestAsyncPresignedURL: + parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"]) + + @parametrize + async def test_method_create(self, async_client: AsyncOpenlayer) -> None: + presigned_url = await async_client.storage.presigned_url.create( + object_name="objectName", + ) + assert_matches_type(PresignedURLCreateResponse, presigned_url, path=["response"]) + + @parametrize + async def test_raw_response_create(self, async_client: AsyncOpenlayer) -> None: + response = await async_client.storage.presigned_url.with_raw_response.create( + object_name="objectName", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + presigned_url = await response.parse() + assert_matches_type(PresignedURLCreateResponse, presigned_url, path=["response"]) + + @parametrize + async def test_streaming_response_create(self, async_client: AsyncOpenlayer) -> None: + async with async_client.storage.presigned_url.with_streaming_response.create( + object_name="objectName", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + presigned_url = await response.parse() + assert_matches_type(PresignedURLCreateResponse, presigned_url, path=["response"]) + + assert cast(Any, response.is_closed) is True