diff --git a/src/codeocean/client.py b/src/codeocean/client.py index 5658c8c..607c801 100644 --- a/src/codeocean/client.py +++ b/src/codeocean/client.py @@ -37,7 +37,7 @@ class CodeOcean: agent_id: Optional[str] = None # Minimum server version required by this SDK - MIN_SERVER_VERSION = "3.9.0" + MIN_SERVER_VERSION = "4.0.0" def __post_init__(self): self.session = BaseUrlSession(base_url=f"{self.domain}/api/v1/") diff --git a/src/codeocean/computation.py b/src/codeocean/computation.py index 53c769b..b0d94eb 100644 --- a/src/codeocean/computation.py +++ b/src/codeocean/computation.py @@ -5,9 +5,10 @@ from requests_toolbelt.sessions import BaseUrlSession from typing import Optional from time import sleep, time +from warnings import warn from codeocean.enum import StrEnum -from codeocean.folder import Folder, DownloadFileURL +from codeocean.folder import FileURLs, Folder, DownloadFileURL class ComputationState(StrEnum): @@ -332,7 +333,16 @@ def list_computation_results(self, computation_id: str, path: str = "") -> Folde return Folder.from_dict(res.json()) def get_result_file_download_url(self, computation_id: str, path: str) -> DownloadFileURL: - """Generate a download URL for a specific result file from a computation.""" + """[DEPRECATED] Generate a download URL for a specific result file from a computation. + + Deprecated: Use get_result_file_urls instead. + """ + warn( + "get_result_file_download_url is deprecated and will be removed in a future release. " + "Use get_result_file_urls instead.", + DeprecationWarning, + stacklevel=2, + ) res = self.client.get( f"computations/{computation_id}/results/download_url", params={"path": path}, @@ -340,6 +350,15 @@ def get_result_file_download_url(self, computation_id: str, path: str) -> Downlo return DownloadFileURL.from_dict(res.json()) + def get_result_file_urls(self, computation_id: str, path: str) -> FileURLs: + """Generate view and download URLs for a specific result file from a computation.""" + res = self.client.get( + f"computations/{computation_id}/results/urls", + params={"path": path}, + ) + + return FileURLs.from_dict(res.json()) + def delete_computation(self, computation_id: str): """Delete a computation and stop it if currently running.""" self.client.delete(f"computations/{computation_id}") diff --git a/src/codeocean/data_asset.py b/src/codeocean/data_asset.py index cfc28c9..89c0a95 100644 --- a/src/codeocean/data_asset.py +++ b/src/codeocean/data_asset.py @@ -5,11 +5,12 @@ from requests_toolbelt.sessions import BaseUrlSession from time import sleep, time from typing import Optional, Iterator +from warnings import warn from codeocean.components import Ownership, SortOrder, SearchFilter, Permissions from codeocean.computation import PipelineProcess, Param from codeocean.enum import StrEnum -from codeocean.folder import Folder, DownloadFileURL +from codeocean.folder import FileURLs, Folder, DownloadFileURL class DataAssetType(StrEnum): @@ -849,7 +850,16 @@ def list_data_asset_files(self, data_asset_id: str, path: str = "") -> Folder: return Folder.from_dict(res.json()) def get_data_asset_file_download_url(self, data_asset_id: str, path: str) -> DownloadFileURL: - """Generate a download URL for a specific file from an internal data asset.""" + """(Deprecated) Generate a download URL for a specific file from an internal data asset. + + Deprecated: Use get_data_asset_file_urls instead. + """ + warn( + "get_data_asset_file_download_url is deprecated and will be removed in a future release. " + "Use get_data_asset_file_urls instead.", + DeprecationWarning, + stacklevel=2, + ) res = self.client.get( f"data_assets/{data_asset_id}/files/download_url", params={"path": path}, @@ -857,6 +867,15 @@ def get_data_asset_file_download_url(self, data_asset_id: str, path: str) -> Dow return DownloadFileURL.from_dict(res.json()) + def get_data_asset_file_urls(self, data_asset_id: str, path: str) -> FileURLs: + """Generate view and download URLs for a specific file from an internal data asset.""" + res = self.client.get( + f"data_assets/{data_asset_id}/files/urls", + params={"path": path}, + ) + + return FileURLs.from_dict(res.json()) + def transfer_data_asset(self, data_asset_id: str, transfer_params: TransferDataParams): """ Transfer a data asset's files to a different S3 storage location (Admin only). diff --git a/src/codeocean/folder.py b/src/codeocean/folder.py index c7eac31..ca3c4a4 100644 --- a/src/codeocean/folder.py +++ b/src/codeocean/folder.py @@ -3,6 +3,7 @@ from dataclasses_json import dataclass_json from dataclasses import dataclass, field from typing import Optional +from warnings import warn @dataclass_json @@ -53,3 +54,23 @@ class DownloadFileURL: url: str = field( metadata={"description": "Pre-signed URL for downloading the specified file"} ) + + def __post_init__(self): + warn( + "DownloadFileURL is deprecated and will be removed in a future release.", + DeprecationWarning, + stacklevel=2 + ) + + +@dataclass_json +@dataclass(frozen=True) +class FileURLs: + """Represents a collection of file download URLs.""" + + download_url: str = field( + metadata={"description": "Signed URL for downloading the file"} + ) + view_url: str = field( + metadata={"description": "Signed URL for viewing the file in the browser"} + )