pub struct KaggleApiClient { /* private fields */ }
Expand description
Client to interact with the kaggle api.
#Example
use kaggle::KaggleApiClient;
let kaggle = KaggleApiClient::builder().build().unwrap();
Implementations§
Source§impl KaggleApiClient
impl KaggleApiClient
Sourcepub fn builder() -> KaggleApiClientBuilder
pub fn builder() -> KaggleApiClientBuilder
Convenience method to create a KaggleApiClientBuilder
Sourcepub fn download_dir(&self) -> &PathBuf
pub fn download_dir(&self) -> &PathBuf
The directory where downloads are stored.
Source§impl KaggleApiClient
impl KaggleApiClient
Sourcepub async fn competitions_list(
&self,
competition: &CompetitionsList,
) -> Result<Vec<Competition>>
pub async fn competitions_list( &self, competition: &CompetitionsList, ) -> Result<Vec<Competition>>
Returns a list of `Competition’ instances.
Sourcepub async fn competition_download_leaderboard(
&self,
id: impl AsRef<str>,
output: Option<PathBuf>,
) -> Result<PathBuf>
pub async fn competition_download_leaderboard( &self, id: impl AsRef<str>, output: Option<PathBuf>, ) -> Result<PathBuf>
Download competition leaderboard as zip file, as zip containing a csv of
KaggleApiClient::competition_view_leaderboard
.
If [output
] is a directory then the destination of the leaderboard zip
file will be <output>/<id>-leaderboard.zip
.
If [output
] is a file then this is the destination of downloaded
leaderboard zip.
If [output
] is None
, then the destination is
<self.download_dir>/<id>-leaderboard.zip
Example
use kaggle::query::CompetitionSortBy;
use kaggle::request::CompetitionsList;
use kaggle::KaggleApiClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let kaggle = KaggleApiClient::builder().build()?;
let resp = kaggle
.competitions_list(
&CompetitionsList::default()
.sort_by(CompetitionSortBy::RecentlyCreated)
.search("health"),
)
.await?;
Ok(())
}
Sourcepub async fn competition_view_leaderboard(
&self,
id: impl AsRef<str>,
) -> Result<LeaderBoard>
pub async fn competition_view_leaderboard( &self, id: impl AsRef<str>, ) -> Result<LeaderBoard>
View a leaderboard based on a competition name
Example
use kaggle::KaggleApiClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let kaggle = KaggleApiClient::builder().build()?;
let resp = kaggle
.competition_view_leaderboard("digit-recognizer")
.await?;
Ok(())
}
Sourcepub async fn competitions_data_download_file(
&self,
id: impl AsRef<str>,
file_name: impl AsRef<str>,
target: Option<PathBuf>,
) -> Result<PathBuf>
pub async fn competitions_data_download_file( &self, id: impl AsRef<str>, file_name: impl AsRef<str>, target: Option<PathBuf>, ) -> Result<PathBuf>
Download a competition data file to a designated location, or to download location. Returns the location of the zip file download.
Errors
This will fail if the authorized user has not yet accepted the competition’s rules.
Example
Download file train.csv
from competition
3d-object-detection-for-autonomous-vehicles
as zipfile to
<download-dir>/train.csv.zip
use kaggle::KaggleApiClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let kaggle = KaggleApiClient::builder().build()?;
let resp = kaggle
.competitions_data_download_file(
"3d-object-detection-for-autonomous-vehicles",
"train.csv",
None,
)
.await?;
Ok(())
}
Sourcepub async fn competitions_data_download_all_files(
&self,
id: impl AsRef<str>,
target: Option<PathBuf>,
) -> Result<PathBuf>
pub async fn competitions_data_download_all_files( &self, id: impl AsRef<str>, target: Option<PathBuf>, ) -> Result<PathBuf>
Downloads all competition files and returns the location of the zip file download.
Errors
This will fail if the authorized user has not yet accepted the competition’s rules.
Example
Download all files from competition
m5-forecasting-accuracy
as zipfile to
<download-dir>/m5-forecasting-accuracy.zip
use kaggle::KaggleApiClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let kaggle = KaggleApiClient::builder().build()?;
let resp = kaggle
.competitions_data_download_all_files(
"m5-forecasting-accuracy",
None,
)
.await?;
Ok(())
}
Sourcepub async fn competitions_data_list_files(
&self,
id: impl AsRef<str>,
) -> Result<Vec<File>>
pub async fn competitions_data_list_files( &self, id: impl AsRef<str>, ) -> Result<Vec<File>>
List all data files for a competition
Example
Overview of all files in the m5-forecasting-accuracy
competition
use kaggle::KaggleApiClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let kaggle = KaggleApiClient::builder().build()?;
let resp = kaggle
.competitions_data_list_files(
"m5-forecasting-accuracy",
)
.await?;
Ok(())
}
Sourcepub async fn competitions_submissions_list(
&self,
id: impl AsRef<str>,
page: usize,
) -> Result<Vec<Submission>>
pub async fn competitions_submissions_list( &self, id: impl AsRef<str>, page: usize, ) -> Result<Vec<Submission>>
Get the list submissions for a particular competition
Sourcepub async fn competitions_submissions_submit(
&self,
id: impl AsRef<str>,
blob_file_tokens: impl ToString,
submission_description: impl ToString,
) -> Result<SubmitResult>
pub async fn competitions_submissions_submit( &self, id: impl AsRef<str>, blob_file_tokens: impl ToString, submission_description: impl ToString, ) -> Result<SubmitResult>
Submit to competition.
Sourcepub async fn competition_submit(
&self,
file: impl AsRef<Path>,
competition: impl AsRef<str>,
message: impl ToString,
) -> Result<SubmitResult>
pub async fn competition_submit( &self, file: impl AsRef<Path>, competition: impl AsRef<str>, message: impl ToString, ) -> Result<SubmitResult>
Submit a competition.
Sourcepub async fn dataset_create_new(
&self,
new_dataset: DatasetNew,
) -> Result<DatasetNewResponse>
pub async fn dataset_create_new( &self, new_dataset: DatasetNew, ) -> Result<DatasetNewResponse>
Create a new dataset meaning the same as creating a version but with extra metadata like license and user/owner.
This will upload any referenced resources in the metadata resources. This will fail on kaggle if the metadata contains no resources to upload.
Example
Create a new kaggle dataset based on the ./dataset-metadata.json
{
"title": "My Awesome dataset",
"id": "mattsse/my-awesome-dataset",
"licenses": [
{
"name": "CC0-1.0"
}
],
"resources": [
{
"path": "LICENSE",
"description": "This is the license"
}
]
}
use kaggle::models::DatasetNew;
use kaggle::KaggleApiClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let kaggle = KaggleApiClient::builder().build()?;
let resp = kaggle
.dataset_create_new(DatasetNew::with_metadata_file(".").await?)
.await?;
Ok(())
}
Sourcepub async fn dataset_create_version(
&self,
folder: impl AsRef<Path>,
version_notes: impl ToString,
convert_to_csv: bool,
delete_old_versions: bool,
archive_mode: ArchiveMode,
) -> Result<DatasetNewVersionResponse>
pub async fn dataset_create_version( &self, folder: impl AsRef<Path>, version_notes: impl ToString, convert_to_csv: bool, delete_old_versions: bool, archive_mode: ArchiveMode, ) -> Result<DatasetNewVersionResponse>
Create a new dataset version
Sourcepub async fn datasets_create_version(
&self,
name: &str,
dataset_req: &DatasetNewVersionRequest,
) -> Result<DatasetNewVersionResponse>
pub async fn datasets_create_version( &self, name: &str, dataset_req: &DatasetNewVersionRequest, ) -> Result<DatasetNewVersionResponse>
Create a new dataset version
Sourcepub async fn datasets_create_version_by_id(
&self,
id: i32,
dataset_req: &DatasetNewVersionRequest,
) -> Result<DatasetNewVersionResponse>
pub async fn datasets_create_version_by_id( &self, id: i32, dataset_req: &DatasetNewVersionRequest, ) -> Result<DatasetNewVersionResponse>
Create a new dataset version by id
Sourcepub async fn dataset_download_all_files(
&self,
name: impl AsRef<str>,
path: Option<PathBuf>,
dataset_version_number: Option<&str>,
) -> Result<PathBuf>
pub async fn dataset_download_all_files( &self, name: impl AsRef<str>, path: Option<PathBuf>, dataset_version_number: Option<&str>, ) -> Result<PathBuf>
Download all files of a dataset.
Example
Download the newest version of the whole unanimad/dataisbeautiful
dataset as zip file into
<download-dir>/datasets/unanimad/dataisbeautiful.zip
use kaggle::KaggleApiClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let kaggle = KaggleApiClient::builder().build()?;
let resp = kaggle
.dataset_download_all_files("unanimad/dataisbeautiful", None, None)
.await?;
Ok(())
}
Sourcepub async fn dataset_download_file(
&self,
name: impl AsRef<str>,
file_name: impl AsRef<str>,
folder: Option<PathBuf>,
dataset_version_number: Option<&str>,
) -> Result<PathBuf>
pub async fn dataset_download_file( &self, name: impl AsRef<str>, file_name: impl AsRef<str>, folder: Option<PathBuf>, dataset_version_number: Option<&str>, ) -> Result<PathBuf>
Download a single file for a dataset.
Sourcepub async fn datasets_list(&self, list: &DatasetsList) -> Result<Vec<Dataset>>
pub async fn datasets_list(&self, list: &DatasetsList) -> Result<Vec<Dataset>>
List datasets
Example
use kaggle::request::DatasetsList;
use kaggle::KaggleApiClient;
use kaggle::query::SortBy;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let kaggle = KaggleApiClient::builder().build()?;
let resp = kaggle
.datasets_list(
&DatasetsList::default()
.sort_by(SortBy::ViewCount)
.search("health"),
)
.await?;
Ok(())
}
Sourcepub async fn datasets_list_files(
&self,
name: impl AsRef<str>,
) -> Result<ListFilesResult>
pub async fn datasets_list_files( &self, name: impl AsRef<str>, ) -> Result<ListFilesResult>
List all files for a dataset.
If the [name
] is not a combination of
<user-name-slug>/<dataset-name-slug>
but only a single slug, the
client request to list all the files for the authorized user’s dataset
with that name <client-auth-username>/<name>
.
Example
List all files for a dataset provided by another user.
use kaggle::KaggleApiClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let kaggle = KaggleApiClient::builder().build()?;
let resp = kaggle
.datasets_list_files("allen-institute-for-ai/CORD-19-research-challenge")
.await?;
Ok(())
}
Example
List all files for your own dataset.
use kaggle::KaggleApiClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let kaggle = KaggleApiClient::builder().build()?;
let resp = kaggle
.datasets_list_files("my-awesome-dataset")
.await?;
Ok(())
}
Sourcepub async fn datasets_status(
&self,
name: impl AsRef<str>,
) -> Result<Option<Value>>
pub async fn datasets_status( &self, name: impl AsRef<str>, ) -> Result<Option<Value>>
Get dataset creation status.
Sourcepub async fn datasets_upload_file(
&self,
file_name: impl ToString,
content_length: u64,
last_modified_date_utc: Duration,
) -> Result<FileUploadInfo>
pub async fn datasets_upload_file( &self, file_name: impl ToString, content_length: u64, last_modified_date_utc: Duration, ) -> Result<FileUploadInfo>
Get URL and token to start uploading a data file.
Sourcepub async fn datasets_view(&self, name: impl AsRef<str>) -> Result<Dataset>
pub async fn datasets_view(&self, name: impl AsRef<str>) -> Result<Dataset>
Show details about a dataset.
Sourcepub async fn kernels_output(
&self,
name: impl AsRef<str>,
path: Option<PathBuf>,
) -> Result<Vec<PathBuf>>
pub async fn kernels_output( &self, name: impl AsRef<str>, path: Option<PathBuf>, ) -> Result<Vec<PathBuf>>
Retrieve output for a specified kernel.
Sourcepub async fn kernel_output(&self, name: impl AsRef<str>) -> Result<KernelOutput>
pub async fn kernel_output(&self, name: impl AsRef<str>) -> Result<KernelOutput>
RDownload the latest output from a kernel
Sourcepub async fn kernel_pull(
&self,
name: impl AsRef<str>,
) -> Result<KernelPullResponse>
pub async fn kernel_pull( &self, name: impl AsRef<str>, ) -> Result<KernelPullResponse>
Pull the latest code from a kernel.
Sourcepub async fn kernels_pull(
&self,
pull: KernelPullRequest,
) -> Result<(PathBuf, Option<PathBuf>)>
pub async fn kernels_pull( &self, pull: KernelPullRequest, ) -> Result<(PathBuf, Option<PathBuf>)>
Pull a kernel, including a metadata file (if metadata is True) and associated files to a specified path.
Sourcepub async fn kernels_push(
&self,
folder: impl AsRef<Path>,
) -> Result<KernelPushResponse>
pub async fn kernels_push( &self, folder: impl AsRef<Path>, ) -> Result<KernelPushResponse>
read the metadata file and kernel files from a notebook, validate both, and use Kernel API to push to Kaggle if all is valid.
Sourcepub async fn kernel_push(
&self,
kernel_push_request: &KernelPushRequest,
) -> Result<KernelPushResponse>
pub async fn kernel_push( &self, kernel_push_request: &KernelPushRequest, ) -> Result<KernelPushResponse>
Push a new kernel version. Can be used to create a new kernel and update an existing one.
Sourcepub async fn kernel_status(&self, name: impl AsRef<str>) -> Result<Value>
pub async fn kernel_status(&self, name: impl AsRef<str>) -> Result<Value>
Get the status of a kernel.
Sourcepub async fn kernels_list(
&self,
kernel_list: &KernelsList,
) -> Result<Vec<Kernel>>
pub async fn kernels_list( &self, kernel_list: &KernelsList, ) -> Result<Vec<Kernel>>
List kernels based on a set of search criteria.
Example
use kaggle::request::KernelsList;
use kaggle::KaggleApiClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let kaggle = KaggleApiClient::builder().build()?;
let resp = kaggle
.kernels_list(&KernelsList::default().search("health"))
.await?;
Ok(())
}
Sourcepub async fn metadata_get(
&self,
name: impl AsRef<str>,
) -> Result<DatasetMetadata>
pub async fn metadata_get( &self, name: impl AsRef<str>, ) -> Result<DatasetMetadata>
Get the metadata for a dataset.
Sourcepub async fn dataset_metadata_update(
&self,
name: impl AsRef<str>,
path: Option<PathBuf>,
) -> Result<Value>
pub async fn dataset_metadata_update( &self, name: impl AsRef<str>, path: Option<PathBuf>, ) -> Result<Value>
Update the metadata for a dataset
pub async fn metadata_post( &self, name: impl AsRef<str>, settings: &DatasetUpdateSettingsRequest, ) -> Result<Value>
Trait Implementations§
Source§impl Clone for KaggleApiClient
impl Clone for KaggleApiClient
Source§fn clone(&self) -> KaggleApiClient
fn clone(&self) -> KaggleApiClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl Freeze for KaggleApiClient
impl !RefUnwindSafe for KaggleApiClient
impl !Send for KaggleApiClient
impl !Sync for KaggleApiClient
impl Unpin for KaggleApiClient
impl !UnwindSafe for KaggleApiClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)