Skip to content

Commit

Permalink
Add kagglesdk (#623)
Browse files Browse the repository at this point in the history
This is generated code. To the extent that it has been tested, it is
used in some of the public API code, which is exercised by the unit
tests.

It might be nice if there was a way to allow both this repo and
`kagglehub` to share this package without publishing to pypi.
  • Loading branch information
stevemessick authored Aug 23, 2024
1 parent baf8902 commit 9fd3320
Show file tree
Hide file tree
Showing 41 changed files with 11,568 additions and 0 deletions.
2 changes: 2 additions & 0 deletions kagglesdk/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from kagglesdk.kaggle_client import KaggleClient
from kagglesdk.kaggle_env import KaggleEnv
Empty file added kagglesdk/common/__init__.py
Empty file.
Empty file.
98 changes: 98 additions & 0 deletions kagglesdk/common/types/file_download.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
from kagglesdk.kaggle_object import *
from typing import Optional

class FileDownload(KaggleObject):
r"""
Standard response object representing a file download.
See http://go/kaggle-proto-handler-file-downloads
Some field names/descriptions borrowed from
google3/gdata/rosy/proto/data.proto
Attributes:
content_type (str)
MIME type of the data
TODO(aip.dev/143): (-- api-linter: core::0143::standardized-codes=disabled
--)
file_name (str)
Original file name
token (str)
A unique fingerprint for the file/media data
content_length (int)
Size of the data, in bytes (if known)
"""

def __init__(self):
self._content_type = ""
self._file_name = ""
self._token = ""
self._content_length = None
self._freeze()

@property
def content_type(self) -> str:
r"""
MIME type of the data
TODO(aip.dev/143): (-- api-linter: core::0143::standardized-codes=disabled
--)
"""
return self._content_type

@content_type.setter
def content_type(self, content_type: str):
if content_type is None:
del self.content_type
return
if not isinstance(content_type, str):
raise TypeError('content_type must be of type str')
self._content_type = content_type

@property
def file_name(self) -> str:
"""Original file name"""
return self._file_name

@file_name.setter
def file_name(self, file_name: str):
if file_name is None:
del self.file_name
return
if not isinstance(file_name, str):
raise TypeError('file_name must be of type str')
self._file_name = file_name

@property
def token(self) -> str:
"""A unique fingerprint for the file/media data"""
return self._token

@token.setter
def token(self, token: str):
if token is None:
del self.token
return
if not isinstance(token, str):
raise TypeError('token must be of type str')
self._token = token

@property
def content_length(self) -> int:
"""Size of the data, in bytes (if known)"""
return self._content_length or 0

@content_length.setter
def content_length(self, content_length: int):
if content_length is None:
del self.content_length
return
if not isinstance(content_length, int):
raise TypeError('content_length must be of type int')
self._content_length = content_length


FileDownload._fields = [
FieldMetadata("contentType", "content_type", "_content_type", str, "", PredefinedSerializer()),
FieldMetadata("fileName", "file_name", "_file_name", str, "", PredefinedSerializer()),
FieldMetadata("token", "token", "_token", str, "", PredefinedSerializer()),
FieldMetadata("contentLength", "content_length", "_content_length", int, None, PredefinedSerializer(), optional=True),
]

105 changes: 105 additions & 0 deletions kagglesdk/common/types/http_redirect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
from datetime import timedelta
from kagglesdk.kaggle_object import *
from typing import Optional

class HttpRedirect(KaggleObject):
r"""
Represents an HTTP redirect (e.g. 301 or 302) response.
Patterned after ASP.NET MVC's RedirectResult.
Attributes:
url (str)
Destination URL for the redirect.
permanent (bool)
Should it be an HTTP 301 (permanent) redirect or just temporary (HTTP
302)?.
bypass_encoding (bool)
When `true`, the `url` is already encoded, so bypass `UriHelper.Encode`.
Otherwise, invoke `UriHelper.Encode` on the `url` before returning to the
client.
expiry (timedelta)
Specifies how long the redirected url can be cached.
"""

def __init__(self):
self._url = ""
self._permanent = False
self._bypass_encoding = None
self._expiry = None
self._freeze()

@property
def url(self) -> str:
"""Destination URL for the redirect."""
return self._url

@url.setter
def url(self, url: str):
if url is None:
del self.url
return
if not isinstance(url, str):
raise TypeError('url must be of type str')
self._url = url

@property
def permanent(self) -> bool:
r"""
Should it be an HTTP 301 (permanent) redirect or just temporary (HTTP
302)?.
"""
return self._permanent

@permanent.setter
def permanent(self, permanent: bool):
if permanent is None:
del self.permanent
return
if not isinstance(permanent, bool):
raise TypeError('permanent must be of type bool')
self._permanent = permanent

@property
def bypass_encoding(self) -> bool:
r"""
When `true`, the `url` is already encoded, so bypass `UriHelper.Encode`.
Otherwise, invoke `UriHelper.Encode` on the `url` before returning to the
client.
"""
return self._bypass_encoding or False

@bypass_encoding.setter
def bypass_encoding(self, bypass_encoding: bool):
if bypass_encoding is None:
del self.bypass_encoding
return
if not isinstance(bypass_encoding, bool):
raise TypeError('bypass_encoding must be of type bool')
self._bypass_encoding = bypass_encoding

@property
def expiry(self) -> timedelta:
"""Specifies how long the redirected url can be cached."""
return self._expiry

@expiry.setter
def expiry(self, expiry: timedelta):
if expiry is None:
del self.expiry
return
if not isinstance(expiry, timedelta):
raise TypeError('expiry must be of type timedelta')
self._expiry = expiry


@classmethod
def prepare_from(cls, http_response):
return http_response

HttpRedirect._fields = [
FieldMetadata("url", "url", "_url", str, "", PredefinedSerializer()),
FieldMetadata("permanent", "permanent", "_permanent", bool, False, PredefinedSerializer()),
FieldMetadata("bypassEncoding", "bypass_encoding", "_bypass_encoding", bool, None, PredefinedSerializer(), optional=True),
FieldMetadata("expiry", "expiry", "_expiry", timedelta, None, TimeDeltaSerializer()),
]

Empty file.
Empty file.
117 changes: 117 additions & 0 deletions kagglesdk/competitions/services/competition_api_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
from kagglesdk.common.types.file_download import FileDownload
from kagglesdk.common.types.http_redirect import HttpRedirect
from kagglesdk.competitions.types.competition_api_service import ApiCreateSubmissionRequest, ApiCreateSubmissionResponse, ApiDownloadDataFileRequest, ApiDownloadDataFilesRequest, ApiDownloadLeaderboardRequest, ApiGetLeaderboardRequest, ApiGetLeaderboardResponse, ApiListCompetitionsRequest, ApiListCompetitionsResponse, ApiListDataFilesRequest, ApiListDataFilesResponse, ApiListSubmissionsRequest, ApiListSubmissionsResponse, ApiStartSubmissionUploadRequest, ApiStartSubmissionUploadResponse
from kagglesdk.kaggle_http_client import KaggleHttpClient

class CompetitionApiClient(object):

def __init__(self, client: KaggleHttpClient):
self._client = client

def list_competitions(self, request: ApiListCompetitionsRequest = None) -> ApiListCompetitionsResponse:
r"""
Args:
request (ApiListCompetitionsRequest):
The request object; initialized to empty instance if not specified.
"""

if request is None:
request = ApiListCompetitionsRequest()

return self._client.call("competitions.CompetitionApiService", "ApiListCompetitions", request, ApiListCompetitionsResponse)

def list_submissions(self, request: ApiListSubmissionsRequest = None) -> ApiListSubmissionsResponse:
r"""
Args:
request (ApiListSubmissionsRequest):
The request object; initialized to empty instance if not specified.
"""

if request is None:
request = ApiListSubmissionsRequest()

return self._client.call("competitions.CompetitionApiService", "ApiListSubmissions", request, ApiListSubmissionsResponse)

def list_data_files(self, request: ApiListDataFilesRequest = None) -> ApiListDataFilesResponse:
r"""
Args:
request (ApiListDataFilesRequest):
The request object; initialized to empty instance if not specified.
"""

if request is None:
request = ApiListDataFilesRequest()

return self._client.call("competitions.CompetitionApiService", "ApiListDataFiles", request, ApiListDataFilesResponse)

def get_leaderboard(self, request: ApiGetLeaderboardRequest = None) -> ApiGetLeaderboardResponse:
r"""
Args:
request (ApiGetLeaderboardRequest):
The request object; initialized to empty instance if not specified.
"""

if request is None:
request = ApiGetLeaderboardRequest()

return self._client.call("competitions.CompetitionApiService", "ApiGetLeaderboard", request, ApiGetLeaderboardResponse)

def download_leaderboard(self, request: ApiDownloadLeaderboardRequest = None) -> FileDownload:
r"""
Args:
request (ApiDownloadLeaderboardRequest):
The request object; initialized to empty instance if not specified.
"""

if request is None:
request = ApiDownloadLeaderboardRequest()

return self._client.call("competitions.CompetitionApiService", "ApiDownloadLeaderboard", request, FileDownload)

def create_submission(self, request: ApiCreateSubmissionRequest = None) -> ApiCreateSubmissionResponse:
r"""
Args:
request (ApiCreateSubmissionRequest):
The request object; initialized to empty instance if not specified.
"""

if request is None:
request = ApiCreateSubmissionRequest()

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

def start_submission_upload(self, request: ApiStartSubmissionUploadRequest = None) -> ApiStartSubmissionUploadResponse:
r"""
Args:
request (ApiStartSubmissionUploadRequest):
The request object; initialized to empty instance if not specified.
"""

if request is None:
request = ApiStartSubmissionUploadRequest()

return self._client.call("competitions.CompetitionApiService", "ApiStartSubmissionUpload", request, ApiStartSubmissionUploadResponse)

def download_data_files(self, request: ApiDownloadDataFilesRequest = None) -> HttpRedirect:
r"""
Args:
request (ApiDownloadDataFilesRequest):
The request object; initialized to empty instance if not specified.
"""

if request is None:
request = ApiDownloadDataFilesRequest()

return self._client.call("competitions.CompetitionApiService", "ApiDownloadDataFiles", request, HttpRedirect)

def download_data_file(self, request: ApiDownloadDataFileRequest = None) -> HttpRedirect:
r"""
Args:
request (ApiDownloadDataFileRequest):
The request object; initialized to empty instance if not specified.
"""

if request is None:
request = ApiDownloadDataFileRequest()

return self._client.call("competitions.CompetitionApiService", "ApiDownloadDataFile", request, HttpRedirect)
Empty file.
Loading

0 comments on commit 9fd3320

Please sign in to comment.