Skip to content

Commit edc8131

Browse files
authored
Update kagglesdk (#683)
This includes the new endpoint for GetSubmission, but also has some changes added to models recently. All this was generated by `kapigen` -- don't spend too much time reviewing!
1 parent 6980230 commit edc8131

File tree

8 files changed

+544
-9
lines changed

8 files changed

+544
-9
lines changed

kagglesdk/competitions/services/competition_api_service.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from kagglesdk.common.types.file_download import FileDownload
22
from kagglesdk.common.types.http_redirect import HttpRedirect
3-
from kagglesdk.competitions.types.competition_api_service import ApiCreateSubmissionRequest, ApiCreateSubmissionResponse, ApiDownloadDataFileRequest, ApiDownloadDataFilesRequest, ApiDownloadLeaderboardRequest, ApiGetLeaderboardRequest, ApiGetLeaderboardResponse, ApiListCompetitionsRequest, ApiListCompetitionsResponse, ApiListDataFilesRequest, ApiListDataFilesResponse, ApiListSubmissionsRequest, ApiListSubmissionsResponse, ApiStartSubmissionUploadRequest, ApiStartSubmissionUploadResponse
3+
from kagglesdk.competitions.types.competition_api_service import ApiCreateSubmissionRequest, ApiCreateSubmissionResponse, ApiDownloadDataFileRequest, ApiDownloadDataFilesRequest, ApiDownloadLeaderboardRequest, ApiGetLeaderboardRequest, ApiGetLeaderboardResponse, ApiGetSubmissionRequest, ApiListCompetitionsRequest, ApiListCompetitionsResponse, ApiListDataFilesRequest, ApiListDataFilesResponse, ApiListSubmissionsRequest, ApiListSubmissionsResponse, ApiStartSubmissionUploadRequest, ApiStartSubmissionUploadResponse, ApiSubmission
44
from kagglesdk.kaggle_http_client import KaggleHttpClient
55

66
class CompetitionApiClient(object):
@@ -80,6 +80,18 @@ def create_submission(self, request: ApiCreateSubmissionRequest = None) -> ApiCr
8080

8181
return self._client.call("competitions.CompetitionApiService", "ApiCreateSubmission", request, ApiCreateSubmissionResponse)
8282

83+
def get_submission(self, request: ApiGetSubmissionRequest = None) -> ApiSubmission:
84+
r"""
85+
Args:
86+
request (ApiGetSubmissionRequest):
87+
The request object; initialized to empty instance if not specified.
88+
"""
89+
90+
if request is None:
91+
request = ApiGetSubmissionRequest()
92+
93+
return self._client.call("competitions.CompetitionApiService", "ApiGetSubmission", request, ApiSubmission)
94+
8395
def start_submission_upload(self, request: ApiStartSubmissionUploadRequest = None) -> ApiStartSubmissionUploadResponse:
8496
r"""
8597
Args:

kagglesdk/competitions/types/competition_api_service.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,22 @@ class ApiCreateSubmissionResponse(KaggleObject):
7777
r"""
7878
Attributes:
7979
message (str)
80+
TODO: Remove when we feel okay with the breaking change, this adds no
81+
value.
82+
ref (int)
8083
"""
8184

8285
def __init__(self):
8386
self._message = ""
87+
self._ref = 0
8488
self._freeze()
8589

8690
@property
8791
def message(self) -> str:
92+
r"""
93+
TODO: Remove when we feel okay with the breaking change, this adds no
94+
value.
95+
"""
8896
return self._message
8997

9098
@message.setter
@@ -96,6 +104,19 @@ def message(self, message: str):
96104
raise TypeError('message must be of type str')
97105
self._message = message
98106

107+
@property
108+
def ref(self) -> int:
109+
return self._ref
110+
111+
@ref.setter
112+
def ref(self, ref: int):
113+
if ref is None:
114+
del self.ref
115+
return
116+
if not isinstance(ref, int):
117+
raise TypeError('ref must be of type int')
118+
self._ref = ref
119+
99120

100121
class ApiDownloadDataFileRequest(KaggleObject):
101122
r"""
@@ -219,10 +240,15 @@ class ApiGetLeaderboardRequest(KaggleObject):
219240
Attributes:
220241
competition_name (str)
221242
Competition name. Example: 'titanic'.
243+
override_public (bool)
244+
By default we return the private leaderboard if it's available, otherwise
245+
the public LB. This flag lets you override to get public even if private
246+
is available.
222247
"""
223248

224249
def __init__(self):
225250
self._competition_name = ""
251+
self._override_public = None
226252
self._freeze()
227253

228254
@property
@@ -239,6 +265,24 @@ def competition_name(self, competition_name: str):
239265
raise TypeError('competition_name must be of type str')
240266
self._competition_name = competition_name
241267

268+
@property
269+
def override_public(self) -> bool:
270+
r"""
271+
By default we return the private leaderboard if it's available, otherwise
272+
the public LB. This flag lets you override to get public even if private
273+
is available.
274+
"""
275+
return self._override_public or False
276+
277+
@override_public.setter
278+
def override_public(self, override_public: bool):
279+
if override_public is None:
280+
del self.override_public
281+
return
282+
if not isinstance(override_public, bool):
283+
raise TypeError('override_public must be of type bool')
284+
self._override_public = override_public
285+
242286

243287
def endpoint(self):
244288
path = '/api/v1/competitions/{competition_name}/leaderboard/view'
@@ -274,6 +318,41 @@ def submissions(self, submissions: Optional[List[Optional['ApiLeaderboardSubmiss
274318
self._submissions = submissions
275319

276320

321+
class ApiGetSubmissionRequest(KaggleObject):
322+
r"""
323+
Attributes:
324+
ref (int)
325+
SubmissionId.
326+
"""
327+
328+
def __init__(self):
329+
self._ref = 0
330+
self._freeze()
331+
332+
@property
333+
def ref(self) -> int:
334+
"""SubmissionId."""
335+
return self._ref
336+
337+
@ref.setter
338+
def ref(self, ref: int):
339+
if ref is None:
340+
del self.ref
341+
return
342+
if not isinstance(ref, int):
343+
raise TypeError('ref must be of type int')
344+
self._ref = ref
345+
346+
347+
def endpoint(self):
348+
path = '/api/v1/competitions/submissions/get/{ref}'
349+
return path.format_map(self.to_field_map(self))
350+
351+
352+
@staticmethod
353+
def method():
354+
return 'POST'
355+
277356
class ApiLeaderboardSubmission(KaggleObject):
278357
r"""
279358
Attributes:
@@ -837,6 +916,8 @@ class ApiSubmission(KaggleObject):
837916
submitted_by_ref (str)
838917
team_name (str)
839918
url (str)
919+
Minor note: ListSubmissions and GetSubmission may differ in setting this
920+
field.
840921
"""
841922

842923
def __init__(self):
@@ -1013,6 +1094,10 @@ def team_name(self, team_name: str):
10131094

10141095
@property
10151096
def url(self) -> str:
1097+
r"""
1098+
Minor note: ListSubmissions and GetSubmission may differ in setting this
1099+
field.
1100+
"""
10161101
return self._url or ""
10171102

10181103
@url.setter
@@ -1634,6 +1719,7 @@ def total_count(self, total_count: int):
16341719

16351720
ApiCreateSubmissionResponse._fields = [
16361721
FieldMetadata("message", "message", "_message", str, "", PredefinedSerializer()),
1722+
FieldMetadata("ref", "ref", "_ref", int, 0, PredefinedSerializer()),
16371723
]
16381724

16391725
ApiDownloadDataFileRequest._fields = [
@@ -1651,12 +1737,17 @@ def total_count(self, total_count: int):
16511737

16521738
ApiGetLeaderboardRequest._fields = [
16531739
FieldMetadata("competitionName", "competition_name", "_competition_name", str, "", PredefinedSerializer()),
1740+
FieldMetadata("overridePublic", "override_public", "_override_public", bool, None, PredefinedSerializer(), optional=True),
16541741
]
16551742

16561743
ApiGetLeaderboardResponse._fields = [
16571744
FieldMetadata("submissions", "submissions", "_submissions", ApiLeaderboardSubmission, [], ListSerializer(KaggleObjectSerializer())),
16581745
]
16591746

1747+
ApiGetSubmissionRequest._fields = [
1748+
FieldMetadata("ref", "ref", "_ref", int, 0, PredefinedSerializer()),
1749+
]
1750+
16601751
ApiLeaderboardSubmission._fields = [
16611752
FieldMetadata("teamId", "team_id", "_team_id", int, 0, PredefinedSerializer()),
16621753
FieldMetadata("teamName", "team_name", "_team_name", str, None, PredefinedSerializer(), optional=True),

kagglesdk/kaggle_http_client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def _prepare_request(self, service_name: str, request_name: str,
122122
self._session.headers.update({
123123
'Accept': 'application/json',
124124
'Content-Type': 'text/plain',
125-
})
125+
})
126126
elif method == 'POST':
127127
data = request.to_field_map(request, ignore_defaults=True)
128128
if isinstance(data, dict):
@@ -176,7 +176,7 @@ def _print_request(self, request):
176176
self._print('---------------------Request----------------------')
177177
self._print(
178178
f'{request.method} {request.url}\n{_headers_to_str(request.headers)}\n\n{request.body}'
179-
)
179+
)
180180
self._print('--------------------------------------------------')
181181

182182
def _print_response(self, response, body=True):
@@ -208,14 +208,14 @@ def _init_session(self):
208208
self._session.headers.update({
209209
'User-Agent': 'kaggle-api/v1.7.0', # Was: V2
210210
'Content-Type': 'application/x-www-form-urlencoded', # Was: /json
211-
})
211+
})
212212

213213
iap_token = self._get_iap_token_if_required()
214214
if iap_token is not None:
215215
self._session.headers.update({
216216
# https://cloud.google.com/iap/docs/authentication-howto#authenticating_from_proxy-authorization_header
217217
'Proxy-Authorization': f'Bearer {iap_token}',
218-
})
218+
})
219219

220220
self._try_fill_auth()
221221
# self._fill_xsrf_token(iap_token) # TODO Make this align with original handler.

kagglesdk/models/services/model_api_service.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from kagglesdk.common.types.http_redirect import HttpRedirect
22
from kagglesdk.kaggle_http_client import KaggleHttpClient
3-
from kagglesdk.models.types.model_api_service import ApiCreateModelInstanceRequest, ApiCreateModelInstanceVersionRequest, ApiCreateModelRequest, ApiCreateModelResponse, ApiDeleteModelInstanceRequest, ApiDeleteModelInstanceVersionRequest, ApiDeleteModelRequest, ApiDeleteModelResponse, ApiDownloadModelInstanceVersionRequest, ApiGetModelInstanceRequest, ApiGetModelRequest, ApiListModelInstanceVersionFilesRequest, ApiListModelInstanceVersionFilesResponse, ApiListModelsRequest, ApiListModelsResponse, ApiModel, ApiModelInstance, ApiUpdateModelInstanceRequest, ApiUpdateModelRequest, ApiUpdateModelResponse, ApiUploadModelFileRequest, ApiUploadModelFileResponse, CreateModelSigningTokenRequest, CreateModelSigningTokenResponse, KeysRequest, KeysResponse, WellKnowEndpointRequest, WellKnowEndpointResponse
3+
from kagglesdk.models.types.model_api_service import ApiCreateModelInstanceRequest, ApiCreateModelInstanceVersionRequest, ApiCreateModelRequest, ApiCreateModelResponse, ApiDeleteModelInstanceRequest, ApiDeleteModelInstanceVersionRequest, ApiDeleteModelRequest, ApiDeleteModelResponse, ApiDownloadModelInstanceVersionRequest, ApiGetModelInstanceRequest, ApiGetModelRequest, ApiListModelGatingUserConsentsRequest, ApiListModelGatingUserConsentsResponse, ApiListModelInstanceVersionFilesRequest, ApiListModelInstanceVersionFilesResponse, ApiListModelsRequest, ApiListModelsResponse, ApiModel, ApiModelInstance, ApiUpdateModelInstanceRequest, ApiUpdateModelRequest, ApiUpdateModelResponse, ApiUploadModelFileRequest, ApiUploadModelFileResponse, CreateModelSigningTokenRequest, CreateModelSigningTokenResponse, KeysRequest, KeysResponse, WellKnowEndpointRequest, WellKnowEndpointResponse
44

55
class ModelApiClient(object):
66

@@ -223,3 +223,19 @@ def keys(self, request: KeysRequest = None) -> KeysResponse:
223223
request = KeysRequest()
224224

225225
return self._client.call("models.ModelApiService", "Keys", request, KeysResponse)
226+
227+
def list_model_gating_user_consents(self, request: ApiListModelGatingUserConsentsRequest = None) -> ApiListModelGatingUserConsentsResponse:
228+
r"""
229+
Model gating
230+
List the user consents for a gated model, under the model's current active
231+
agreement.
232+
233+
Args:
234+
request (ApiListModelGatingUserConsentsRequest):
235+
The request object; initialized to empty instance if not specified.
236+
"""
237+
238+
if request is None:
239+
request = ApiListModelGatingUserConsentsRequest()
240+
241+
return self._client.call("models.ModelApiService", "ApiListModelGatingUserConsents", request, ApiListModelGatingUserConsentsResponse)

0 commit comments

Comments
 (0)