huggingface-hub 0.36.0rc0__py3-none-any.whl → 1.0.0__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.

Potentially problematic release.


This version of huggingface-hub might be problematic. Click here for more details.

Files changed (132) hide show
  1. huggingface_hub/__init__.py +33 -45
  2. huggingface_hub/_commit_api.py +39 -43
  3. huggingface_hub/_commit_scheduler.py +11 -8
  4. huggingface_hub/_inference_endpoints.py +8 -8
  5. huggingface_hub/_jobs_api.py +20 -20
  6. huggingface_hub/_login.py +17 -43
  7. huggingface_hub/_oauth.py +8 -8
  8. huggingface_hub/_snapshot_download.py +135 -50
  9. huggingface_hub/_space_api.py +4 -4
  10. huggingface_hub/_tensorboard_logger.py +5 -5
  11. huggingface_hub/_upload_large_folder.py +18 -32
  12. huggingface_hub/_webhooks_payload.py +3 -3
  13. huggingface_hub/_webhooks_server.py +2 -2
  14. huggingface_hub/cli/__init__.py +0 -14
  15. huggingface_hub/cli/_cli_utils.py +143 -39
  16. huggingface_hub/cli/auth.py +105 -171
  17. huggingface_hub/cli/cache.py +594 -361
  18. huggingface_hub/cli/download.py +120 -112
  19. huggingface_hub/cli/hf.py +38 -41
  20. huggingface_hub/cli/jobs.py +689 -1017
  21. huggingface_hub/cli/lfs.py +120 -143
  22. huggingface_hub/cli/repo.py +282 -216
  23. huggingface_hub/cli/repo_files.py +50 -84
  24. huggingface_hub/cli/system.py +6 -25
  25. huggingface_hub/cli/upload.py +198 -220
  26. huggingface_hub/cli/upload_large_folder.py +91 -106
  27. huggingface_hub/community.py +5 -5
  28. huggingface_hub/constants.py +17 -52
  29. huggingface_hub/dataclasses.py +135 -21
  30. huggingface_hub/errors.py +47 -30
  31. huggingface_hub/fastai_utils.py +8 -9
  32. huggingface_hub/file_download.py +351 -303
  33. huggingface_hub/hf_api.py +398 -570
  34. huggingface_hub/hf_file_system.py +101 -66
  35. huggingface_hub/hub_mixin.py +32 -54
  36. huggingface_hub/inference/_client.py +177 -162
  37. huggingface_hub/inference/_common.py +38 -54
  38. huggingface_hub/inference/_generated/_async_client.py +218 -258
  39. huggingface_hub/inference/_generated/types/automatic_speech_recognition.py +3 -3
  40. huggingface_hub/inference/_generated/types/base.py +10 -7
  41. huggingface_hub/inference/_generated/types/chat_completion.py +16 -16
  42. huggingface_hub/inference/_generated/types/depth_estimation.py +2 -2
  43. huggingface_hub/inference/_generated/types/document_question_answering.py +2 -2
  44. huggingface_hub/inference/_generated/types/feature_extraction.py +2 -2
  45. huggingface_hub/inference/_generated/types/fill_mask.py +2 -2
  46. huggingface_hub/inference/_generated/types/sentence_similarity.py +3 -3
  47. huggingface_hub/inference/_generated/types/summarization.py +2 -2
  48. huggingface_hub/inference/_generated/types/table_question_answering.py +4 -4
  49. huggingface_hub/inference/_generated/types/text2text_generation.py +2 -2
  50. huggingface_hub/inference/_generated/types/text_generation.py +10 -10
  51. huggingface_hub/inference/_generated/types/text_to_video.py +2 -2
  52. huggingface_hub/inference/_generated/types/token_classification.py +2 -2
  53. huggingface_hub/inference/_generated/types/translation.py +2 -2
  54. huggingface_hub/inference/_generated/types/zero_shot_classification.py +2 -2
  55. huggingface_hub/inference/_generated/types/zero_shot_image_classification.py +2 -2
  56. huggingface_hub/inference/_generated/types/zero_shot_object_detection.py +1 -3
  57. huggingface_hub/inference/_mcp/agent.py +3 -3
  58. huggingface_hub/inference/_mcp/constants.py +1 -2
  59. huggingface_hub/inference/_mcp/mcp_client.py +33 -22
  60. huggingface_hub/inference/_mcp/types.py +10 -10
  61. huggingface_hub/inference/_mcp/utils.py +4 -4
  62. huggingface_hub/inference/_providers/__init__.py +12 -4
  63. huggingface_hub/inference/_providers/_common.py +62 -24
  64. huggingface_hub/inference/_providers/black_forest_labs.py +6 -6
  65. huggingface_hub/inference/_providers/cohere.py +3 -3
  66. huggingface_hub/inference/_providers/fal_ai.py +25 -25
  67. huggingface_hub/inference/_providers/featherless_ai.py +4 -4
  68. huggingface_hub/inference/_providers/fireworks_ai.py +3 -3
  69. huggingface_hub/inference/_providers/hf_inference.py +13 -13
  70. huggingface_hub/inference/_providers/hyperbolic.py +4 -4
  71. huggingface_hub/inference/_providers/nebius.py +10 -10
  72. huggingface_hub/inference/_providers/novita.py +5 -5
  73. huggingface_hub/inference/_providers/nscale.py +4 -4
  74. huggingface_hub/inference/_providers/replicate.py +15 -15
  75. huggingface_hub/inference/_providers/sambanova.py +6 -6
  76. huggingface_hub/inference/_providers/together.py +7 -7
  77. huggingface_hub/lfs.py +21 -94
  78. huggingface_hub/repocard.py +15 -16
  79. huggingface_hub/repocard_data.py +57 -57
  80. huggingface_hub/serialization/__init__.py +0 -1
  81. huggingface_hub/serialization/_base.py +9 -9
  82. huggingface_hub/serialization/_dduf.py +7 -7
  83. huggingface_hub/serialization/_torch.py +28 -28
  84. huggingface_hub/utils/__init__.py +11 -6
  85. huggingface_hub/utils/_auth.py +5 -5
  86. huggingface_hub/utils/_cache_manager.py +49 -74
  87. huggingface_hub/utils/_deprecation.py +1 -1
  88. huggingface_hub/utils/_dotenv.py +3 -3
  89. huggingface_hub/utils/_fixes.py +0 -10
  90. huggingface_hub/utils/_git_credential.py +3 -3
  91. huggingface_hub/utils/_headers.py +7 -29
  92. huggingface_hub/utils/_http.py +371 -208
  93. huggingface_hub/utils/_pagination.py +4 -4
  94. huggingface_hub/utils/_parsing.py +98 -0
  95. huggingface_hub/utils/_paths.py +5 -5
  96. huggingface_hub/utils/_runtime.py +59 -23
  97. huggingface_hub/utils/_safetensors.py +21 -21
  98. huggingface_hub/utils/_subprocess.py +9 -9
  99. huggingface_hub/utils/_telemetry.py +3 -3
  100. huggingface_hub/{commands/_cli_utils.py → utils/_terminal.py} +4 -9
  101. huggingface_hub/utils/_typing.py +3 -3
  102. huggingface_hub/utils/_validators.py +53 -72
  103. huggingface_hub/utils/_xet.py +16 -16
  104. huggingface_hub/utils/_xet_progress_reporting.py +1 -1
  105. huggingface_hub/utils/insecure_hashlib.py +3 -9
  106. huggingface_hub/utils/tqdm.py +3 -3
  107. {huggingface_hub-0.36.0rc0.dist-info → huggingface_hub-1.0.0.dist-info}/METADATA +16 -35
  108. huggingface_hub-1.0.0.dist-info/RECORD +152 -0
  109. {huggingface_hub-0.36.0rc0.dist-info → huggingface_hub-1.0.0.dist-info}/entry_points.txt +0 -1
  110. huggingface_hub/commands/__init__.py +0 -27
  111. huggingface_hub/commands/delete_cache.py +0 -476
  112. huggingface_hub/commands/download.py +0 -204
  113. huggingface_hub/commands/env.py +0 -39
  114. huggingface_hub/commands/huggingface_cli.py +0 -65
  115. huggingface_hub/commands/lfs.py +0 -200
  116. huggingface_hub/commands/repo.py +0 -151
  117. huggingface_hub/commands/repo_files.py +0 -132
  118. huggingface_hub/commands/scan_cache.py +0 -183
  119. huggingface_hub/commands/tag.py +0 -161
  120. huggingface_hub/commands/upload.py +0 -318
  121. huggingface_hub/commands/upload_large_folder.py +0 -131
  122. huggingface_hub/commands/user.py +0 -208
  123. huggingface_hub/commands/version.py +0 -40
  124. huggingface_hub/inference_api.py +0 -217
  125. huggingface_hub/keras_mixin.py +0 -497
  126. huggingface_hub/repository.py +0 -1471
  127. huggingface_hub/serialization/_tensorflow.py +0 -92
  128. huggingface_hub/utils/_hf_folder.py +0 -68
  129. huggingface_hub-0.36.0rc0.dist-info/RECORD +0 -170
  130. {huggingface_hub-0.36.0rc0.dist-info → huggingface_hub-1.0.0.dist-info}/LICENSE +0 -0
  131. {huggingface_hub-0.36.0rc0.dist-info → huggingface_hub-1.0.0.dist-info}/WHEEL +0 -0
  132. {huggingface_hub-0.36.0rc0.dist-info → huggingface_hub-1.0.0.dist-info}/top_level.txt +0 -0
@@ -37,145 +37,153 @@ Usage:
37
37
  """
38
38
 
39
39
  import warnings
40
- from argparse import Namespace, _SubParsersAction
41
- from typing import List, Optional
40
+ from typing import Annotated, Optional, Union
41
+
42
+ import typer
42
43
 
43
44
  from huggingface_hub import logging
44
45
  from huggingface_hub._snapshot_download import snapshot_download
45
- from huggingface_hub.commands import BaseHuggingfaceCLICommand
46
- from huggingface_hub.file_download import hf_hub_download
47
- from huggingface_hub.utils import disable_progress_bars, enable_progress_bars
46
+ from huggingface_hub.file_download import DryRunFileInfo, hf_hub_download
47
+ from huggingface_hub.utils import _format_size, disable_progress_bars, enable_progress_bars, tabulate
48
+
49
+ from ._cli_utils import RepoIdArg, RepoTypeOpt, RevisionOpt, TokenOpt
48
50
 
49
51
 
50
52
  logger = logging.get_logger(__name__)
51
53
 
52
54
 
53
- class DownloadCommand(BaseHuggingfaceCLICommand):
54
- @staticmethod
55
- def register_subcommand(parser: _SubParsersAction):
56
- download_parser = parser.add_parser("download", help="Download files from the Hub")
57
- download_parser.add_argument(
58
- "repo_id", type=str, help="ID of the repo to download from (e.g. `username/repo-name`)."
59
- )
60
- download_parser.add_argument(
61
- "filenames", type=str, nargs="*", help="Files to download (e.g. `config.json`, `data/metadata.jsonl`)."
62
- )
63
- download_parser.add_argument(
64
- "--repo-type",
65
- choices=["model", "dataset", "space"],
66
- default="model",
67
- help="Type of repo to download from (defaults to 'model').",
68
- )
69
- download_parser.add_argument(
70
- "--revision",
71
- type=str,
72
- help="An optional Git revision id which can be a branch name, a tag, or a commit hash.",
73
- )
74
- download_parser.add_argument(
75
- "--include", nargs="*", type=str, help="Glob patterns to match files to download."
76
- )
77
- download_parser.add_argument(
78
- "--exclude", nargs="*", type=str, help="Glob patterns to exclude from files to download."
79
- )
80
- download_parser.add_argument(
81
- "--cache-dir", type=str, help="Path to the directory where to save the downloaded files."
82
- )
83
- download_parser.add_argument(
84
- "--local-dir",
85
- type=str,
86
- help=(
87
- "If set, the downloaded file will be placed under this directory. Check out"
88
- " https://huggingface.co/docs/huggingface_hub/guides/download#download-files-to-local-folder for more"
89
- " details."
90
- ),
91
- )
92
- download_parser.add_argument(
93
- "--force-download",
94
- action="store_true",
55
+ def download(
56
+ repo_id: RepoIdArg,
57
+ filenames: Annotated[
58
+ Optional[list[str]],
59
+ typer.Argument(
60
+ help="Files to download (e.g. `config.json`, `data/metadata.jsonl`).",
61
+ ),
62
+ ] = None,
63
+ repo_type: RepoTypeOpt = RepoTypeOpt.model,
64
+ revision: RevisionOpt = None,
65
+ include: Annotated[
66
+ Optional[list[str]],
67
+ typer.Option(
68
+ help="Glob patterns to include from files to download. eg: *.json",
69
+ ),
70
+ ] = None,
71
+ exclude: Annotated[
72
+ Optional[list[str]],
73
+ typer.Option(
74
+ help="Glob patterns to exclude from files to download.",
75
+ ),
76
+ ] = None,
77
+ cache_dir: Annotated[
78
+ Optional[str],
79
+ typer.Option(
80
+ help="Directory where to save files.",
81
+ ),
82
+ ] = None,
83
+ local_dir: Annotated[
84
+ Optional[str],
85
+ typer.Option(
86
+ help="If set, the downloaded file will be placed under this directory. Check out https://huggingface.co/docs/huggingface_hub/guides/download#download-files-to-local-folder for more details.",
87
+ ),
88
+ ] = None,
89
+ force_download: Annotated[
90
+ bool,
91
+ typer.Option(
95
92
  help="If True, the files will be downloaded even if they are already cached.",
96
- )
97
- download_parser.add_argument(
98
- "--token", type=str, help="A User Access Token generated from https://huggingface.co/settings/tokens"
99
- )
100
- download_parser.add_argument(
101
- "--quiet",
102
- action="store_true",
93
+ ),
94
+ ] = False,
95
+ dry_run: Annotated[
96
+ bool,
97
+ typer.Option(
98
+ help="If True, perform a dry run without actually downloading the file.",
99
+ ),
100
+ ] = False,
101
+ token: TokenOpt = None,
102
+ quiet: Annotated[
103
+ bool,
104
+ typer.Option(
103
105
  help="If True, progress bars are disabled and only the path to the download files is printed.",
104
- )
105
- download_parser.add_argument(
106
- "--max-workers",
107
- type=int,
108
- default=8,
106
+ ),
107
+ ] = False,
108
+ max_workers: Annotated[
109
+ int,
110
+ typer.Option(
109
111
  help="Maximum number of workers to use for downloading files. Default is 8.",
110
- )
111
- download_parser.set_defaults(func=DownloadCommand)
112
-
113
- def __init__(self, args: Namespace) -> None:
114
- self.token = args.token
115
- self.repo_id: str = args.repo_id
116
- self.filenames: List[str] = args.filenames
117
- self.repo_type: str = args.repo_type
118
- self.revision: Optional[str] = args.revision
119
- self.include: Optional[List[str]] = args.include
120
- self.exclude: Optional[List[str]] = args.exclude
121
- self.cache_dir: Optional[str] = args.cache_dir
122
- self.local_dir: Optional[str] = args.local_dir
123
- self.force_download: bool = args.force_download
124
- self.quiet: bool = args.quiet
125
- self.max_workers: int = args.max_workers
126
-
127
- def run(self) -> None:
128
- if self.quiet:
129
- disable_progress_bars()
130
- with warnings.catch_warnings():
131
- warnings.simplefilter("ignore")
132
- print(self._download()) # Print path to downloaded files
133
- enable_progress_bars()
134
- else:
135
- logging.set_verbosity_info()
136
- print(self._download()) # Print path to downloaded files
137
- logging.set_verbosity_warning()
112
+ ),
113
+ ] = 8,
114
+ ) -> None:
115
+ """Download files from the Hub."""
138
116
 
139
- def _download(self) -> str:
117
+ def run_download() -> Union[str, DryRunFileInfo, list[DryRunFileInfo]]:
118
+ filenames_list = filenames if filenames is not None else []
140
119
  # Warn user if patterns are ignored
141
- if len(self.filenames) > 0:
142
- if self.include is not None and len(self.include) > 0:
120
+ if len(filenames_list) > 0:
121
+ if include is not None and len(include) > 0:
143
122
  warnings.warn("Ignoring `--include` since filenames have being explicitly set.")
144
- if self.exclude is not None and len(self.exclude) > 0:
123
+ if exclude is not None and len(exclude) > 0:
145
124
  warnings.warn("Ignoring `--exclude` since filenames have being explicitly set.")
146
125
 
147
126
  # Single file to download: use `hf_hub_download`
148
- if len(self.filenames) == 1:
127
+ if len(filenames_list) == 1:
149
128
  return hf_hub_download(
150
- repo_id=self.repo_id,
151
- repo_type=self.repo_type,
152
- revision=self.revision,
153
- filename=self.filenames[0],
154
- cache_dir=self.cache_dir,
155
- force_download=self.force_download,
156
- token=self.token,
157
- local_dir=self.local_dir,
129
+ repo_id=repo_id,
130
+ repo_type=repo_type.value,
131
+ revision=revision,
132
+ filename=filenames_list[0],
133
+ cache_dir=cache_dir,
134
+ force_download=force_download,
135
+ token=token,
136
+ local_dir=local_dir,
158
137
  library_name="huggingface-cli",
138
+ dry_run=dry_run,
159
139
  )
160
140
 
161
141
  # Otherwise: use `snapshot_download` to ensure all files comes from same revision
162
- elif len(self.filenames) == 0:
163
- allow_patterns = self.include
164
- ignore_patterns = self.exclude
142
+ if len(filenames_list) == 0:
143
+ allow_patterns = include
144
+ ignore_patterns = exclude
165
145
  else:
166
- allow_patterns = self.filenames
146
+ allow_patterns = filenames_list
167
147
  ignore_patterns = None
168
148
 
169
149
  return snapshot_download(
170
- repo_id=self.repo_id,
171
- repo_type=self.repo_type,
172
- revision=self.revision,
150
+ repo_id=repo_id,
151
+ repo_type=repo_type.value,
152
+ revision=revision,
173
153
  allow_patterns=allow_patterns,
174
154
  ignore_patterns=ignore_patterns,
175
- force_download=self.force_download,
176
- cache_dir=self.cache_dir,
177
- token=self.token,
178
- local_dir=self.local_dir,
155
+ force_download=force_download,
156
+ cache_dir=cache_dir,
157
+ token=token,
158
+ local_dir=local_dir,
179
159
  library_name="huggingface-cli",
180
- max_workers=self.max_workers,
160
+ max_workers=max_workers,
161
+ dry_run=dry_run,
162
+ )
163
+
164
+ def _print_result(result: Union[str, DryRunFileInfo, list[DryRunFileInfo]]) -> None:
165
+ if isinstance(result, str):
166
+ print(result)
167
+ return
168
+
169
+ # Print dry run info
170
+ if isinstance(result, DryRunFileInfo):
171
+ result = [result]
172
+ print(
173
+ f"[dry-run] Will download {len([r for r in result if r.will_download])} files (out of {len(result)}) totalling {_format_size(sum(r.file_size for r in result if r.will_download))}."
181
174
  )
175
+ columns = ["File", "Bytes to download"]
176
+ items: list[list[Union[str, int]]] = []
177
+ for info in sorted(result, key=lambda x: x.filename):
178
+ items.append([info.filename, _format_size(info.file_size) if info.will_download else "-"])
179
+ print(tabulate(items, headers=columns))
180
+
181
+ if quiet:
182
+ disable_progress_bars()
183
+ with warnings.catch_warnings():
184
+ warnings.simplefilter("ignore")
185
+ _print_result(run_download())
186
+ enable_progress_bars()
187
+ else:
188
+ _print_result(run_download())
189
+ logging.set_verbosity_warning()
huggingface_hub/cli/hf.py CHANGED
@@ -12,51 +12,48 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- from argparse import ArgumentParser
16
15
 
17
- from huggingface_hub.cli.auth import AuthCommands
18
- from huggingface_hub.cli.cache import CacheCommand
19
- from huggingface_hub.cli.download import DownloadCommand
20
- from huggingface_hub.cli.jobs import JobsCommands
21
- from huggingface_hub.cli.lfs import LfsCommands
22
- from huggingface_hub.cli.repo import RepoCommands
23
- from huggingface_hub.cli.repo_files import RepoFilesCommand
24
- from huggingface_hub.cli.system import EnvironmentCommand, VersionCommand
25
- from huggingface_hub.cli.upload import UploadCommand
26
- from huggingface_hub.cli.upload_large_folder import UploadLargeFolderCommand
16
+ from huggingface_hub.cli._cli_utils import check_cli_update, typer_factory
17
+ from huggingface_hub.cli.auth import auth_cli
18
+ from huggingface_hub.cli.cache import cache_cli
19
+ from huggingface_hub.cli.download import download
20
+ from huggingface_hub.cli.jobs import jobs_cli
21
+ from huggingface_hub.cli.lfs import lfs_enable_largefiles, lfs_multipart_upload
22
+ from huggingface_hub.cli.repo import repo_cli
23
+ from huggingface_hub.cli.repo_files import repo_files_cli
24
+ from huggingface_hub.cli.system import env, version
25
+
26
+ # from huggingface_hub.cli.jobs import jobs_app
27
+ from huggingface_hub.cli.upload import upload
28
+ from huggingface_hub.cli.upload_large_folder import upload_large_folder
29
+ from huggingface_hub.utils import logging
30
+
31
+
32
+ app = typer_factory(help="Hugging Face Hub CLI")
33
+
34
+
35
+ # top level single commands (defined in their respective files)
36
+ app.command(help="Download files from the Hub.")(download)
37
+ app.command(help="Upload a file or a folder to the Hub.")(upload)
38
+ app.command(help="Upload a large folder to the Hub. Recommended for resumable uploads.")(upload_large_folder)
39
+ app.command(name="env", help="Print information about the environment.")(env)
40
+ app.command(help="Print information about the hf version.")(version)
41
+ app.command(help="Configure your repository to enable upload of files > 5GB.", hidden=True)(lfs_enable_largefiles)
42
+ app.command(help="Upload large files to the Hub.", hidden=True)(lfs_multipart_upload)
43
+
44
+
45
+ # command groups
46
+ app.add_typer(auth_cli, name="auth")
47
+ app.add_typer(cache_cli, name="cache")
48
+ app.add_typer(repo_cli, name="repo")
49
+ app.add_typer(repo_files_cli, name="repo-files")
50
+ app.add_typer(jobs_cli, name="jobs")
27
51
 
28
52
 
29
53
  def main():
30
- parser = ArgumentParser("hf", usage="hf <command> [<args>]")
31
- commands_parser = parser.add_subparsers(help="hf command helpers")
32
-
33
- # Register commands
34
- AuthCommands.register_subcommand(commands_parser)
35
- CacheCommand.register_subcommand(commands_parser)
36
- DownloadCommand.register_subcommand(commands_parser)
37
- JobsCommands.register_subcommand(commands_parser)
38
- RepoCommands.register_subcommand(commands_parser)
39
- RepoFilesCommand.register_subcommand(commands_parser)
40
- UploadCommand.register_subcommand(commands_parser)
41
- UploadLargeFolderCommand.register_subcommand(commands_parser)
42
-
43
- # System commands
44
- EnvironmentCommand.register_subcommand(commands_parser)
45
- VersionCommand.register_subcommand(commands_parser)
46
-
47
- # LFS commands (hidden in --help)
48
- LfsCommands.register_subcommand(commands_parser)
49
-
50
- # Let's go
51
- args = parser.parse_args()
52
- if not hasattr(args, "func"):
53
- parser.print_help()
54
- exit(1)
55
-
56
- # Run
57
- service = args.func(args)
58
- if service is not None:
59
- service.run()
54
+ logging.set_verbosity_info()
55
+ check_cli_update()
56
+ app()
60
57
 
61
58
 
62
59
  if __name__ == "__main__":