Skip to content

Commit 91078fe

Browse files
feat: Code Ocean version 4.0 functionality (#55)
1 parent cab7adb commit 91078fe

File tree

4 files changed

+64
-5
lines changed

4 files changed

+64
-5
lines changed

src/codeocean/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class CodeOcean:
3737
agent_id: Optional[str] = None
3838

3939
# Minimum server version required by this SDK
40-
MIN_SERVER_VERSION = "3.9.0"
40+
MIN_SERVER_VERSION = "4.0.0"
4141

4242
def __post_init__(self):
4343
self.session = BaseUrlSession(base_url=f"{self.domain}/api/v1/")

src/codeocean/computation.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
from requests_toolbelt.sessions import BaseUrlSession
66
from typing import Optional
77
from time import sleep, time
8+
from warnings import warn
89

910
from codeocean.enum import StrEnum
10-
from codeocean.folder import Folder, DownloadFileURL
11+
from codeocean.folder import FileURLs, Folder, DownloadFileURL
1112

1213

1314
class ComputationState(StrEnum):
@@ -332,14 +333,32 @@ def list_computation_results(self, computation_id: str, path: str = "") -> Folde
332333
return Folder.from_dict(res.json())
333334

334335
def get_result_file_download_url(self, computation_id: str, path: str) -> DownloadFileURL:
335-
"""Generate a download URL for a specific result file from a computation."""
336+
"""[DEPRECATED] Generate a download URL for a specific result file from a computation.
337+
338+
Deprecated: Use get_result_file_urls instead.
339+
"""
340+
warn(
341+
"get_result_file_download_url is deprecated and will be removed in a future release. "
342+
"Use get_result_file_urls instead.",
343+
DeprecationWarning,
344+
stacklevel=2,
345+
)
336346
res = self.client.get(
337347
f"computations/{computation_id}/results/download_url",
338348
params={"path": path},
339349
)
340350

341351
return DownloadFileURL.from_dict(res.json())
342352

353+
def get_result_file_urls(self, computation_id: str, path: str) -> FileURLs:
354+
"""Generate view and download URLs for a specific result file from a computation."""
355+
res = self.client.get(
356+
f"computations/{computation_id}/results/urls",
357+
params={"path": path},
358+
)
359+
360+
return FileURLs.from_dict(res.json())
361+
343362
def delete_computation(self, computation_id: str):
344363
"""Delete a computation and stop it if currently running."""
345364
self.client.delete(f"computations/{computation_id}")

src/codeocean/data_asset.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
from requests_toolbelt.sessions import BaseUrlSession
66
from time import sleep, time
77
from typing import Optional, Iterator
8+
from warnings import warn
89

910
from codeocean.components import Ownership, SortOrder, SearchFilter, Permissions
1011
from codeocean.computation import PipelineProcess, Param
1112
from codeocean.enum import StrEnum
12-
from codeocean.folder import Folder, DownloadFileURL
13+
from codeocean.folder import FileURLs, Folder, DownloadFileURL
1314

1415

1516
class DataAssetType(StrEnum):
@@ -849,14 +850,32 @@ def list_data_asset_files(self, data_asset_id: str, path: str = "") -> Folder:
849850
return Folder.from_dict(res.json())
850851

851852
def get_data_asset_file_download_url(self, data_asset_id: str, path: str) -> DownloadFileURL:
852-
"""Generate a download URL for a specific file from an internal data asset."""
853+
"""(Deprecated) Generate a download URL for a specific file from an internal data asset.
854+
855+
Deprecated: Use get_data_asset_file_urls instead.
856+
"""
857+
warn(
858+
"get_data_asset_file_download_url is deprecated and will be removed in a future release. "
859+
"Use get_data_asset_file_urls instead.",
860+
DeprecationWarning,
861+
stacklevel=2,
862+
)
853863
res = self.client.get(
854864
f"data_assets/{data_asset_id}/files/download_url",
855865
params={"path": path},
856866
)
857867

858868
return DownloadFileURL.from_dict(res.json())
859869

870+
def get_data_asset_file_urls(self, data_asset_id: str, path: str) -> FileURLs:
871+
"""Generate view and download URLs for a specific file from an internal data asset."""
872+
res = self.client.get(
873+
f"data_assets/{data_asset_id}/files/urls",
874+
params={"path": path},
875+
)
876+
877+
return FileURLs.from_dict(res.json())
878+
860879
def transfer_data_asset(self, data_asset_id: str, transfer_params: TransferDataParams):
861880
"""
862881
Transfer a data asset's files to a different S3 storage location (Admin only).

src/codeocean/folder.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from dataclasses_json import dataclass_json
44
from dataclasses import dataclass, field
55
from typing import Optional
6+
from warnings import warn
67

78

89
@dataclass_json
@@ -53,3 +54,23 @@ class DownloadFileURL:
5354
url: str = field(
5455
metadata={"description": "Pre-signed URL for downloading the specified file"}
5556
)
57+
58+
def __post_init__(self):
59+
warn(
60+
"DownloadFileURL is deprecated and will be removed in a future release.",
61+
DeprecationWarning,
62+
stacklevel=2
63+
)
64+
65+
66+
@dataclass_json
67+
@dataclass(frozen=True)
68+
class FileURLs:
69+
"""Represents a collection of file download URLs."""
70+
71+
download_url: str = field(
72+
metadata={"description": "Signed URL for downloading the file"}
73+
)
74+
view_url: str = field(
75+
metadata={"description": "Signed URL for viewing the file in the browser"}
76+
)

0 commit comments

Comments
 (0)