Skip to content

Commit ad9233c

Browse files
committed
Updates for OpenAPI endpoints
1 parent 514beab commit ad9233c

File tree

3 files changed

+18
-28
lines changed

3 files changed

+18
-28
lines changed

unboxapi/__init__.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from .projects import Project
2020
from .version import __version__
2121

22+
2223
class DeploymentType(Enum):
2324
"""Specify the storage medium being used by your Unbox deployment."""
2425

@@ -50,7 +51,7 @@ class UnboxClient(object):
5051

5152
def __init__(self, api_key: str):
5253
self.api = Api(api_key)
53-
self.subscription_plan = self.api.get_request("users/subscriptionPlan")
54+
self.subscription_plan = self.api.get_request("me/subscription-plan")
5455

5556
if DEPLOYMENT == DeploymentType.AWS:
5657
self.upload = self.api.upload_blob_s3
@@ -61,21 +62,14 @@ def __init__(self, api_key: str):
6162
else:
6263
self.upload = self.api.transfer_blob
6364

64-
def create_project(
65-
self,
66-
name: str,
67-
description: str,
68-
):
69-
endpoint = "initialize_project"
70-
payload = dict(
71-
name=name,
72-
description=description,
73-
)
65+
def create_project(self, name: str, description: str):
66+
endpoint = "projects"
67+
payload = dict(name=name, description=description)
7468
project_data = self.api.post_request(endpoint, body=payload)
7569
return Project(project_data, self.upload, self.subscription_plan, self)
7670

7771
def load_project(self, name: str):
78-
endpoint = f"load_project/{name}"
72+
endpoint = f"projects/{name}"
7973
project_data = self.api.get_request(endpoint)
8074
return Project(project_data, self.upload, self.subscription_plan, self)
8175

@@ -440,14 +434,14 @@ def add_model(
440434
with tarfile.open(tarfile_path, mode="w:gz") as tar:
441435
tar.add(temp_dir, arcname=bento_service.name)
442436

443-
endpoint = "models"
437+
endpoint = f"projects/{project_id}/ml-models"
444438
payload = dict(
445439
name=name,
446440
project_id=project_id,
447441
description=description,
448442
classNames=class_names,
449443
taskType=task_type.value,
450-
type=model_type.name,
444+
architectureType=model_type.name,
451445
kwargs=list(kwargs.keys()),
452446
featureNames=feature_names,
453447
categoricalFeatureNames=categorical_feature_names,
@@ -650,7 +644,7 @@ def add_dataset(
650644
raise UnboxException(
651645
"Label / text / feature / tag column names not in dataset."
652646
)
653-
endpoint = "datasets"
647+
endpoint = f"projects/{project_id}/datasets"
654648
payload = dict(
655649
name=name,
656650
project_id=project_id,
@@ -686,7 +680,7 @@ def add_dataframe(
686680
description: Optional[str] = None,
687681
tag_column_name: Optional[str] = None,
688682
language: str = "en",
689-
project_id: str = None
683+
project_id: str = None,
690684
) -> Dataset:
691685
r"""Uploads a dataset to the Unbox platform (from a pandas DataFrame).
692686
@@ -828,7 +822,7 @@ def add_dataframe(
828822
language=language,
829823
feature_names=feature_names,
830824
categorical_feature_names=categorical_feature_names,
831-
project_id=project_id
825+
project_id=project_id,
832826
)
833827

834828
@staticmethod
@@ -841,4 +835,3 @@ def _validate_categorical_features(
841835
f"Feature '{feature}' contains more options in the df than provided "
842836
"for it in `categorical_features_map`"
843837
)
844-

unboxapi/api.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def upload_blob_s3(
166166
)
167167
if res.ok:
168168
body["storageUri"] = presigned_json["storageUri"]
169-
return self.post_request(f"{endpoint}/{presigned_json['id']}", body=body)
169+
return self.post_request(f"{endpoint}?id={presigned_json['id']}", body=body)
170170
else:
171171
self._raise_on_respose(res)
172172

@@ -193,7 +193,7 @@ def upload_blob_gcs(
193193
)
194194
if res.ok:
195195
body["storageUri"] = presigned_json["storageUri"]
196-
return self.post_request(f"{endpoint}/{presigned_json['id']}", body=body)
196+
return self.post_request(f"{endpoint}?id={presigned_json['id']}", body=body)
197197
else:
198198
self._raise_on_respose(res)
199199

@@ -223,7 +223,7 @@ def upload_blob_azure(
223223
)
224224
if res.ok:
225225
body["storageUri"] = presigned_json["storageUri"]
226-
return self.post_request(f"{endpoint}/{presigned_json['id']}", body=body)
226+
return self.post_request(f"{endpoint}?id={presigned_json['id']}", body=body)
227227
else:
228228
self._raise_on_respose(res)
229229

@@ -239,4 +239,4 @@ def transfer_blob(self, endpoint: str, file_path: str, object_name: str, body=No
239239
raise UnboxException(f"Directory {blob_path} cannot be created")
240240
shutil.copyfile(file_path, f"{blob_path}/{object_name}")
241241
body["storageUri"] = f"local://{blob_path}"
242-
return self.post_request(f"{endpoint}/{id}", body=body)
242+
return self.post_request(f"{endpoint}?id={id}", body=body)

unboxapi/projects.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from .models import Model
22
from .datasets import Dataset
33

4+
45
class Project:
56
"""An object containing information about a project on the Unbox platform."""
67

@@ -50,10 +51,6 @@ def add_dataset(
5051
kwargs["project_id"] = self.id
5152
return self.client.add_dataset(*args, **kwargs)
5253

53-
def add_dataframe(
54-
self,
55-
*args,
56-
**kwargs
57-
) -> Dataset:
54+
def add_dataframe(self, *args, **kwargs) -> Dataset:
5855
kwargs["project_id"] = self.id
59-
return self.client.add_dataframe(*args, **kwargs)
56+
return self.client.add_dataframe(*args, **kwargs)

0 commit comments

Comments
 (0)