Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/codeocean/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/")
Expand Down
23 changes: 21 additions & 2 deletions src/codeocean/computation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -332,14 +333,32 @@ 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},
)

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}")
Expand Down
23 changes: 21 additions & 2 deletions src/codeocean/data_asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -849,14 +850,32 @@ 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},
)

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).
Expand Down
21 changes: 21 additions & 0 deletions src/codeocean/folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"}
)