kaggle 1.7.4.2__py3-none-any.whl → 1.7.4.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. kaggle/api/kaggle_api.py +92 -79
  2. kaggle/api/kaggle_api_extended.py +907 -876
  3. kaggle/configuration.py +3 -3
  4. kaggle/models/dataset_column.py +58 -49
  5. kaggle/models/dataset_new_request.py +47 -31
  6. kaggle/models/dataset_new_version_request.py +56 -31
  7. kaggle/models/dataset_update_settings_request.py +58 -32
  8. kaggle/models/kernel_push_request.py +86 -51
  9. kaggle/models/model_instance_new_version_request.py +20 -12
  10. kaggle/models/model_instance_update_request.py +68 -37
  11. kaggle/models/model_new_instance_request.py +85 -47
  12. kaggle/models/model_new_request.py +26 -19
  13. kaggle/models/model_update_request.py +34 -23
  14. kaggle/models/start_blob_upload_request.py +60 -49
  15. kaggle/models/start_blob_upload_response.py +27 -22
  16. kaggle/models/upload_file.py +33 -31
  17. {kaggle-1.7.4.2.dist-info → kaggle-1.7.4.5.dist-info}/METADATA +1 -1
  18. {kaggle-1.7.4.2.dist-info → kaggle-1.7.4.5.dist-info}/RECORD +40 -31
  19. kagglesdk/__init__.py +1 -1
  20. kagglesdk/datasets/types/dataset_api_service.py +16 -0
  21. kagglesdk/kaggle_client.py +12 -0
  22. kagglesdk/kaggle_env.py +9 -11
  23. kagglesdk/kaggle_http_client.py +91 -56
  24. kagglesdk/kaggle_object.py +97 -42
  25. kagglesdk/kernels/types/kernels_api_service.py +24 -0
  26. kagglesdk/models/services/model_api_service.py +7 -6
  27. kagglesdk/models/types/model_api_service.py +31 -15
  28. kagglesdk/security/__init__.py +0 -0
  29. kagglesdk/security/services/__init__.py +0 -0
  30. kagglesdk/security/services/oauth_service.py +32 -0
  31. kagglesdk/security/types/__init__.py +0 -0
  32. kagglesdk/security/types/authentication.py +171 -0
  33. kagglesdk/security/types/oauth_service.py +394 -0
  34. kagglesdk/test/test_client.py +4 -6
  35. kagglesdk/users/services/__init__.py +0 -0
  36. kagglesdk/users/services/account_service.py +19 -0
  37. kagglesdk/users/types/account_service.py +204 -0
  38. {kaggle-1.7.4.2.dist-info → kaggle-1.7.4.5.dist-info}/WHEEL +0 -0
  39. {kaggle-1.7.4.2.dist-info → kaggle-1.7.4.5.dist-info}/entry_points.txt +0 -0
  40. {kaggle-1.7.4.2.dist-info → kaggle-1.7.4.5.dist-info}/licenses/LICENSE.txt +0 -0
@@ -253,7 +253,7 @@ class ResumableFileUpload(object):
253
253
 
254
254
 
255
255
  class KaggleApi:
256
- __version__ = '1.7.4.2'
256
+ __version__ = '1.7.4.5'
257
257
 
258
258
  CONFIG_NAME_PROXY = 'proxy'
259
259
  CONFIG_NAME_COMPETITION = 'competition'
@@ -312,7 +312,7 @@ class KaggleApi:
312
312
  'unlaunched_community'
313
313
  ]
314
314
  valid_competition_categories = [
315
- 'all', 'featured', 'research', 'recruitment', 'gettingStarted', 'masters',
315
+ 'unspecified', 'featured', 'research', 'recruitment', 'gettingStarted', 'masters',
316
316
  'playground'
317
317
  ]
318
318
  valid_competition_sort_by = [
@@ -406,11 +406,12 @@ class KaggleApi:
406
406
  ## Authentication
407
407
 
408
408
  def authenticate(self):
409
- """authenticate the user with the Kaggle API. This method will generate
410
- a configuration, first checking the environment for credential
411
- variables, and falling back to looking for the .kaggle/kaggle.json
412
- configuration file.
413
- """
409
+ """Authenticate the user with the Kaggle API.
410
+
411
+ This method will generate a configuration, first checking the
412
+ environment for credential variables, and falling back to looking
413
+ for the .kaggle/kaggle.json configuration file.
414
+ """
414
415
 
415
416
  config_data = {}
416
417
  # Ex: 'datasets list', 'competitions files', 'models instances get', etc.
@@ -440,26 +441,27 @@ class KaggleApi:
440
441
  self._load_config(config_data)
441
442
 
442
443
  def _is_help_or_version_command(self, api_command):
443
- """determines if the string command passed in is for a help or version
444
- command.
445
- Parameters
446
- ==========
447
- api_command: a string, 'datasets list', 'competitions files',
448
- 'models instances get', etc.
449
- """
444
+ """Determines if the string command passed in is for a help or version
445
+ command.
446
+
447
+ Parameters
448
+ ==========
449
+ api_command: a string, 'datasets list', 'competitions files',
450
+ 'models instances get', etc.
451
+ """
450
452
  return api_command.endswith(('-h', '--help', '-v', '--version'))
451
453
 
452
454
  def read_config_environment(self, config_data=None, quiet=False):
453
- """read_config_environment is the second effort to get a username
454
- and key to authenticate to the Kaggle API. The environment keys
455
- are equivalent to the kaggle.json file, but with "KAGGLE_" prefix
456
- to define a unique namespace.
457
-
458
- Parameters
459
- ==========
460
- config_data: a partially loaded configuration dictionary (optional)
461
- quiet: suppress verbose print of output (default is False)
462
- """
455
+ """read_config_environment is the second effort to get a username and key
456
+ to authenticate to the Kaggle API. The environment keys are equivalent to
457
+ the kaggle.json file, but with "KAGGLE_" prefix to define a unique
458
+ namespace.
459
+
460
+ Parameters
461
+ ==========
462
+ config_data: a partially loaded configuration dictionary (optional)
463
+ quiet: suppress verbose print of output (default is False)
464
+ """
463
465
 
464
466
  # Add all variables that start with KAGGLE_ to config data
465
467
 
@@ -475,15 +477,14 @@ class KaggleApi:
475
477
  ## Configuration
476
478
 
477
479
  def _load_config(self, config_data):
478
- """the final step of the authenticate steps, where we load the values
479
- from config_data into the Configuration object.
480
-
481
- Parameters
482
- ==========
483
- config_data: a dictionary with configuration values (keys) to read
484
- into self.config_values
480
+ """The final step of the authenticate steps, where we load the values from
481
+ config_data into the Configuration object.
485
482
 
486
- """
483
+ Parameters
484
+ ==========
485
+ config_data: a dictionary with configuration values (keys) to read
486
+ into self.config_values
487
+ """
487
488
  # Username and password are required.
488
489
 
489
490
  for item in [self.CONFIG_NAME_USER, self.CONFIG_NAME_KEY]:
@@ -512,16 +513,16 @@ class KaggleApi:
512
513
  self.config_values = config_data
513
514
 
514
515
  def read_config_file(self, config_data=None, quiet=False):
515
- """read_config_file is the first effort to get a username
516
- and key to authenticate to the Kaggle API. Since we can get the
517
- username and password from the environment, it's not required.
518
-
519
- Parameters
520
- ==========
521
- config_data: the Configuration object to save a username and
522
- password, if defined
523
- quiet: suppress verbose print of output (default is False)
524
- """
516
+ """read_config_file is the first effort to get a username and key to
517
+ authenticate to the Kaggle API. Since we can get the username and password
518
+ from the environment, it's not required.
519
+
520
+ Parameters
521
+ ==========
522
+ config_data: the Configuration object to save a username and
523
+ password, if defined
524
+ quiet: suppress verbose print of output (default is False)
525
+ """
525
526
  if config_data is None:
526
527
  config_data = {}
527
528
 
@@ -549,7 +550,7 @@ class KaggleApi:
549
550
  return config_data
550
551
 
551
552
  def _read_config_file(self):
552
- """read in the configuration file, a json file defined at self.config"""
553
+ """Read in the configuration file, a json file defined at self.config."""
553
554
 
554
555
  try:
555
556
  with open(self.config, 'r') as f:
@@ -560,28 +561,28 @@ class KaggleApi:
560
561
  return config_data
561
562
 
562
563
  def _write_config_file(self, config_data, indent=2):
563
- """write config data to file.
564
+ """Write config data to file.
564
565
 
565
- Parameters
566
- ==========
567
- config_data: the Configuration object to save a username and
568
- password, if defined
569
- indent: number of tab indentations to use when writing json
570
- """
566
+ Parameters
567
+ ==========
568
+ config_data: the Configuration object to save a username and
569
+ password, if defined
570
+ indent: number of tab indentations to use when writing json
571
+ """
571
572
  with open(self.config, 'w') as f:
572
573
  json.dump(config_data, f, indent=indent)
573
574
 
574
575
  def set_config_value(self, name, value, quiet=False):
575
- """a client helper function to set a configuration value, meaning
576
- reading in the configuration file (if it exists), saving a new
577
- config value, and then writing back
578
-
579
- Parameters
580
- ==========
581
- name: the name of the value to set (key in dictionary)
582
- value: the value to set at the key
583
- quiet: disable verbose output if True (default is False)
584
- """
576
+ """A client helper function to set a configuration value, meaning reading
577
+ in the configuration file (if it exists), saving a new config value, and
578
+ then writing back.
579
+
580
+ Parameters
581
+ ==========
582
+ name: the name of the value to set (key in dictionary)
583
+ value: the value to set at the key
584
+ quiet: disable verbose output if True (default is False)
585
+ """
585
586
 
586
587
  config_data = self._read_config_file()
587
588
 
@@ -619,25 +620,24 @@ class KaggleApi:
619
620
  self.print_config_value(name, separator=' is now set to: ')
620
621
 
621
622
  def get_config_value(self, name):
622
- """ return a config value (with key name) if it's in the config_values,
623
- otherwise return None
624
-
625
- Parameters
626
- ==========
627
- name: the config value key to get
623
+ """Return a config value (with key name) if it's in the config_values,
624
+ otherwise return None.
628
625
 
629
- """
626
+ Parameters
627
+ ==========
628
+ name: the config value key to get
629
+ """
630
630
  if name in self.config_values:
631
631
  return self.config_values[name]
632
632
 
633
633
  def get_default_download_dir(self, *subdirs):
634
- """ Get the download path for a file. If not defined, return default
635
- from config.
634
+ """Get the download path for a file. If not defined, return default from
635
+ config.
636
636
 
637
- Parameters
638
- ==========
639
- subdirs: a single (or list of) subfolders under the basepath
640
- """
637
+ Parameters
638
+ ==========
639
+ subdirs: a single (or list of) subfolders under the basepath
640
+ """
641
641
  # Look up value for key "path" in the config
642
642
  path = self.get_config_value(self.CONFIG_NAME_PATH)
643
643
 
@@ -648,14 +648,14 @@ class KaggleApi:
648
648
  return os.path.join(path, *subdirs)
649
649
 
650
650
  def print_config_value(self, name, prefix='- ', separator=': '):
651
- """print a single configuration value, based on a prefix and separator
651
+ """Print a single configuration value, based on a prefix and separator.
652
652
 
653
- Parameters
654
- ==========
655
- name: the key of the config valur in self.config_values to print
656
- prefix: the prefix to print
657
- separator: the separator to use (default is : )
658
- """
653
+ Parameters
654
+ ==========
655
+ name: the key of the config valur in self.config_values to print
656
+ prefix: the prefix to print
657
+ separator: the separator to use (default is : )
658
+ """
659
659
 
660
660
  value_out = 'None'
661
661
  if name in self.config_values and self.config_values[name] is not None:
@@ -727,18 +727,18 @@ class KaggleApi:
727
727
  sort_by=None,
728
728
  page=1,
729
729
  search=None):
730
- """ Make a call to list competitions, format the response, and return
731
- a list of ApiCompetition instances
730
+ """Make a call to list competitions, format the response, and return a list
731
+ of ApiCompetition instances.
732
732
 
733
- Parameters
734
- ==========
733
+ Parameters
734
+ ==========
735
735
 
736
- page: the page to return (default is 1)
737
- search: a search term to use (default is empty string)
738
- sort_by: how to sort the result, see valid_competition_sort_by for options
739
- category: category to filter result to; use 'all' to get closed competitions
740
- group: group to filter result to
741
- """
736
+ page: the page to return (default is 1)
737
+ search: a search term to use (default is empty string)
738
+ sort_by: how to sort the result, see valid_competition_sort_by for options
739
+ category: category to filter result to; use 'all' to get closed competitions
740
+ group: group to filter result to
741
+ """
742
742
  if group:
743
743
  if group not in self.valid_competition_groups:
744
744
  raise ValueError('Invalid group specified. Valid options are ' +
@@ -750,7 +750,10 @@ class KaggleApi:
750
750
 
751
751
  if category:
752
752
  if category not in self.valid_competition_categories:
753
- raise ValueError('Invalid category specified. Valid options are ' +
753
+ if category == 'all':
754
+ category = 'unspecified'
755
+ else:
756
+ raise ValueError('Invalid category specified. Valid options are ' +
754
757
  str(self.valid_competition_categories))
755
758
  category = self.lookup_enum(HostSegment, category)
756
759
 
@@ -778,17 +781,17 @@ class KaggleApi:
778
781
  page=1,
779
782
  search=None,
780
783
  csv_display=False):
781
- """ A wrapper for competitions_list for the client.
782
-
783
- Parameters
784
- ==========
785
- group: group to filter result to
786
- category: category to filter result to
787
- sort_by: how to sort the result, see valid_sort_by for options
788
- page: the page to return (default is 1)
789
- search: a search term to use (default is empty string)
790
- csv_display: if True, print comma separated values
791
- """
784
+ """A wrapper for competitions_list for the client.
785
+
786
+ Parameters
787
+ ==========
788
+ group: group to filter result to
789
+ category: category to filter result to
790
+ sort_by: how to sort the result, see valid_sort_by for options
791
+ page: the page to return (default is 1)
792
+ search: a search term to use (default is empty string)
793
+ csv_display: if True, print comma separated values
794
+ """
792
795
  competitions = self.competitions_list(
793
796
  group=group,
794
797
  category=category,
@@ -804,17 +807,17 @@ class KaggleApi:
804
807
  print('No competitions found')
805
808
 
806
809
  def competition_submit_code(self, file_name, message, competition, kernel=None, kernel_version=None, quiet=False):
807
- """ Submit to a code competition.
808
-
809
- Parameters
810
- ==========
811
- file_name: the name of the output file created by the kernel (not used for packages)
812
- message: the submission description
813
- competition: the competition name; if not given use the 'competition' config value
814
- kernel: the <owner>/<notebook> of the notebook to use for a code competition
815
- kernel_version: the version number, returned by 'kaggle kernels push ...'
816
- quiet: suppress verbose output (default is False)
817
- """
810
+ """Submit to a code competition.
811
+
812
+ Parameters
813
+ ==========
814
+ file_name: the name of the output file created by the kernel (not used for packages)
815
+ message: the submission description
816
+ competition: the competition name; if not given use the 'competition' config value
817
+ kernel: the <owner>/<notebook> of the notebook to use for a code competition
818
+ kernel_version: the version number, returned by 'kaggle kernels push ...'
819
+ quiet: suppress verbose output (default is False)
820
+ """
818
821
  if competition is None:
819
822
  competition = self.get_config_value(self.CONFIG_NAME_COMPETITION)
820
823
  if competition is not None and not quiet:
@@ -843,15 +846,15 @@ class KaggleApi:
843
846
  return submit_response
844
847
 
845
848
  def competition_submit(self, file_name, message, competition, quiet=False):
846
- """ Submit to a competition.
847
-
848
- Parameters
849
- ==========
850
- file_name: the competition metadata file
851
- message: the submission description
852
- competition: the competition name; if not given use the 'competition' config value
853
- quiet: suppress verbose output (default is False)
854
- """
849
+ """Submit to a competition.
850
+
851
+ Parameters
852
+ ==========
853
+ file_name: the competition metadata file
854
+ message: the submission description
855
+ competition: the competition name; if not given use the 'competition' config value
856
+ quiet: suppress verbose output (default is False)
857
+ """
855
858
  if competition is None:
856
859
  competition = self.get_config_value(self.CONFIG_NAME_COMPETITION)
857
860
  if competition is not None and not quiet:
@@ -894,19 +897,19 @@ class KaggleApi:
894
897
  version=None,
895
898
  competition_opt=None,
896
899
  quiet=False):
897
- """ Submit a competition using the client. Arguments are same as for
898
- competition_submit, except for extra arguments provided here.
899
-
900
- Parameters
901
- ==========
902
- file_name: the competition metadata file
903
- message: the submission description
904
- competition: the competition name; if not given use the 'competition' config value
905
- kernel: the name of the kernel to submit to a code competition
906
- version: the version of the kernel to submit to a code competition, e.g. '1'
907
- quiet: suppress verbose output (default is False)
908
- competition_opt: an alternative competition option provided by cli
909
- """
900
+ """Submit a competition using the client. Arguments are same as for
901
+ competition_submit, except for extra arguments provided here.
902
+
903
+ Parameters
904
+ ==========
905
+ file_name: the competition metadata file
906
+ message: the submission description
907
+ competition: the competition name; if not given use the 'competition' config value
908
+ kernel: the name of the kernel to submit to a code competition
909
+ version: the version of the kernel to submit to a code competition, e.g. '1'
910
+ quiet: suppress verbose output (default is False)
911
+ competition_opt: an alternative competition option provided by cli
912
+ """
910
913
  if kernel and not version or version and not kernel:
911
914
  raise ValueError('Code competition submissions require both the output file name and the version label')
912
915
  competition = competition or competition_opt
@@ -933,16 +936,16 @@ class KaggleApi:
933
936
  sort=None,
934
937
  page_token=0,
935
938
  page_size=20):
936
- """ Get the list of Submission for a particular competition.
937
-
938
- Parameters
939
- ==========
940
- competition: the name of the competition
941
- group: the submission group
942
- sort: the sort-by option
943
- page_token: token for pagination
944
- page_size: the number of items per page
945
- """
939
+ """Get the list of Submission for a particular competition.
940
+
941
+ Parameters
942
+ ==========
943
+ competition: the name of the competition
944
+ group: the submission group
945
+ sort: the sort-by option
946
+ page_token: token for pagination
947
+ page_size: the number of items per page
948
+ """
946
949
  with self.build_kaggle_client() as kaggle:
947
950
  request = ApiListSubmissionsRequest()
948
951
  request.competition_name = competition
@@ -960,19 +963,19 @@ class KaggleApi:
960
963
  page_token=None,
961
964
  page_size=20,
962
965
  quiet=False):
963
- """ A wrapper to competition_submission, will return either json or csv
964
- to the user. Additional parameters are listed below, see
965
- competition_submissions for rest.
966
-
967
- Parameters
968
- ==========
969
- competition: the name of the competition. If None, look to config
970
- competition_opt: an alternative competition option provided by cli
971
- csv_display: if True, print comma separated values
972
- page_token: token for pagination
973
- page_size: the number of items per page
974
- quiet: suppress verbose output (default is False)
975
- """
966
+ """A wrapper to competition_submission, will return either json or csv to
967
+ the user. Additional parameters are listed below, see
968
+ competition_submissions for rest.
969
+
970
+ Parameters
971
+ ==========
972
+ competition: the name of the competition. If None, look to config
973
+ competition_opt: an alternative competition option provided by cli
974
+ csv_display: if True, print comma separated values
975
+ page_token: token for pagination
976
+ page_size: the number of items per page
977
+ quiet: suppress verbose output (default is False)
978
+ """
976
979
  competition = competition or competition_opt
977
980
  if competition is None:
978
981
  competition = self.get_config_value(self.CONFIG_NAME_COMPETITION)
@@ -993,13 +996,14 @@ class KaggleApi:
993
996
  print('No submissions found')
994
997
 
995
998
  def competition_list_files(self, competition, page_token=None, page_size=20):
996
- """ List files for a competition.
997
- Parameters
998
- ==========
999
- competition: the name of the competition
1000
- page_token: the page token for pagination
1001
- page_size: the number of items per page
1002
- """
999
+ """List files for a competition.
1000
+
1001
+ Parameters
1002
+ ==========
1003
+ competition: the name of the competition
1004
+ page_token: the page token for pagination
1005
+ page_size: the number of items per page
1006
+ """
1003
1007
  with self.build_kaggle_client() as kaggle:
1004
1008
  request = ApiListDataFilesRequest()
1005
1009
  request.competition_name = competition
@@ -1016,17 +1020,17 @@ class KaggleApi:
1016
1020
  page_token=None,
1017
1021
  page_size=20,
1018
1022
  quiet=False):
1019
- """ List files for a competition, if it exists.
1020
-
1021
- Parameters
1022
- ==========
1023
- competition: the name of the competition. If None, look to config
1024
- competition_opt: an alternative competition option provided by cli
1025
- csv_display: if True, print comma separated values
1026
- page_token: the page token for pagination
1027
- page_size: the number of items per page
1028
- quiet: suppress verbose output (default is False)
1029
- """
1023
+ """List files for a competition, if it exists.
1024
+
1025
+ Parameters
1026
+ ==========
1027
+ competition: the name of the competition. If None, look to config
1028
+ competition_opt: an alternative competition option provided by cli
1029
+ csv_display: if True, print comma separated values
1030
+ page_token: the page token for pagination
1031
+ page_size: the number of items per page
1032
+ quiet: suppress verbose output (default is False)
1033
+ """
1030
1034
  competition = competition or competition_opt
1031
1035
  if competition is None:
1032
1036
  competition = self.get_config_value(self.CONFIG_NAME_COMPETITION)
@@ -1056,17 +1060,17 @@ class KaggleApi:
1056
1060
  path=None,
1057
1061
  force=False,
1058
1062
  quiet=False):
1059
- """ Download a competition file to a designated location, or use
1060
- a default location.
1061
-
1062
- Parameters
1063
- =========
1064
- competition: the name of the competition
1065
- file_name: the configuration file name
1066
- path: a path to download the file to
1067
- force: force the download if the file already exists (default False)
1068
- quiet: suppress verbose output (default is False)
1069
- """
1063
+ """Download a competition file to a designated location, or use a default
1064
+ location.
1065
+
1066
+ Parameters
1067
+ =========
1068
+ competition: the name of the competition
1069
+ file_name: the configuration file name
1070
+ path: a path to download the file to
1071
+ force: force the download if the file already exists (default False)
1072
+ quiet: suppress verbose output (default is False)
1073
+ """
1070
1074
  if path is None:
1071
1075
  effective_path = self.get_default_download_dir('competitions',
1072
1076
  competition)
@@ -1076,30 +1080,30 @@ class KaggleApi:
1076
1080
  with self.build_kaggle_client() as kaggle:
1077
1081
  request = ApiDownloadDataFileRequest()
1078
1082
  request.competition_name = competition
1079
- request.file_name = file_name
1083
+ request.file_name = file_name.replace('/', '%2F')
1080
1084
  response = kaggle.competitions.competition_api_client.download_data_file(
1081
1085
  request)
1082
- url = response.history[0].url
1083
- outfile = os.path.join(effective_path, url.split('?')[0].split('/')[-1])
1084
-
1085
- if force or self.download_needed(response, outfile, quiet):
1086
- self.download_file(response, outfile, kaggle.http_client(), quiet,
1087
- not force)
1086
+ url = response.history[0].url.replace('%2F', '/')
1087
+ outfile = os.path.join(effective_path, url.split('?')[0].split('/')[-1])
1088
+
1089
+ if force or self.download_needed(response, outfile, quiet):
1090
+ self.download_file(response, outfile, kaggle.http_client(), quiet,
1091
+ not force)
1088
1092
 
1089
1093
  def competition_download_files(self,
1090
1094
  competition,
1091
1095
  path=None,
1092
1096
  force=False,
1093
1097
  quiet=True):
1094
- """ Download all competition files.
1095
-
1096
- Parameters
1097
- =========
1098
- competition: the name of the competition
1099
- path: a path to download the file to
1100
- force: force the download if the file already exists (default False)
1101
- quiet: suppress verbose output (default is True)
1102
- """
1098
+ """Download all competition files.
1099
+
1100
+ Parameters
1101
+ =========
1102
+ competition: the name of the competition
1103
+ path: a path to download the file to
1104
+ force: force the download if the file already exists (default False)
1105
+ quiet: suppress verbose output (default is True)
1106
+ """
1103
1107
  if path is None:
1104
1108
  effective_path = self.get_default_download_dir('competitions',
1105
1109
  competition)
@@ -1111,12 +1115,12 @@ class KaggleApi:
1111
1115
  request.competition_name = competition
1112
1116
  response = kaggle.competitions.competition_api_client.download_data_files(
1113
1117
  request)
1114
- url = response.url.split('?')[0]
1115
- outfile = os.path.join(effective_path,
1116
- competition + '.' + url.split('.')[-1])
1117
-
1118
- if force or self.download_needed(response, outfile, quiet):
1119
- self.download_file(response, outfile, quiet, not force)
1118
+ url = response.url.split('?')[0]
1119
+ outfile = os.path.join(effective_path,
1120
+ competition + '.' + url.split('.')[-1])
1121
+
1122
+ if force or self.download_needed(response, outfile, quiet):
1123
+ self.download_file(response, outfile, kaggle.http_client(), quiet, not force)
1120
1124
 
1121
1125
  def competition_download_cli(self,
1122
1126
  competition,
@@ -1125,19 +1129,19 @@ class KaggleApi:
1125
1129
  path=None,
1126
1130
  force=False,
1127
1131
  quiet=False):
1128
- """ A wrapper to competition_download_files, but first will parse input
1129
- from API client. Additional parameters are listed here, see
1130
- competition_download for remaining.
1131
-
1132
- Parameters
1133
- =========
1134
- competition: the name of the competition
1135
- competition_opt: an alternative competition option provided by cli
1136
- file_name: the configuration file name
1137
- path: a path to download the file to
1138
- force: force the download if the file already exists (default False)
1139
- quiet: suppress verbose output (default is False)
1140
- """
1132
+ """A wrapper to competition_download_files, but first will parse input from
1133
+ API client. Additional parameters are listed here, see competition_download
1134
+ for remaining.
1135
+
1136
+ Parameters
1137
+ =========
1138
+ competition: the name of the competition
1139
+ competition_opt: an alternative competition option provided by cli
1140
+ file_name: the configuration file name
1141
+ path: a path to download the file to
1142
+ force: force the download if the file already exists (default False)
1143
+ quiet: suppress verbose output (default is False)
1144
+ """
1141
1145
  competition = competition or competition_opt
1142
1146
  if competition is None:
1143
1147
  competition = self.get_config_value(self.CONFIG_NAME_COMPETITION)
@@ -1154,36 +1158,36 @@ class KaggleApi:
1154
1158
  quiet)
1155
1159
 
1156
1160
  def competition_leaderboard_download(self, competition, path, quiet=True):
1157
- """ Download a competition leaderboard.
1161
+ """Download a competition leaderboard.
1158
1162
 
1159
- Parameters
1160
- =========
1161
- competition: the name of the competition
1162
- path: a path to download the file to
1163
- quiet: suppress verbose output (default is True)
1164
- """
1163
+ Parameters
1164
+ =========
1165
+ competition: the name of the competition
1166
+ path: a path to download the file to
1167
+ quiet: suppress verbose output (default is True)
1168
+ """
1165
1169
  with self.build_kaggle_client() as kaggle:
1166
1170
  request = ApiDownloadLeaderboardRequest()
1167
1171
  request.competition_name = competition
1168
1172
  response = kaggle.competitions.competition_api_client.download_leaderboard(
1169
1173
  request)
1170
- if path is None:
1171
- effective_path = self.get_default_download_dir('competitions',
1172
- competition)
1173
- else:
1174
- effective_path = path
1175
-
1176
- file_name = competition + '.zip'
1177
- outfile = os.path.join(effective_path, file_name)
1178
- self.download_file(response, outfile, quiet)
1174
+ if path is None:
1175
+ effective_path = self.get_default_download_dir('competitions',
1176
+ competition)
1177
+ else:
1178
+ effective_path = path
1179
+
1180
+ file_name = competition + '.zip'
1181
+ outfile = os.path.join(effective_path, file_name)
1182
+ self.download_file(response, outfile, kaggle.http_client(), quiet)
1179
1183
 
1180
1184
  def competition_leaderboard_view(self, competition):
1181
- """ View a leaderboard based on a competition name.
1185
+ """View a leaderboard based on a competition name.
1182
1186
 
1183
- Parameters
1184
- ==========
1185
- competition: the competition name to view leadboard for
1186
- """
1187
+ Parameters
1188
+ ==========
1189
+ competition: the competition name to view leadboard for
1190
+ """
1187
1191
  with self.build_kaggle_client() as kaggle:
1188
1192
  request = ApiGetLeaderboardRequest()
1189
1193
  request.competition_name = competition
@@ -1199,19 +1203,19 @@ class KaggleApi:
1199
1203
  download=False,
1200
1204
  csv_display=False,
1201
1205
  quiet=False):
1202
- """ A wrapper for competition_leaderbord_view that will print the
1203
- results as a table or comma separated values
1204
-
1205
- Parameters
1206
- ==========
1207
- competition: the competition name to view leadboard for
1208
- competition_opt: an alternative competition option provided by cli
1209
- path: a path to download to, if download is True
1210
- view: if True, show the results in the terminal as csv or table
1211
- download: if True, download the entire leaderboard
1212
- csv_display: if True, print comma separated values instead of table
1213
- quiet: suppress verbose output (default is False)
1214
- """
1206
+ """A wrapper for competition_leaderbord_view that will print the results as
1207
+ a table or comma separated values.
1208
+
1209
+ Parameters
1210
+ ==========
1211
+ competition: the competition name to view leadboard for
1212
+ competition_opt: an alternative competition option provided by cli
1213
+ path: a path to download to, if download is True
1214
+ view: if True, show the results in the terminal as csv or table
1215
+ download: if True, download the entire leaderboard
1216
+ csv_display: if True, print comma separated values instead of table
1217
+ quiet: suppress verbose output (default is False)
1218
+ """
1215
1219
  competition = competition or competition_opt
1216
1220
  if not view and not download:
1217
1221
  raise ValueError('Either --show or --download must be specified')
@@ -1249,22 +1253,22 @@ class KaggleApi:
1249
1253
  page=1,
1250
1254
  max_size=None,
1251
1255
  min_size=None):
1252
- """ Return a list of datasets.
1253
-
1254
- Parameters
1255
- ==========
1256
- sort_by: how to sort the result, see valid_dataset_sort_bys for options
1257
- size: Deprecated
1258
- file_type: the format, see valid_dataset_file_types for string options
1259
- license_name: string descriptor for license, see valid_dataset_license_names
1260
- tag_ids: tag identifiers to filter the search
1261
- search: a search term to use (default is empty string)
1262
- user: username to filter the search to
1263
- mine: boolean if True, group is changed to "my" to return personal
1264
- page: the page to return (default is 1)
1265
- max_size: the maximum size of the dataset to return (bytes)
1266
- min_size: the minimum size of the dataset to return (bytes)
1267
- """
1256
+ """Return a list of datasets.
1257
+
1258
+ Parameters
1259
+ ==========
1260
+ sort_by: how to sort the result, see valid_dataset_sort_bys for options
1261
+ size: Deprecated
1262
+ file_type: the format, see valid_dataset_file_types for string options
1263
+ license_name: string descriptor for license, see valid_dataset_license_names
1264
+ tag_ids: tag identifiers to filter the search
1265
+ search: a search term to use (default is empty string)
1266
+ user: username to filter the search to
1267
+ mine: boolean if True, group is changed to "my" to return personal
1268
+ page: the page to return (default is 1)
1269
+ max_size: the maximum size of the dataset to return (bytes)
1270
+ min_size: the minimum size of the dataset to return (bytes)
1271
+ """
1268
1272
  if sort_by:
1269
1273
  if sort_by not in self.valid_dataset_sort_bys:
1270
1274
  raise ValueError('Invalid sort by specified. Valid options are ' +
@@ -1338,24 +1342,24 @@ class KaggleApi:
1338
1342
  csv_display=False,
1339
1343
  max_size=None,
1340
1344
  min_size=None):
1341
- """ A wrapper to dataset_list for the client. Additional parameters
1342
- are described here, see dataset_list for others.
1343
-
1344
- Parameters
1345
- ==========
1346
- sort_by: how to sort the result, see valid_dataset_sort_bys for options
1347
- size: DEPRECATED
1348
- file_type: the format, see valid_dataset_file_types for string options
1349
- license_name: string descriptor for license, see valid_dataset_license_names
1350
- tag_ids: tag identifiers to filter the search
1351
- search: a search term to use (default is empty string)
1352
- user: username to filter the search to
1353
- mine: boolean if True, group is changed to "my" to return personal
1354
- page: the page to return (default is 1)
1355
- csv_display: if True, print comma separated values instead of table
1356
- max_size: the maximum size of the dataset to return (bytes)
1357
- min_size: the minimum size of the dataset to return (bytes)
1358
- """
1345
+ """A wrapper to dataset_list for the client. Additional parameters are
1346
+ described here, see dataset_list for others.
1347
+
1348
+ Parameters
1349
+ ==========
1350
+ sort_by: how to sort the result, see valid_dataset_sort_bys for options
1351
+ size: DEPRECATED
1352
+ file_type: the format, see valid_dataset_file_types for string options
1353
+ license_name: string descriptor for license, see valid_dataset_license_names
1354
+ tag_ids: tag identifiers to filter the search
1355
+ search: a search term to use (default is empty string)
1356
+ user: username to filter the search to
1357
+ mine: boolean if True, group is changed to "my" to return personal
1358
+ page: the page to return (default is 1)
1359
+ csv_display: if True, print comma separated values instead of table
1360
+ max_size: the maximum size of the dataset to return (bytes)
1361
+ min_size: the minimum size of the dataset to return (bytes)
1362
+ """
1359
1363
  datasets = self.dataset_list(sort_by, size, file_type, license_name,
1360
1364
  tag_ids, search, user, mine, page, max_size,
1361
1365
  min_size)
@@ -1469,14 +1473,14 @@ class KaggleApi:
1469
1473
  print('Downloaded metadata to ' + meta_file)
1470
1474
 
1471
1475
  def dataset_list_files(self, dataset, page_token=None, page_size=20):
1472
- """ List files for a dataset.
1473
-
1474
- Parameters
1475
- ==========
1476
- dataset: the string identified of the dataset
1477
- should be in format [owner]/[dataset-name]
1478
- page_token: the page token for pagination
1479
- page_size: the number of items per page
1476
+ """List files for a dataset.
1477
+
1478
+ Parameters
1479
+ ==========
1480
+ dataset: the string identified of the dataset
1481
+ should be in format [owner]/[dataset-name]
1482
+ page_token: the page token for pagination
1483
+ page_size: the number of items per page
1480
1484
  """
1481
1485
  if dataset is None:
1482
1486
  raise ValueError('A dataset must be specified')
@@ -1499,17 +1503,18 @@ class KaggleApi:
1499
1503
  csv_display=False,
1500
1504
  page_token=None,
1501
1505
  page_size=20):
1502
- """ A wrapper to dataset_list_files for the client
1503
- (list files for a dataset).
1504
- Parameters
1505
- ==========
1506
- dataset: the string identified of the dataset
1507
- should be in format [owner]/[dataset-name]
1508
- dataset_opt: an alternative option to providing a dataset
1509
- csv_display: if True, print comma separated values instead of table
1510
- page_token: the page token for pagination
1511
- page_size: the number of items per page
1512
- """
1506
+ """A wrapper to dataset_list_files for the client (list files for a
1507
+ dataset).
1508
+
1509
+ Parameters
1510
+ ==========
1511
+ dataset: the string identified of the dataset
1512
+ should be in format [owner]/[dataset-name]
1513
+ dataset_opt: an alternative option to providing a dataset
1514
+ csv_display: if True, print comma separated values instead of table
1515
+ page_token: the page token for pagination
1516
+ page_size: the number of items per page
1517
+ """
1513
1518
  dataset = dataset or dataset_opt
1514
1519
  result = self.dataset_list_files(dataset, page_token, page_size)
1515
1520
 
@@ -1530,11 +1535,12 @@ class KaggleApi:
1530
1535
  print('No files found')
1531
1536
 
1532
1537
  def dataset_status(self, dataset):
1533
- """ Call to get the status of a dataset from the API.
1534
- Parameters
1535
- ==========
1536
- dataset: the string identifier of the dataset
1537
- should be in format [owner]/[dataset-name]
1538
+ """Call to get the status of a dataset from the API.
1539
+
1540
+ Parameters
1541
+ ==========
1542
+ dataset: the string identifier of the dataset
1543
+ should be in format [owner]/[dataset-name]
1538
1544
  """
1539
1545
  if dataset is None:
1540
1546
  raise ValueError('A dataset must be specified')
@@ -1555,12 +1561,13 @@ class KaggleApi:
1555
1561
  return response.status.name.lower()
1556
1562
 
1557
1563
  def dataset_status_cli(self, dataset, dataset_opt=None):
1558
- """ A wrapper for client for dataset_status, with additional
1559
- dataset_opt to get the status of a dataset from the API.
1560
- Parameters
1561
- ==========
1562
- dataset_opt: an alternative to dataset
1563
- """
1564
+ """A wrapper for client for dataset_status, with additional dataset_opt to
1565
+ get the status of a dataset from the API.
1566
+
1567
+ Parameters
1568
+ ==========
1569
+ dataset_opt: an alternative to dataset
1570
+ """
1564
1571
  dataset = dataset or dataset_opt
1565
1572
  return self.dataset_status(dataset)
1566
1573
 
@@ -1571,17 +1578,17 @@ class KaggleApi:
1571
1578
  force=False,
1572
1579
  quiet=True,
1573
1580
  licenses=[]):
1574
- """ Download a single file for a dataset.
1575
-
1576
- Parameters
1577
- ==========
1578
- dataset: the string identified of the dataset
1579
- should be in format [owner]/[dataset-name]
1580
- file_name: the dataset configuration file
1581
- path: if defined, download to this location
1582
- force: force the download if the file already exists (default False)
1583
- quiet: suppress verbose output (default is True)
1584
- licenses: a list of license names, e.g. ['CC0-1.0']
1581
+ """Download a single file for a dataset.
1582
+
1583
+ Parameters
1584
+ ==========
1585
+ dataset: the string identified of the dataset
1586
+ should be in format [owner]/[dataset-name]
1587
+ file_name: the dataset configuration file
1588
+ path: if defined, download to this location
1589
+ force: force the download if the file already exists (default False)
1590
+ quiet: suppress verbose output (default is True)
1591
+ licenses: a list of license names, e.g. ['CC0-1.0']
1585
1592
  """
1586
1593
  if '/' in dataset:
1587
1594
  self.validate_dataset_string(dataset)
@@ -1608,14 +1615,14 @@ class KaggleApi:
1608
1615
  request.dataset_version_number = dataset_version_number
1609
1616
  request.file_name = file_name
1610
1617
  response = kaggle.datasets.dataset_api_client.download_dataset(request)
1611
- url = response.history[0].url
1612
- outfile = os.path.join(effective_path, url.split('?')[0].split('/')[-1])
1613
-
1614
- if force or self.download_needed(response, outfile, quiet):
1615
- self.download_file(response, outfile, quiet, not force)
1616
- return True
1617
- else:
1618
- return False
1618
+ url = response.history[0].url
1619
+ outfile = os.path.join(effective_path, url.split('?')[0].split('/')[-1])
1620
+
1621
+ if force or self.download_needed(response, outfile, quiet):
1622
+ self.download_file(response, outfile, kaggle.http_client(), quiet, not force)
1623
+ return True
1624
+ else:
1625
+ return False
1619
1626
 
1620
1627
  def dataset_download_files(self,
1621
1628
  dataset,
@@ -1624,17 +1631,17 @@ class KaggleApi:
1624
1631
  quiet=True,
1625
1632
  unzip=False,
1626
1633
  licenses=[]):
1627
- """ Download all files for a dataset.
1628
-
1629
- Parameters
1630
- ==========
1631
- dataset: the string identified of the dataset
1632
- should be in format [owner]/[dataset-name]
1633
- path: the path to download the dataset to
1634
- force: force the download if the file already exists (default False)
1635
- quiet: suppress verbose output (default is True)
1636
- unzip: if True, unzip files upon download (default is False)
1637
- licenses: a list of license names, e.g. ['CC0-1.0']
1634
+ """Download all files for a dataset.
1635
+
1636
+ Parameters
1637
+ ==========
1638
+ dataset: the string identified of the dataset
1639
+ should be in format [owner]/[dataset-name]
1640
+ path: the path to download the dataset to
1641
+ force: force the download if the file already exists (default False)
1642
+ quiet: suppress verbose output (default is True)
1643
+ unzip: if True, unzip files upon download (default is False)
1644
+ licenses: a list of license names, e.g. ['CC0-1.0']
1638
1645
  """
1639
1646
  if dataset is None:
1640
1647
  raise ValueError('A dataset must be specified')
@@ -1656,39 +1663,39 @@ class KaggleApi:
1656
1663
  request.dataset_version_number = dataset_version_number
1657
1664
  response = kaggle.datasets.dataset_api_client.download_dataset(request)
1658
1665
 
1659
- outfile = os.path.join(effective_path, dataset_slug + '.zip')
1660
- if force or self.download_needed(response, outfile, quiet):
1661
- self.download_file(response, outfile, quiet, not force)
1662
- downloaded = True
1663
- else:
1664
- downloaded = False
1665
-
1666
- if downloaded:
1667
1666
  outfile = os.path.join(effective_path, dataset_slug + '.zip')
1668
- if unzip:
1669
- try:
1670
- with zipfile.ZipFile(outfile) as z:
1671
- z.extractall(effective_path)
1672
- except zipfile.BadZipFile as e:
1673
- raise ValueError(
1674
- f"The file {outfile} is corrupted or not a valid zip file. "
1675
- "Please report this issue at https://www.github.com/kaggle/kaggle-api"
1676
- )
1677
- except FileNotFoundError:
1678
- raise FileNotFoundError(
1679
- f"The file {outfile} was not found. "
1680
- "Please report this issue at https://www.github.com/kaggle/kaggle-api"
1681
- )
1682
- except Exception as e:
1683
- raise RuntimeError(
1684
- f"An unexpected error occurred: {e}. "
1685
- "Please report this issue at https://www.github.com/kaggle/kaggle-api"
1686
- )
1687
-
1688
- try:
1689
- os.remove(outfile)
1690
- except OSError as e:
1691
- print('Could not delete zip file, got %s' % e)
1667
+ if force or self.download_needed(response, outfile, quiet):
1668
+ self.download_file(response, outfile, kaggle.http_client(), quiet, not force)
1669
+ downloaded = True
1670
+ else:
1671
+ downloaded = False
1672
+
1673
+ if downloaded:
1674
+ outfile = os.path.join(effective_path, dataset_slug + '.zip')
1675
+ if unzip:
1676
+ try:
1677
+ with zipfile.ZipFile(outfile) as z:
1678
+ z.extractall(effective_path)
1679
+ except zipfile.BadZipFile as e:
1680
+ raise ValueError(
1681
+ f"The file {outfile} is corrupted or not a valid zip file. "
1682
+ "Please report this issue at https://www.github.com/kaggle/kaggle-api"
1683
+ )
1684
+ except FileNotFoundError:
1685
+ raise FileNotFoundError(
1686
+ f"The file {outfile} was not found. "
1687
+ "Please report this issue at https://www.github.com/kaggle/kaggle-api"
1688
+ )
1689
+ except Exception as e:
1690
+ raise RuntimeError(
1691
+ f"An unexpected error occurred: {e}. "
1692
+ "Please report this issue at https://www.github.com/kaggle/kaggle-api"
1693
+ )
1694
+
1695
+ try:
1696
+ os.remove(outfile)
1697
+ except OSError as e:
1698
+ print('Could not delete zip file, got %s' % e)
1692
1699
 
1693
1700
  def _print_dataset_url_and_license(self, owner_slug, dataset_slug,
1694
1701
  dataset_version_number, licenses):
@@ -1710,21 +1717,21 @@ class KaggleApi:
1710
1717
  unzip=False,
1711
1718
  force=False,
1712
1719
  quiet=False):
1713
- """ Client wrapper for dataset_download_files and download dataset file,
1714
- either for a specific file (when file_name is provided),
1715
- or all files for a dataset (plural).
1716
-
1717
- Parameters
1718
- ==========
1719
- dataset: the string identified of the dataset
1720
- should be in format [owner]/[dataset-name]
1721
- dataset_opt: an alternative option to providing a dataset
1722
- file_name: the dataset configuration file
1723
- path: the path to download the dataset to
1724
- force: force the download if the file already exists (default False)
1725
- quiet: suppress verbose output (default is False)
1726
- unzip: if True, unzip files upon download (default is False)
1727
- """
1720
+ """Client wrapper for dataset_download_files and download dataset file,
1721
+ either for a specific file (when file_name is provided), or all files for a
1722
+ dataset (plural).
1723
+
1724
+ Parameters
1725
+ ==========
1726
+ dataset: the string identified of the dataset
1727
+ should be in format [owner]/[dataset-name]
1728
+ dataset_opt: an alternative option to providing a dataset
1729
+ file_name: the dataset configuration file
1730
+ path: the path to download the dataset to
1731
+ force: force the download if the file already exists (default False)
1732
+ quiet: suppress verbose output (default is False)
1733
+ unzip: if True, unzip files upon download (default is False)
1734
+ """
1728
1735
  dataset = dataset or dataset_opt
1729
1736
 
1730
1737
  owner_slug, dataset_slug, _ = self.split_dataset_string(dataset)
@@ -1768,15 +1775,15 @@ class KaggleApi:
1768
1775
  licenses=licenses)
1769
1776
 
1770
1777
  def _upload_blob(self, path, quiet, blob_type, upload_context):
1771
- """ Upload a file.
1772
-
1773
- Parameters
1774
- ==========
1775
- path: the complete path to upload
1776
- quiet: suppress verbose output (default is False)
1777
- blob_type (ApiBlobType): To which entity the file/blob refers
1778
- upload_context (ResumableUploadContext): Context for resumable uploads
1779
- """
1778
+ """Upload a file.
1779
+
1780
+ Parameters
1781
+ ==========
1782
+ path: the complete path to upload
1783
+ quiet: suppress verbose output (default is False)
1784
+ blob_type (ApiBlobType): To which entity the file/blob refers
1785
+ upload_context (ResumableUploadContext): Context for resumable uploads
1786
+ """
1780
1787
  file_name = os.path.basename(path)
1781
1788
  content_length = os.path.getsize(path)
1782
1789
  last_modified_epoch_seconds = int(os.path.getmtime(path))
@@ -1823,17 +1830,17 @@ class KaggleApi:
1823
1830
  convert_to_csv=True,
1824
1831
  delete_old_versions=False,
1825
1832
  dir_mode='skip'):
1826
- """ Create a version of a dataset.
1827
-
1828
- Parameters
1829
- ==========
1830
- folder: the folder with the dataset configuration / data files
1831
- version_notes: notes to add for the version
1832
- quiet: suppress verbose output (default is False)
1833
- convert_to_csv: on upload, if data should be converted to csv
1834
- delete_old_versions: if True, do that (default False)
1835
- dir_mode: What to do with directories: "skip" - ignore; "zip" - compress and upload
1836
- """
1833
+ """Create a version of a dataset.
1834
+
1835
+ Parameters
1836
+ ==========
1837
+ folder: the folder with the dataset configuration / data files
1838
+ version_notes: notes to add for the version
1839
+ quiet: suppress verbose output (default is False)
1840
+ convert_to_csv: on upload, if data should be converted to csv
1841
+ delete_old_versions: if True, do that (default False)
1842
+ dir_mode: What to do with directories: "skip" - ignore; "zip" - compress and upload
1843
+ """
1837
1844
  if not os.path.isdir(folder):
1838
1845
  raise ValueError('Invalid folder: ' + folder)
1839
1846
 
@@ -1906,16 +1913,17 @@ class KaggleApi:
1906
1913
  convert_to_csv=True,
1907
1914
  delete_old_versions=False,
1908
1915
  dir_mode='skip'):
1909
- """ client wrapper for creating a version of a dataset
1910
- Parameters
1911
- ==========
1912
- folder: the folder with the dataset configuration / data files
1913
- version_notes: notes to add for the version
1914
- quiet: suppress verbose output (default is False)
1915
- convert_to_csv: on upload, if data should be converted to csv
1916
- delete_old_versions: if True, do that (default False)
1917
- dir_mode: What to do with directories: "skip" - ignore; "zip" - compress and upload
1918
- """
1916
+ """Client wrapper for creating a version of a dataset.
1917
+
1918
+ Parameters
1919
+ ==========
1920
+ folder: the folder with the dataset configuration / data files
1921
+ version_notes: notes to add for the version
1922
+ quiet: suppress verbose output (default is False)
1923
+ convert_to_csv: on upload, if data should be converted to csv
1924
+ delete_old_versions: if True, do that (default False)
1925
+ dir_mode: What to do with directories: "skip" - ignore; "zip" - compress and upload
1926
+ """
1919
1927
  folder = folder or os.getcwd()
1920
1928
  result = self.dataset_create_version(
1921
1929
  folder,
@@ -1937,12 +1945,12 @@ class KaggleApi:
1937
1945
  print('Dataset version creation error: ' + result.error)
1938
1946
 
1939
1947
  def dataset_initialize(self, folder):
1940
- """ initialize a folder with a a dataset configuration (metadata) file
1948
+ """Initialize a folder with a dataset configuration (metadata) file.
1941
1949
 
1942
- Parameters
1943
- ==========
1944
- folder: the folder to initialize the metadata file in
1945
- """
1950
+ Parameters
1951
+ ==========
1952
+ folder: the folder to initialize the metadata file in
1953
+ """
1946
1954
  if not os.path.isdir(folder):
1947
1955
  raise ValueError('Invalid folder: ' + folder)
1948
1956
 
@@ -1969,16 +1977,16 @@ class KaggleApi:
1969
1977
  quiet=False,
1970
1978
  convert_to_csv=True,
1971
1979
  dir_mode='skip'):
1972
- """ Create a new dataset, meaning the same as creating a version but
1973
- with extra metadata like license and user/owner.
1974
-
1975
- Parameters
1976
- ==========
1977
- folder: the folder to get the metadata file from
1978
- public: should the dataset be public?
1979
- quiet: suppress verbose output (default is False)
1980
- convert_to_csv: if True, convert data to comma separated value
1981
- dir_mode: What to do with directories: "skip" - ignore; "zip" - compress and upload
1980
+ """Create a new dataset, meaning the same as creating a version but with
1981
+ extra metadata like license and user/owner.
1982
+
1983
+ Parameters
1984
+ ==========
1985
+ folder: the folder to get the metadata file from
1986
+ public: should the dataset be public?
1987
+ quiet: suppress verbose output (default is False)
1988
+ convert_to_csv: if True, convert data to comma separated value
1989
+ dir_mode: What to do with directories: "skip" - ignore; "zip" - compress and upload
1982
1990
  """
1983
1991
  if not os.path.isdir(folder):
1984
1992
  raise ValueError('Invalid folder: ' + folder)
@@ -2092,17 +2100,17 @@ class KaggleApi:
2092
2100
  quiet=True,
2093
2101
  resume=False,
2094
2102
  chunk_size=1048576):
2095
- """ download a file to an output file based on a chunk size
2096
-
2097
- Parameters
2098
- ==========
2099
- response: the response to download
2100
- outfile: the output file to download to
2101
- http_client: the Kaggle http client to use
2102
- quiet: suppress verbose output (default is True)
2103
- chunk_size: the size of the chunk to stream
2104
- resume: whether to resume an existing download
2105
- """
2103
+ """Download a file to an output file based on a chunk size.
2104
+
2105
+ Parameters
2106
+ ==========
2107
+ response: the response to download
2108
+ outfile: the output file to download to
2109
+ http_client: the Kaggle http client to use
2110
+ quiet: suppress verbose output (default is True)
2111
+ chunk_size: the size of the chunk to stream
2112
+ resume: whether to resume an existing download
2113
+ """
2106
2114
 
2107
2115
  outpath = os.path.dirname(outfile)
2108
2116
  if not os.path.exists(outpath):
@@ -2190,23 +2198,23 @@ class KaggleApi:
2190
2198
  kernel_type=None,
2191
2199
  output_type=None,
2192
2200
  sort_by=None):
2193
- """ List kernels based on a set of search criteria.
2194
-
2195
- Parameters
2196
- ==========
2197
- page: the page of results to return (default is 1)
2198
- page_size: results per page (default is 20)
2199
- dataset: if defined, filter to this dataset (default None)
2200
- competition: if defined, filter to this competition (default None)
2201
- parent_kernel: if defined, filter to those with specified parent
2202
- search: a custom search string to pass to the list query
2203
- mine: if true, group is specified as "my" to return personal kernels
2204
- user: filter results to a specific user
2205
- language: the programming language of the kernel
2206
- kernel_type: the type of kernel, one of valid_list_kernel_types (str)
2207
- output_type: the output type, one of valid_list_output_types (str)
2208
- sort_by: if defined, sort results by this string (valid_list_sort_by)
2209
- """
2201
+ """List kernels based on a set of search criteria.
2202
+
2203
+ Parameters
2204
+ ==========
2205
+ page: the page of results to return (default is 1)
2206
+ page_size: results per page (default is 20)
2207
+ dataset: if defined, filter to this dataset (default None)
2208
+ competition: if defined, filter to this competition (default None)
2209
+ parent_kernel: if defined, filter to those with specified parent
2210
+ search: a custom search string to pass to the list query
2211
+ mine: if true, group is specified as "my" to return personal kernels
2212
+ user: filter results to a specific user
2213
+ language: the programming language of the kernel
2214
+ kernel_type: the type of kernel, one of valid_list_kernel_types (str)
2215
+ output_type: the output type, one of valid_list_output_types (str)
2216
+ sort_by: if defined, sort results by this string (valid_list_sort_by)
2217
+ """
2210
2218
  if int(page) <= 0:
2211
2219
  raise ValueError('Page number must be >= 1')
2212
2220
 
@@ -2262,22 +2270,6 @@ class KaggleApi:
2262
2270
  request.search = search or ''
2263
2271
  return kaggle.kernels.kernels_api_client.list_kernels(request).kernels
2264
2272
 
2265
- kernels_list_result = self.process_response(
2266
- self.kernels_list_with_http_info(
2267
- page=page,
2268
- page_size=page_size,
2269
- group=group,
2270
- user=user or '',
2271
- language=language or 'all',
2272
- kernel_type=kernel_type or 'all',
2273
- output_type=output_type or 'all',
2274
- sort_by=sort_by or 'hotness',
2275
- dataset=dataset or '',
2276
- competition=competition or '',
2277
- parent_kernel=parent_kernel or '',
2278
- search=search or ''))
2279
- return [Kernel(k) for k in kernels_list_result]
2280
-
2281
2273
  def kernels_list_cli(self,
2282
2274
  mine=False,
2283
2275
  page=1,
@@ -2292,12 +2284,13 @@ class KaggleApi:
2292
2284
  kernel_type=None,
2293
2285
  output_type=None,
2294
2286
  sort_by=None):
2295
- """ Client wrapper for kernels_list, see this function for arguments.
2296
- Additional arguments are provided here.
2297
- Parameters
2298
- ==========
2299
- csv_display: if True, print comma separated values instead of table
2300
- """
2287
+ """Client wrapper for kernels_list, see this function for arguments.
2288
+
2289
+ Additional arguments are provided here.
2290
+ Parameters
2291
+ ==========
2292
+ csv_display: if True, print comma separated values instead of table
2293
+ """
2301
2294
  kernels = self.kernels_list(
2302
2295
  page=page,
2303
2296
  page_size=page_size,
@@ -2348,17 +2341,18 @@ class KaggleApi:
2348
2341
  csv_display=False,
2349
2342
  page_token=None,
2350
2343
  page_size=20):
2351
- """ A wrapper to kernel_list_files for the client.
2352
- (list files for a kernel)
2353
- Parameters
2354
- ==========
2355
- kernel: the string identifier of the kernel
2356
- should be in format [owner]/[kernel-name]
2357
- kernel_opt: an alternative option to providing a kernel
2358
- csv_display: if True, print comma separated values instead of table
2359
- page_token: the page token for pagination
2360
- page_size: the number of items per page
2361
- """
2344
+ """A wrapper to kernel_list_files for the client.
2345
+
2346
+ (list files for a kernel)
2347
+ Parameters
2348
+ ==========
2349
+ kernel: the string identifier of the kernel
2350
+ should be in format [owner]/[kernel-name]
2351
+ kernel_opt: an alternative option to providing a kernel
2352
+ csv_display: if True, print comma separated values instead of table
2353
+ page_token: the page token for pagination
2354
+ page_size: the number of items per page
2355
+ """
2362
2356
  kernel = kernel or kernel_opt
2363
2357
  result = self.kernels_list_files(kernel, page_token, page_size)
2364
2358
 
@@ -2376,12 +2370,13 @@ class KaggleApi:
2376
2370
  self.print_table(result.files, fields)
2377
2371
 
2378
2372
  def kernels_initialize(self, folder):
2379
- """ Create a new kernel in a specified folder from a template, including
2380
- json metadata that grabs values from the configuration.
2381
- Parameters
2382
- ==========
2383
- folder: the path of the folder
2384
- """
2373
+ """Create a new kernel in a specified folder from a template, including
2374
+ json metadata that grabs values from the configuration.
2375
+
2376
+ Parameters
2377
+ ==========
2378
+ folder: the path of the folder
2379
+ """
2385
2380
  if not os.path.isdir(folder):
2386
2381
  raise ValueError('Invalid folder: ' + folder)
2387
2382
 
@@ -2423,25 +2418,28 @@ class KaggleApi:
2423
2418
  return meta_file
2424
2419
 
2425
2420
  def kernels_initialize_cli(self, folder=None):
2426
- """ A client wrapper for kernels_initialize. It takes same arguments but
2427
- sets default folder to be None. If None, defaults to present
2428
- working directory.
2429
- Parameters
2430
- ==========
2431
- folder: the path of the folder (None defaults to ${PWD})
2432
- """
2421
+ """A client wrapper for kernels_initialize.
2422
+
2423
+ It takes same arguments but
2424
+ sets default folder to be None. If None, defaults to present
2425
+ working directory.
2426
+ Parameters
2427
+ ==========
2428
+ folder: the path of the folder (None defaults to ${PWD})
2429
+ """
2433
2430
  folder = folder or os.getcwd()
2434
2431
  meta_file = self.kernels_initialize(folder)
2435
2432
  print('Kernel metadata template written to: ' + meta_file)
2436
2433
 
2437
2434
  def kernels_push(self, folder, timeout=None) -> ApiSaveKernelResponse:
2438
- """ Read the metadata file and kernel files from a notebook, validate
2439
- both, and use the Kernel API to push to Kaggle if all is valid.
2440
- Parameters
2441
- ==========
2442
- folder: the path of the folder
2443
- timeout: maximum run time iin seconds
2444
- """
2435
+ """Read the metadata file and kernel files from a notebook, validate both,
2436
+ and use the Kernel API to push to Kaggle if all is valid.
2437
+
2438
+ Parameters
2439
+ ==========
2440
+ folder: the path of the folder
2441
+ timeout: maximum run time iin seconds
2442
+ """
2445
2443
  if not os.path.isdir(folder):
2446
2444
  raise ValueError('Invalid folder: ' + folder)
2447
2445
 
@@ -2558,12 +2556,13 @@ class KaggleApi:
2558
2556
  return kaggle.kernels.kernels_api_client.save_kernel(request)
2559
2557
 
2560
2558
  def kernels_push_cli(self, folder, timeout):
2561
- """ Client wrapper for kernels_push.
2562
- Parameters
2563
- ==========
2564
- folder: the path of the folder
2565
- timeout: maximum run time in seconds
2566
- """
2559
+ """Client wrapper for kernels_push.
2560
+
2561
+ Parameters
2562
+ ==========
2563
+ folder: the path of the folder
2564
+ timeout: maximum run time in seconds
2565
+ """
2567
2566
  folder = folder or os.getcwd()
2568
2567
  result = self.kernels_push(folder, timeout)
2569
2568
 
@@ -2595,15 +2594,16 @@ class KaggleApi:
2595
2594
  print('Kernel push error: ' + result.error)
2596
2595
 
2597
2596
  def kernels_pull(self, kernel, path, metadata=False, quiet=True):
2598
- """ Pull a kernel, including a metadata file (if metadata is True)
2599
- and associated files to a specified path.
2600
- Parameters
2601
- ==========
2602
- kernel: the kernel to pull
2603
- path: the path to pull files to on the filesystem
2604
- metadata: if True, also pull metadata
2605
- quiet: suppress verbosity (default is True)
2606
- """
2597
+ """Pull a kernel, including a metadata file (if metadata is True) and
2598
+ associated files to a specified path.
2599
+
2600
+ Parameters
2601
+ ==========
2602
+ kernel: the kernel to pull
2603
+ path: the path to pull files to on the filesystem
2604
+ metadata: if True, also pull metadata
2605
+ quiet: suppress verbosity (default is True)
2606
+ """
2607
2607
  existing_metadata = None
2608
2608
  if kernel is None:
2609
2609
  if path is None:
@@ -2729,8 +2729,7 @@ class KaggleApi:
2729
2729
  kernel_opt=None,
2730
2730
  path=None,
2731
2731
  metadata=False):
2732
- """ Client wrapper for kernels_pull.
2733
- """
2732
+ """Client wrapper for kernels_pull."""
2734
2733
  kernel = kernel or kernel_opt
2735
2734
  effective_path = self.kernels_pull(
2736
2735
  kernel, path=path, metadata=metadata, quiet=False)
@@ -2740,14 +2739,15 @@ class KaggleApi:
2740
2739
  print('Source code downloaded to ' + effective_path)
2741
2740
 
2742
2741
  def kernels_output(self, kernel, path, force=False, quiet=True):
2743
- """ Retrieve the output for a specified kernel.
2744
- Parameters
2745
- ==========
2746
- kernel: the kernel to output
2747
- path: the path to pull files to on the filesystem
2748
- force: if output already exists, force overwrite (default False)
2749
- quiet: suppress verbosity (default is True)
2750
- """
2742
+ """Retrieve the output for a specified kernel.
2743
+
2744
+ Parameters
2745
+ ==========
2746
+ kernel: the kernel to output
2747
+ path: the path to pull files to on the filesystem
2748
+ force: if output already exists, force overwrite (default False)
2749
+ quiet: suppress verbosity (default is True)
2750
+ """
2751
2751
  if kernel is None:
2752
2752
  raise ValueError('A kernel must be specified')
2753
2753
  if '/' in kernel:
@@ -2809,23 +2809,26 @@ class KaggleApi:
2809
2809
  path=None,
2810
2810
  force=False,
2811
2811
  quiet=False):
2812
- """ Client wrapper for kernels_output, with same arguments. Extra
2813
- arguments are described below, and see kernels_output for others.
2814
- Parameters
2815
- ==========
2816
- kernel_opt: option from client instead of kernel, if not defined
2817
- """
2812
+ """Client wrapper for kernels_output, with same arguments.
2813
+
2814
+ Extra
2815
+ arguments are described below, and see kernels_output for others.
2816
+ Parameters
2817
+ ==========
2818
+ kernel_opt: option from client instead of kernel, if not defined
2819
+ """
2818
2820
  kernel = kernel or kernel_opt
2819
2821
  (_, token) = self.kernels_output(kernel, path, force, quiet)
2820
2822
  if token:
2821
2823
  print(f"Next page token: {token}")
2822
2824
 
2823
2825
  def kernels_status(self, kernel):
2824
- """ Call to the api to get the status of a kernel.
2825
- Parameters
2826
- ==========
2827
- kernel: the kernel to get the status for
2828
- """
2826
+ """Call to the api to get the status of a kernel.
2827
+
2828
+ Parameters
2829
+ ==========
2830
+ kernel: the kernel to get the status for
2831
+ """
2829
2832
  if kernel is None:
2830
2833
  raise ValueError('A kernel must be specified')
2831
2834
  if '/' in kernel:
@@ -2844,11 +2847,12 @@ class KaggleApi:
2844
2847
  request)
2845
2848
 
2846
2849
  def kernels_status_cli(self, kernel, kernel_opt=None):
2847
- """ Client wrapper for kernel_status.
2848
- Parameters
2849
- ==========
2850
- kernel_opt: additional option from the client, if kernel not defined
2851
- """
2850
+ """Client wrapper for kernel_status.
2851
+
2852
+ Parameters
2853
+ ==========
2854
+ kernel_opt: additional option from the client, if kernel not defined
2855
+ """
2852
2856
  kernel = kernel or kernel_opt
2853
2857
  response = self.kernels_status(kernel)
2854
2858
  status = response.status
@@ -2860,12 +2864,13 @@ class KaggleApi:
2860
2864
  print('%s has status "%s"' % (kernel, status))
2861
2865
 
2862
2866
  def model_get(self, model):
2863
- """ Get a model.
2864
- Parameters
2865
- ==========
2866
- model: the string identifier of the model
2867
- should be in format [owner]/[model-name]
2868
- """
2867
+ """Get a model.
2868
+
2869
+ Parameters
2870
+ ==========
2871
+ model: the string identifier of the model
2872
+ should be in format [owner]/[model-name]
2873
+ """
2869
2874
  owner_slug, model_slug = self.split_model_string(model)
2870
2875
 
2871
2876
  with self.build_kaggle_client() as kaggle:
@@ -2875,14 +2880,15 @@ class KaggleApi:
2875
2880
  return kaggle.models.model_api_client.get_model(request)
2876
2881
 
2877
2882
  def model_get_cli(self, model, folder=None):
2878
- """ Clent wrapper for model_get, with additional
2879
- model_opt to get a model from the API.
2880
- Parameters
2881
- ==========
2882
- model: the string identifier of the model
2883
- should be in format [owner]/[model-name]
2884
- folder: the folder to download the model metadata file
2885
- """
2883
+ """Clent wrapper for model_get, with additional model_opt to get a model
2884
+ from the API.
2885
+
2886
+ Parameters
2887
+ ==========
2888
+ model: the string identifier of the model
2889
+ should be in format [owner]/[model-name]
2890
+ folder: the folder to download the model metadata file
2891
+ """
2886
2892
  model = self.model_get(model)
2887
2893
  if folder is None:
2888
2894
  self.print_obj(model)
@@ -2910,16 +2916,16 @@ class KaggleApi:
2910
2916
  owner=None,
2911
2917
  page_size=20,
2912
2918
  page_token=None):
2913
- """ Return a list of models.
2914
-
2915
- Parameters
2916
- ==========
2917
- sort_by: how to sort the result, see valid_model_sort_bys for options
2918
- search: a search term to use (default is empty string)
2919
- owner: username or organization slug to filter the search to
2920
- page_size: the page size to return (default is 20)
2921
- page_token: the page token for pagination
2922
- """
2919
+ """Return a list of models.
2920
+
2921
+ Parameters
2922
+ ==========
2923
+ sort_by: how to sort the result, see valid_model_sort_bys for options
2924
+ search: a search term to use (default is empty string)
2925
+ owner: username or organization slug to filter the search to
2926
+ page_size: the page size to return (default is 20)
2927
+ page_token: the page token for pagination
2928
+ """
2923
2929
  if sort_by:
2924
2930
  if sort_by not in self.valid_model_sort_bys:
2925
2931
  raise ValueError('Invalid sort by specified. Valid options are ' +
@@ -2948,18 +2954,18 @@ class KaggleApi:
2948
2954
  page_size=20,
2949
2955
  page_token=None,
2950
2956
  csv_display=False):
2951
- """ Client wrapper for model_list. Additional parameters
2952
- are described here, see model_list for others.
2953
-
2954
- Parameters
2955
- ==========
2956
- sort_by: how to sort the result, see valid_model_sort_bys for options
2957
- search: a search term to use (default is empty string)
2958
- owner: username or organization slug to filter the search to
2959
- page_size: the page size to return (default is 20)
2960
- page_token: the page token for pagination
2961
- csv_display: if True, print comma separated values instead of table
2962
- """
2957
+ """Client wrapper for model_list. Additional parameters are described here,
2958
+ see model_list for others.
2959
+
2960
+ Parameters
2961
+ ==========
2962
+ sort_by: how to sort the result, see valid_model_sort_bys for options
2963
+ search: a search term to use (default is empty string)
2964
+ owner: username or organization slug to filter the search to
2965
+ page_size: the page size to return (default is 20)
2966
+ page_token: the page token for pagination
2967
+ csv_display: if True, print comma separated values instead of table
2968
+ """
2963
2969
  models = self.model_list(sort_by, search, owner, page_size, page_token)
2964
2970
  fields = ['id', 'ref', 'title', 'subtitle', 'author']
2965
2971
  if models:
@@ -2971,11 +2977,12 @@ class KaggleApi:
2971
2977
  print('No models found')
2972
2978
 
2973
2979
  def model_initialize(self, folder):
2974
- """ Initialize a folder with a model configuration (metadata) file.
2975
- Parameters
2976
- ==========
2977
- folder: the folder to initialize the metadata file in
2978
- """
2980
+ """Initialize a folder with a model configuration (metadata) file.
2981
+
2982
+ Parameters
2983
+ ==========
2984
+ folder: the folder to initialize the metadata file in
2985
+ """
2979
2986
  if not os.path.isdir(folder):
2980
2987
  raise ValueError('Invalid folder: ' + folder)
2981
2988
 
@@ -3016,11 +3023,12 @@ class KaggleApi:
3016
3023
  self.model_initialize(folder)
3017
3024
 
3018
3025
  def model_create_new(self, folder):
3019
- """ Create a new model.
3020
- Parameters
3021
- ==========
3022
- folder: the folder to get the metadata file from
3023
- """
3026
+ """Create a new model.
3027
+
3028
+ Parameters
3029
+ ==========
3030
+ folder: the folder to get the metadata file from
3031
+ """
3024
3032
  if not os.path.isdir(folder):
3025
3033
  raise ValueError('Invalid folder: ' + folder)
3026
3034
 
@@ -3069,11 +3077,12 @@ class KaggleApi:
3069
3077
  return kaggle.models.model_api_client.create_model(request)
3070
3078
 
3071
3079
  def model_create_new_cli(self, folder=None):
3072
- """ Client wrapper for creating a new model.
3073
- Parameters
3074
- ==========
3075
- folder: the folder to get the metadata file from
3076
- """
3080
+ """Client wrapper for creating a new model.
3081
+
3082
+ Parameters
3083
+ ==========
3084
+ folder: the folder to get the metadata file from
3085
+ """
3077
3086
  folder = folder or os.getcwd()
3078
3087
  result = self.model_create_new(folder)
3079
3088
 
@@ -3084,13 +3093,14 @@ class KaggleApi:
3084
3093
  print('Model creation error: ' + result.error)
3085
3094
 
3086
3095
  def model_delete(self, model, yes):
3087
- """ Delete a modeL.
3088
- Parameters
3089
- ==========
3090
- model: the string identifier of the model
3091
- should be in format [owner]/[model-name]
3092
- yes: automatic confirmation
3093
- """
3096
+ """Delete a modeL.
3097
+
3098
+ Parameters
3099
+ ==========
3100
+ model: the string identifier of the model
3101
+ should be in format [owner]/[model-name]
3102
+ yes: automatic confirmation
3103
+ """
3094
3104
  owner_slug, model_slug = self.split_model_string(model)
3095
3105
 
3096
3106
  if not yes:
@@ -3105,13 +3115,14 @@ class KaggleApi:
3105
3115
  return kaggle.models.model_api_client.delete_model(request)
3106
3116
 
3107
3117
  def model_delete_cli(self, model, yes):
3108
- """ Client wrapper for deleting a model.
3109
- Parameters
3110
- ==========
3111
- model: the string identified of the model
3112
- should be in format [owner]/[model-name]
3113
- yes: automatic confirmation
3114
- """
3118
+ """Client wrapper for deleting a model.
3119
+
3120
+ Parameters
3121
+ ==========
3122
+ model: the string identified of the model
3123
+ should be in format [owner]/[model-name]
3124
+ yes: automatic confirmation
3125
+ """
3115
3126
  result = self.model_delete(model, yes)
3116
3127
 
3117
3128
  if result.error:
@@ -3120,11 +3131,12 @@ class KaggleApi:
3120
3131
  print('The model was deleted.')
3121
3132
 
3122
3133
  def model_update(self, folder):
3123
- """ Update a model.
3124
- Parameters
3125
- ==========
3126
- folder: the folder to get the metadata file from
3127
- """
3134
+ """Update a model.
3135
+
3136
+ Parameters
3137
+ ==========
3138
+ folder: the folder to get the metadata file from
3139
+ """
3128
3140
  if not os.path.isdir(folder):
3129
3141
  raise ValueError('Invalid folder: ' + folder)
3130
3142
 
@@ -3193,11 +3205,12 @@ class KaggleApi:
3193
3205
  return kaggle.models.model_api_client.update_model(request)
3194
3206
 
3195
3207
  def model_update_cli(self, folder=None):
3196
- """ Client wrapper for updating a model.
3197
- Parameters
3198
- ==========
3199
- folder: the folder to get the metadata file from
3200
- """
3208
+ """Client wrapper for updating a model.
3209
+
3210
+ Parameters
3211
+ ==========
3212
+ folder: the folder to get the metadata file from
3213
+ """
3201
3214
  folder = folder or os.getcwd()
3202
3215
  result = self.model_update(folder)
3203
3216
 
@@ -3208,12 +3221,13 @@ class KaggleApi:
3208
3221
  print('Model update error: ' + result.error)
3209
3222
 
3210
3223
  def model_instance_get(self, model_instance):
3211
- """ Get a model instance.
3212
- Parameters
3213
- ==========
3214
- model_instance: the string identifier of the model instance
3215
- should be in format [owner]/[model-name]/[framework]/[instance-slug]
3216
- """
3224
+ """Get a model instance.
3225
+
3226
+ Parameters
3227
+ ==========
3228
+ model_instance: the string identifier of the model instance
3229
+ should be in format [owner]/[model-name]/[framework]/[instance-slug]
3230
+ """
3217
3231
  if model_instance is None:
3218
3232
  raise ValueError('A model instance must be specified')
3219
3233
  owner_slug, model_slug, framework, instance_slug = self.split_model_instance_string(
@@ -3228,13 +3242,14 @@ class KaggleApi:
3228
3242
  return kaggle.models.model_api_client.get_model_instance(request)
3229
3243
 
3230
3244
  def model_instance_get_cli(self, model_instance, folder=None):
3231
- """ Client wrapper for model_instance_get.
3232
- Parameters
3233
- ==========
3234
- model_instance: the string identifier of the model instance
3235
- should be in format [owner]/[model-name]/[framework]/[instance-slug]
3236
- folder: the folder to download the model metadata file
3237
- """
3245
+ """Client wrapper for model_instance_get.
3246
+
3247
+ Parameters
3248
+ ==========
3249
+ model_instance: the string identifier of the model instance
3250
+ should be in format [owner]/[model-name]/[framework]/[instance-slug]
3251
+ folder: the folder to download the model metadata file
3252
+ """
3238
3253
  mi = self.model_instance_get(model_instance)
3239
3254
  if folder is None:
3240
3255
  self.print_obj(mi)
@@ -3273,11 +3288,12 @@ class KaggleApi:
3273
3288
  print('Metadata file written to {}'.format(meta_file))
3274
3289
 
3275
3290
  def model_instance_initialize(self, folder):
3276
- """ Initialize a folder with a model instance configuration (metadata) file.
3277
- Parameters
3278
- ==========
3279
- folder: the folder to initialize the metadata file in
3280
- """
3291
+ """Initialize a folder with a model instance configuration (metadata) file.
3292
+
3293
+ Parameters
3294
+ ==========
3295
+ folder: the folder to initialize the metadata file in
3296
+ """
3281
3297
  if not os.path.isdir(folder):
3282
3298
  raise ValueError('Invalid folder: ' + folder)
3283
3299
 
@@ -3431,13 +3447,14 @@ class KaggleApi:
3431
3447
  print('Model instance creation error: ' + result.error)
3432
3448
 
3433
3449
  def model_instance_delete(self, model_instance, yes):
3434
- """ Delete a model instance.
3435
- Parameters
3436
- ==========
3437
- model_instance: the string identified of the model instance
3438
- should be in format [owner]/[model-name]/[framework]/[instance-slug]
3439
- yes: automatic confirmation
3440
- """
3450
+ """Delete a model instance.
3451
+
3452
+ Parameters
3453
+ ==========
3454
+ model_instance: the string identified of the model instance
3455
+ should be in format [owner]/[model-name]/[framework]/[instance-slug]
3456
+ yes: automatic confirmation
3457
+ """
3441
3458
  if model_instance is None:
3442
3459
  raise ValueError('A model instance must be specified')
3443
3460
  owner_slug, model_slug, framework, instance_slug = self.split_model_instance_string(
@@ -3458,13 +3475,14 @@ class KaggleApi:
3458
3475
  return res
3459
3476
 
3460
3477
  def model_instance_delete_cli(self, model_instance, yes):
3461
- """ Client wrapper for model_instance_delete.
3462
- Parameters
3463
- ==========
3464
- model_instance: the string identified of the model instance
3465
- should be in format [owner]/[model-name]/[framework]/[instance-slug]
3466
- yes: automatic confirmation
3467
- """
3478
+ """Client wrapper for model_instance_delete.
3479
+
3480
+ Parameters
3481
+ ==========
3482
+ model_instance: the string identified of the model instance
3483
+ should be in format [owner]/[model-name]/[framework]/[instance-slug]
3484
+ yes: automatic confirmation
3485
+ """
3468
3486
  result = self.model_instance_delete(model_instance, yes)
3469
3487
 
3470
3488
  if len(result.error) > 0:
@@ -3477,16 +3495,16 @@ class KaggleApi:
3477
3495
  page_token=None,
3478
3496
  page_size=20,
3479
3497
  csv_display=False):
3480
- """ List files for the current version of a model instance.
3481
-
3482
- Parameters
3483
- ==========
3484
- model_instance: the string identifier of the model instance
3485
- should be in format [owner]/[model-name]/[framework]/[instance-slug]
3486
- page_token: token for pagination
3487
- page_size: the number of items per page
3488
- csv_display: if True, print comma separated values instead of table
3489
- """
3498
+ """List files for the current version of a model instance.
3499
+
3500
+ Parameters
3501
+ ==========
3502
+ model_instance: the string identifier of the model instance
3503
+ should be in format [owner]/[model-name]/[framework]/[instance-slug]
3504
+ page_token: token for pagination
3505
+ page_size: the number of items per page
3506
+ csv_display: if True, print comma separated values instead of table
3507
+ """
3490
3508
  if model_instance is None:
3491
3509
  raise ValueError('A model_instance must be specified')
3492
3510
 
@@ -3519,16 +3537,16 @@ class KaggleApi:
3519
3537
  page_token=None,
3520
3538
  page_size=20,
3521
3539
  csv_display=False):
3522
- """ Client wrapper for model_instance_files.
3523
-
3524
- Parameters
3525
- ==========
3526
- model_instance: the string identified of the model instance version
3527
- should be in format [owner]/[model-name]/[framework]/[instance-slug]
3528
- page_token: token for pagination
3529
- page_size: the number of items per page
3530
- csv_display: if True, print comma separated values instead of table
3531
- """
3540
+ """Client wrapper for model_instance_files.
3541
+
3542
+ Parameters
3543
+ ==========
3544
+ model_instance: the string identified of the model instance version
3545
+ should be in format [owner]/[model-name]/[framework]/[instance-slug]
3546
+ page_token: token for pagination
3547
+ page_size: the number of items per page
3548
+ csv_display: if True, print comma separated values instead of table
3549
+ """
3532
3550
  result = self.model_instance_files(
3533
3551
  model_instance,
3534
3552
  page_token=page_token,
@@ -3542,11 +3560,12 @@ class KaggleApi:
3542
3560
  self.print_table(result.files, fields)
3543
3561
 
3544
3562
  def model_instance_update(self, folder):
3545
- """ Update a model instance.
3546
- Parameters
3547
- ==========
3548
- folder: the folder to get the metadata file from
3549
- """
3563
+ """Update a model instance.
3564
+
3565
+ Parameters
3566
+ ==========
3567
+ folder: the folder to get the metadata file from
3568
+ """
3550
3569
  if not os.path.isdir(folder):
3551
3570
  raise ValueError('Invalid folder: ' + folder)
3552
3571
 
@@ -3637,11 +3656,12 @@ class KaggleApi:
3637
3656
  return kaggle.models.model_api_client.update_model_instance(request)
3638
3657
 
3639
3658
  def model_instance_update_cli(self, folder=None):
3640
- """ Client wrapper for updating a model instance.
3641
- Parameters
3642
- ==========
3643
- folder: the folder to get the metadata file from
3644
- """
3659
+ """Client wrapper for updating a model instance.
3660
+
3661
+ Parameters
3662
+ ==========
3663
+ folder: the folder to get the metadata file from
3664
+ """
3645
3665
  folder = folder or os.getcwd()
3646
3666
  result = self.model_instance_update(folder)
3647
3667
 
@@ -3720,17 +3740,17 @@ class KaggleApi:
3720
3740
  force=False,
3721
3741
  quiet=True,
3722
3742
  untar=False):
3723
- """ Download all files for a model instance version.
3724
-
3725
- Parameters
3726
- ==========
3727
- model_instance_version: the string identifier of the model instance version
3728
- should be in format [owner]/[model-name]/[framework]/[instance-slug]/[version-number]
3729
- path: the path to download the model instance version to
3730
- force: force the download if the file already exists (default False)
3731
- quiet: suppress verbose output (default is True)
3732
- untar: if True, untar files upon download (default is False)
3733
- """
3743
+ """Download all files for a model instance version.
3744
+
3745
+ Parameters
3746
+ ==========
3747
+ model_instance_version: the string identifier of the model instance version
3748
+ should be in format [owner]/[model-name]/[framework]/[instance-slug]/[version-number]
3749
+ path: the path to download the model instance version to
3750
+ force: force the download if the file already exists (default False)
3751
+ quiet: suppress verbose output (default is True)
3752
+ untar: if True, untar files upon download (default is False)
3753
+ """
3734
3754
  if model_instance_version is None:
3735
3755
  raise ValueError('A model_instance_version must be specified')
3736
3756
 
@@ -3760,28 +3780,28 @@ class KaggleApi:
3760
3780
  response = kaggle.models.model_api_client.download_model_instance_version(
3761
3781
  request)
3762
3782
 
3763
- outfile = os.path.join(effective_path, model_slug + '.tar.gz')
3764
- if force or self.download_needed(response, outfile, quiet):
3765
- self.download_file(response, outfile, quiet, not force)
3766
- downloaded = True
3767
- else:
3768
- downloaded = False
3769
-
3770
- if downloaded:
3771
- if untar:
3772
- try:
3773
- with tarfile.open(outfile, mode='r:gz') as t:
3774
- t.extractall(effective_path)
3775
- except Exception as e:
3776
- raise ValueError(
3777
- 'Error extracting the tar.gz file, please report on '
3778
- 'www.github.com/kaggle/kaggle-api', e)
3779
-
3780
- try:
3781
- os.remove(outfile)
3782
- except OSError as e:
3783
- print('Could not delete tar file, got %s' % e)
3784
- return outfile
3783
+ outfile = os.path.join(effective_path, model_slug + '.tar.gz')
3784
+ if force or self.download_needed(response, outfile, quiet):
3785
+ self.download_file(response, outfile, kaggle.http_client(), quiet, not force)
3786
+ downloaded = True
3787
+ else:
3788
+ downloaded = False
3789
+
3790
+ if downloaded:
3791
+ if untar:
3792
+ try:
3793
+ with tarfile.open(outfile, mode='r:gz') as t:
3794
+ t.extractall(effective_path)
3795
+ except Exception as e:
3796
+ raise ValueError(
3797
+ 'Error extracting the tar.gz file, please report on '
3798
+ 'www.github.com/kaggle/kaggle-api', e)
3799
+
3800
+ try:
3801
+ os.remove(outfile)
3802
+ except OSError as e:
3803
+ print('Could not delete tar file, got %s' % e)
3804
+ return outfile
3785
3805
 
3786
3806
  def model_instance_version_download_cli(self,
3787
3807
  model_instance_version,
@@ -3789,17 +3809,17 @@ class KaggleApi:
3789
3809
  untar=False,
3790
3810
  force=False,
3791
3811
  quiet=False):
3792
- """ Client wrapper for model_instance_version_download.
3793
-
3794
- Parameters
3795
- ==========
3796
- model_instance_version: the string identifier of the model instance version
3797
- should be in format [owner]/[model-name]/[framework]/[instance-slug]/[version-number]
3798
- path: the path to download the model instance version to
3799
- force: force the download if the file already exists (default False)
3800
- quiet: suppress verbose output (default is False)
3801
- untar: if True, untar files upon download (default is False)
3802
- """
3812
+ """Client wrapper for model_instance_version_download.
3813
+
3814
+ Parameters
3815
+ ==========
3816
+ model_instance_version: the string identifier of the model instance version
3817
+ should be in format [owner]/[model-name]/[framework]/[instance-slug]/[version-number]
3818
+ path: the path to download the model instance version to
3819
+ force: force the download if the file already exists (default False)
3820
+ quiet: suppress verbose output (default is False)
3821
+ untar: if True, untar files upon download (default is False)
3822
+ """
3803
3823
  return self.model_instance_version_download(
3804
3824
  model_instance_version,
3805
3825
  path=path,
@@ -3812,16 +3832,16 @@ class KaggleApi:
3812
3832
  page_token=None,
3813
3833
  page_size=20,
3814
3834
  csv_display=False):
3815
- """ List all files for a model instance version.
3816
-
3817
- Parameters
3818
- ==========
3819
- model_instance_version: the string identifier of the model instance version
3820
- should be in format [owner]/[model-name]/[framework]/[instance-slug]/[version-number]
3821
- page_token: token for pagination
3822
- page_size: the number of items per page
3823
- csv_display: if True, print comma separated values instead of table
3824
- """
3835
+ """List all files for a model instance version.
3836
+
3837
+ Parameters
3838
+ ==========
3839
+ model_instance_version: the string identifier of the model instance version
3840
+ should be in format [owner]/[model-name]/[framework]/[instance-slug]/[version-number]
3841
+ page_token: token for pagination
3842
+ page_size: the number of items per page
3843
+ csv_display: if True, print comma separated values instead of table
3844
+ """
3825
3845
  if model_instance_version is None:
3826
3846
  raise ValueError('A model_instance_version must be specified')
3827
3847
 
@@ -3854,16 +3874,16 @@ class KaggleApi:
3854
3874
  page_token=None,
3855
3875
  page_size=20,
3856
3876
  csv_display=False):
3857
- """ Client wrapper for model_instance_version_files.
3858
-
3859
- Parameters
3860
- ==========
3861
- model_instance_version: the string identifier of the model instance version
3862
- should be in format [owner]/[model-name]/[framework]/[instance-slug]/[version-number]
3863
- page_token: token for pagination
3864
- page_size: the number of items per page
3865
- csv_display: if True, print comma separated values instead of table
3866
- """
3877
+ """Client wrapper for model_instance_version_files.
3878
+
3879
+ Parameters
3880
+ ==========
3881
+ model_instance_version: the string identifier of the model instance version
3882
+ should be in format [owner]/[model-name]/[framework]/[instance-slug]/[version-number]
3883
+ page_token: token for pagination
3884
+ page_size: the number of items per page
3885
+ csv_display: if True, print comma separated values instead of table
3886
+ """
3867
3887
  result = self.model_instance_version_files(
3868
3888
  model_instance_version,
3869
3889
  page_token=page_token,
@@ -3878,13 +3898,14 @@ class KaggleApi:
3878
3898
  self.print_table(result.files, fields, labels)
3879
3899
 
3880
3900
  def model_instance_version_delete(self, model_instance_version, yes):
3881
- """ Delete a model instance version.
3882
- Parameters
3883
- ==========
3884
- model_instance_version: the string identifier of the model instance version
3885
- should be in format [owner]/[model-name]/[framework]/[instance-slug]/[version-number]
3886
- yes: automatic confirmation
3887
- """
3901
+ """Delete a model instance version.
3902
+
3903
+ Parameters
3904
+ ==========
3905
+ model_instance_version: the string identifier of the model instance version
3906
+ should be in format [owner]/[model-name]/[framework]/[instance-slug]/[version-number]
3907
+ yes: automatic confirmation
3908
+ """
3888
3909
  if model_instance_version is None:
3889
3910
  raise ValueError('A model instance version must be specified')
3890
3911
 
@@ -3970,14 +3991,16 @@ class KaggleApi:
3970
3991
  print(pretty)
3971
3992
 
3972
3993
  def download_needed(self, response, outfile, quiet=True):
3973
- """ determine if a download is needed based on timestamp. Return True
3974
- if needed (remote is newer) or False if local is newest.
3975
- Parameters
3976
- ==========
3977
- response: the response from the API
3978
- outfile: the output file to write to
3979
- quiet: suppress verbose output (default is True)
3980
- """
3994
+ """Determine if a download is needed based on timestamp.
3995
+
3996
+ Return True
3997
+ if needed (remote is newer) or False if local is newest.
3998
+ Parameters
3999
+ ==========
4000
+ response: the response from the API
4001
+ outfile: the output file to write to
4002
+ quiet: suppress verbose output (default is True)
4003
+ """
3981
4004
  try:
3982
4005
  last_modified = response.headers.get('Last-Modified')
3983
4006
  if last_modified is None:
@@ -4004,14 +4027,14 @@ class KaggleApi:
4004
4027
  return True
4005
4028
 
4006
4029
  def print_table(self, items, fields, labels=None):
4007
- """ print a table of items, for a set of fields defined
4030
+ """Print a table of items, for a set of fields defined.
4008
4031
 
4009
- Parameters
4010
- ==========
4011
- items: a list of items to print
4012
- fields: a list of fields to select from items
4013
- labels: labels for the fields, defaults to fields
4014
- """
4032
+ Parameters
4033
+ ==========
4034
+ items: a list of items to print
4035
+ fields: a list of fields to select from items
4036
+ labels: labels for the fields, defaults to fields
4037
+ """
4015
4038
  if labels is None:
4016
4039
  labels = fields
4017
4040
  formats = []
@@ -4044,14 +4067,14 @@ class KaggleApi:
4044
4067
  print(row_format.format(*i_fields).encode('utf-8'))
4045
4068
 
4046
4069
  def print_csv(self, items, fields, labels=None):
4047
- """ print a set of fields in a set of items using a csv.writer
4070
+ """Print a set of fields in a set of items using a csv.writer.
4048
4071
 
4049
- Parameters
4050
- ==========
4051
- items: a list of items to print
4052
- fields: a list of fields to select from items
4053
- labels: labels for the fields, defaults to fields
4054
- """
4072
+ Parameters
4073
+ ==========
4074
+ items: a list of items to print
4075
+ fields: a list of fields to select from items
4076
+ labels: labels for the fields, defaults to fields
4077
+ """
4055
4078
  if labels is None:
4056
4079
  labels = fields
4057
4080
  writer = csv.writer(sys.stdout)
@@ -4118,13 +4141,13 @@ class KaggleApi:
4118
4141
  return meta_file
4119
4142
 
4120
4143
  def process_response(self, result):
4121
- """ process a response from the API. We check the API version against
4122
- the client's to see if it's old, and give them a warning (once)
4144
+ """Process a response from the API. We check the API version against the
4145
+ client's to see if it's old, and give them a warning (once)
4123
4146
 
4124
- Parameters
4125
- ==========
4126
- result: the result from the API
4127
- """
4147
+ Parameters
4148
+ ==========
4149
+ result: the result from the API
4150
+ """
4128
4151
  if len(result) == 3:
4129
4152
  data = result[0]
4130
4153
  headers = result[2]
@@ -4142,13 +4165,15 @@ class KaggleApi:
4142
4165
  return result
4143
4166
 
4144
4167
  def is_up_to_date(self, server_version):
4145
- """ determine if a client (on the local user's machine) is up to date
4146
- with the version provided on the server. Return a boolean with True
4147
- or False
4148
- Parameters
4149
- ==========
4150
- server_version: the server version string to compare to the host
4151
- """
4168
+ """Determine if a client (on the local user's machine) is up to date with
4169
+ the version provided on the server.
4170
+
4171
+ Return a boolean with True
4172
+ or False
4173
+ Parameters
4174
+ ==========
4175
+ server_version: the server version string to compare to the host
4176
+ """
4152
4177
  client_split = self.__version__.split('.')
4153
4178
  client_len = len(client_split)
4154
4179
  server_split = server_version.split('.')
@@ -4412,12 +4437,13 @@ class KaggleApi:
4412
4437
  return None # Shouldn't happen, something's wrong with Range header format.
4413
4438
 
4414
4439
  def validate_dataset_string(self, dataset):
4415
- """ determine if a dataset string is valid, meaning it is in the format
4416
- of {username}/{dataset-slug} or {username}/{dataset-slug}/{version-number}.
4417
- Parameters
4418
- ==========
4419
- dataset: the dataset name to validate
4420
- """
4440
+ """Determine if a dataset string is valid, meaning it is in the format of
4441
+ {username}/{dataset-slug} or {username}/{dataset-slug}/{version-number}.
4442
+
4443
+ Parameters
4444
+ ==========
4445
+ dataset: the dataset name to validate
4446
+ """
4421
4447
  if dataset:
4422
4448
  if '/' not in dataset:
4423
4449
  raise ValueError('Dataset must be specified in the form of '
@@ -4445,12 +4471,13 @@ class KaggleApi:
4445
4471
  return self.get_config_value(self.CONFIG_NAME_USER), dataset, None
4446
4472
 
4447
4473
  def validate_model_string(self, model):
4448
- """ determine if a model string is valid, meaning it is in the format
4449
- of {owner}/{model-slug}.
4450
- Parameters
4451
- ==========
4452
- model: the model name to validate
4453
- """
4474
+ """Determine if a model string is valid, meaning it is in the format of
4475
+ {owner}/{model-slug}.
4476
+
4477
+ Parameters
4478
+ ==========
4479
+ model: the model name to validate
4480
+ """
4454
4481
  if model:
4455
4482
  if model.count('/') != 1:
4456
4483
  raise ValueError('Model must be specified in the form of '
@@ -4474,12 +4501,13 @@ class KaggleApi:
4474
4501
  return self.get_config_value(self.CONFIG_NAME_USER), model
4475
4502
 
4476
4503
  def validate_model_instance_string(self, model_instance):
4477
- """ determine if a model instance string is valid, meaning it is in the format
4478
- of {owner}/{model-slug}/{framework}/{instance-slug}.
4479
- Parameters
4480
- ==========
4481
- model_instance: the model instance name to validate
4482
- """
4504
+ """Determine if a model instance string is valid, meaning it is in the
4505
+ format of {owner}/{model-slug}/{framework}/{instance-slug}.
4506
+
4507
+ Parameters
4508
+ ==========
4509
+ model_instance: the model instance name to validate
4510
+ """
4483
4511
  if model_instance:
4484
4512
  if model_instance.count('/') != 3:
4485
4513
  raise ValueError('Model instance must be specified in the form of '
@@ -4502,12 +4530,14 @@ class KaggleApi:
4502
4530
  return urls[0], urls[1], urls[2], urls[3]
4503
4531
 
4504
4532
  def validate_model_instance_version_string(self, model_instance_version):
4505
- """ determine if a model instance version string is valid, meaning it is in the format
4506
- of {owner}/{model-slug}/{framework}/{instance-slug}/{version-number}.
4507
- Parameters
4508
- ==========
4509
- model_instance_version: the model instance version name to validate
4510
- """
4533
+ """Determine if a model instance version string is valid, meaning it is in
4534
+ the format of {owner}/{model-slug}/{framework}/{instance-slug}/{version-
4535
+ number}.
4536
+
4537
+ Parameters
4538
+ ==========
4539
+ model_instance_version: the model instance version name to validate
4540
+ """
4511
4541
  if model_instance_version:
4512
4542
  if model_instance_version.count('/') != 4:
4513
4543
  raise ValueError(
@@ -4528,12 +4558,13 @@ class KaggleApi:
4528
4558
  'Model instance version\'s version-number must be an integer')
4529
4559
 
4530
4560
  def validate_kernel_string(self, kernel):
4531
- """ determine if a kernel string is valid, meaning it is in the format
4532
- of {username}/{kernel-slug}.
4533
- Parameters
4534
- ==========
4535
- kernel: the kernel name to validate
4536
- """
4561
+ """Determine if a kernel string is valid, meaning it is in the format of
4562
+ {username}/{kernel-slug}.
4563
+
4564
+ Parameters
4565
+ ==========
4566
+ kernel: the kernel name to validate
4567
+ """
4537
4568
  if kernel:
4538
4569
  if '/' not in kernel:
4539
4570
  raise ValueError('Kernel must be specified in the form of '
@@ -4548,12 +4579,13 @@ class KaggleApi:
4548
4579
  raise ValueError('Kernel slug must be at least five characters')
4549
4580
 
4550
4581
  def validate_model_string(self, model):
4551
- """ determine if a model string is valid, meaning it is in the format
4552
- of {username}/{model-slug}/{framework}/{variation-slug}/{version-number}.
4553
- Parameters
4554
- ==========
4555
- model: the model name to validate
4556
- """
4582
+ """Determine if a model string is valid, meaning it is in the format of
4583
+ {username}/{model-slug}/{framework}/{variation-slug}/{version-number}.
4584
+
4585
+ Parameters
4586
+ ==========
4587
+ model: the model name to validate
4588
+ """
4557
4589
  if model:
4558
4590
  if '/' not in model:
4559
4591
  raise ValueError(
@@ -4566,25 +4598,25 @@ class KaggleApi:
4566
4598
  raise ValueError('Invalid model specification ' + model)
4567
4599
 
4568
4600
  def validate_resources(self, folder, resources):
4569
- """ validate resources is a wrapper to validate the existence of files
4570
- and that there are no duplicates for a folder and set of resources.
4601
+ """Validate resources is a wrapper to validate the existence of files and
4602
+ that there are no duplicates for a folder and set of resources.
4571
4603
 
4572
- Parameters
4573
- ==========
4574
- folder: the folder to validate
4575
- resources: one or more resources to validate within the folder
4576
- """
4604
+ Parameters
4605
+ ==========
4606
+ folder: the folder to validate
4607
+ resources: one or more resources to validate within the folder
4608
+ """
4577
4609
  self.validate_files_exist(folder, resources)
4578
4610
  self.validate_no_duplicate_paths(resources)
4579
4611
 
4580
4612
  def validate_files_exist(self, folder, resources):
4581
- """ ensure that one or more resource files exist in a folder
4613
+ """Ensure that one or more resource files exist in a folder.
4582
4614
 
4583
- Parameters
4584
- ==========
4585
- folder: the folder to validate
4586
- resources: one or more resources to validate within the folder
4587
- """
4615
+ Parameters
4616
+ ==========
4617
+ folder: the folder to validate
4618
+ resources: one or more resources to validate within the folder
4619
+ """
4588
4620
  for item in resources:
4589
4621
  file_name = item.get('path')
4590
4622
  full_path = os.path.join(folder, file_name)
@@ -4592,13 +4624,13 @@ class KaggleApi:
4592
4624
  raise ValueError('%s does not exist' % full_path)
4593
4625
 
4594
4626
  def validate_no_duplicate_paths(self, resources):
4595
- """ ensure that the user has not provided duplicate paths in
4596
- a list of resources.
4627
+ """Ensure that the user has not provided duplicate paths in a list of
4628
+ resources.
4597
4629
 
4598
- Parameters
4599
- ==========
4600
- resources: one or more resources to validate not duplicated
4601
- """
4630
+ Parameters
4631
+ ==========
4632
+ resources: one or more resources to validate not duplicated
4633
+ """
4602
4634
  paths = set()
4603
4635
  for item in resources:
4604
4636
  file_name = item.get('path')
@@ -4608,13 +4640,13 @@ class KaggleApi:
4608
4640
  paths.add(file_name)
4609
4641
 
4610
4642
  def convert_to_dataset_file_metadata(self, file_data, path):
4611
- """ convert a set of file_data to a metadata file at path
4643
+ """Convert a set of file_data to a metadata file at path.
4612
4644
 
4613
- Parameters
4614
- ==========
4615
- file_data: a dictionary of file data to write to file
4616
- path: the path to write the metadata to
4617
- """
4645
+ Parameters
4646
+ ==========
4647
+ file_data: a dictionary of file data to write to file
4648
+ path: the path to write the metadata to
4649
+ """
4618
4650
  as_metadata = {
4619
4651
  'path': os.path.join(path, file_data['name']),
4620
4652
  'description': file_data['description']
@@ -4667,20 +4699,19 @@ class TqdmBufferedReader(io.BufferedReader):
4667
4699
  self.progress_bar = progress_bar
4668
4700
 
4669
4701
  def read(self, *args, **kwargs):
4670
- """ read the buffer, passing named and non named arguments to the
4671
- io.BufferedReader function.
4672
- """
4702
+ """Read the buffer, passing named and non named arguments to the
4703
+ io.BufferedReader function."""
4673
4704
  buf = io.BufferedReader.read(self, *args, **kwargs)
4674
4705
  self.increment(len(buf))
4675
4706
  return buf
4676
4707
 
4677
4708
  def increment(self, length):
4678
- """ increment the reader by some length
4709
+ """Increment the reader by some length.
4679
4710
 
4680
- Parameters
4681
- ==========
4682
- length: bytes to increment the reader by
4683
- """
4711
+ Parameters
4712
+ ==========
4713
+ length: bytes to increment the reader by
4714
+ """
4684
4715
  self.progress_bar.update(length)
4685
4716
 
4686
4717