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
huggingface_hub/errors.py CHANGED
@@ -3,7 +3,7 @@
3
3
  from pathlib import Path
4
4
  from typing import Optional, Union
5
5
 
6
- from requests import HTTPError, Response
6
+ from httpx import HTTPError, Response
7
7
 
8
8
 
9
9
  # CACHE ERRORS
@@ -37,7 +37,7 @@ class OfflineModeIsEnabled(ConnectionError):
37
37
  """Raised when a request is made but `HF_HUB_OFFLINE=1` is set as environment variable."""
38
38
 
39
39
 
40
- class HfHubHTTPError(HTTPError):
40
+ class HfHubHTTPError(HTTPError, OSError):
41
41
  """
42
42
  HTTPError to inherit from for any custom HTTP Error raised in HF Hub.
43
43
 
@@ -51,7 +51,7 @@ class HfHubHTTPError(HTTPError):
51
51
 
52
52
  Example:
53
53
  ```py
54
- import requests
54
+ import httpx
55
55
  from huggingface_hub.utils import get_session, hf_raise_for_status, HfHubHTTPError
56
56
 
57
57
  response = get_session().post(...)
@@ -67,19 +67,18 @@ class HfHubHTTPError(HTTPError):
67
67
  ```
68
68
  """
69
69
 
70
- def __init__(self, message: str, response: Optional[Response] = None, *, server_message: Optional[str] = None):
71
- self.request_id = (
72
- response.headers.get("x-request-id") or response.headers.get("X-Amzn-Trace-Id")
73
- if response is not None
74
- else None
75
- )
70
+ def __init__(
71
+ self,
72
+ message: str,
73
+ *,
74
+ response: Response,
75
+ server_message: Optional[str] = None,
76
+ ):
77
+ self.request_id = response.headers.get("x-request-id") or response.headers.get("X-Amzn-Trace-Id")
76
78
  self.server_message = server_message
77
-
78
- super().__init__(
79
- message,
80
- response=response, # type: ignore [arg-type]
81
- request=response.request if response is not None else None, # type: ignore [arg-type]
82
- )
79
+ self.response = response
80
+ self.request = response.request
81
+ super().__init__(message)
83
82
 
84
83
  def append_to_message(self, additional_message: str) -> None:
85
84
  """Append additional information to the `HfHubHTTPError` initial message."""
@@ -161,6 +160,10 @@ class HFValidationError(ValueError):
161
160
  # FILE METADATA ERRORS
162
161
 
163
162
 
163
+ class DryRunError(OSError):
164
+ """Error triggered when a dry run is requested but cannot be performed (e.g. invalid repo)."""
165
+
166
+
164
167
  class FileMetadataError(OSError):
165
168
  """Error triggered when the metadata of a file on the Hub cannot be retrieved (missing ETag or commit_hash).
166
169
 
@@ -182,7 +185,7 @@ class RepositoryNotFoundError(HfHubHTTPError):
182
185
  >>> from huggingface_hub import model_info
183
186
  >>> model_info("<non_existent_repository>")
184
187
  (...)
185
- huggingface_hub.utils._errors.RepositoryNotFoundError: 401 Client Error. (Request ID: PvMw_VjBMjVdMz53WKIzP)
188
+ huggingface_hub.errors.RepositoryNotFoundError: 401 Client Error. (Request ID: PvMw_VjBMjVdMz53WKIzP)
186
189
 
187
190
  Repository Not Found for url: https://huggingface.co/api/models/%3Cnon_existent_repository%3E.
188
191
  Please make sure you specified the correct `repo_id` and `repo_type`.
@@ -205,7 +208,7 @@ class GatedRepoError(RepositoryNotFoundError):
205
208
  >>> from huggingface_hub import model_info
206
209
  >>> model_info("<gated_repository>")
207
210
  (...)
208
- huggingface_hub.utils._errors.GatedRepoError: 403 Client Error. (Request ID: ViT1Bf7O_026LGSQuVqfa)
211
+ huggingface_hub.errors.GatedRepoError: 403 Client Error. (Request ID: ViT1Bf7O_026LGSQuVqfa)
209
212
 
210
213
  Cannot access gated repo for url https://huggingface.co/api/models/ardent-figment/gated-model.
211
214
  Access to model ardent-figment/gated-model is restricted and you are not in the authorized list.
@@ -224,7 +227,7 @@ class DisabledRepoError(HfHubHTTPError):
224
227
  >>> from huggingface_hub import dataset_info
225
228
  >>> dataset_info("laion/laion-art")
226
229
  (...)
227
- huggingface_hub.utils._errors.DisabledRepoError: 403 Client Error. (Request ID: Root=1-659fc3fa-3031673e0f92c71a2260dbe2;bc6f4dfb-b30a-4862-af0a-5cfe827610d8)
230
+ huggingface_hub.errors.DisabledRepoError: 403 Client Error. (Request ID: Root=1-659fc3fa-3031673e0f92c71a2260dbe2;bc6f4dfb-b30a-4862-af0a-5cfe827610d8)
228
231
 
229
232
  Cannot access repository for url https://huggingface.co/api/datasets/laion/laion-art.
230
233
  Access to this resource is disabled.
@@ -246,7 +249,7 @@ class RevisionNotFoundError(HfHubHTTPError):
246
249
  >>> from huggingface_hub import hf_hub_download
247
250
  >>> hf_hub_download('bert-base-cased', 'config.json', revision='<non-existent-revision>')
248
251
  (...)
249
- huggingface_hub.utils._errors.RevisionNotFoundError: 404 Client Error. (Request ID: Mwhe_c3Kt650GcdKEFomX)
252
+ huggingface_hub.errors.RevisionNotFoundError: 404 Client Error. (Request ID: Mwhe_c3Kt650GcdKEFomX)
250
253
 
251
254
  Revision Not Found for url: https://huggingface.co/bert-base-cased/resolve/%3Cnon-existent-revision%3E/config.json.
252
255
  ```
@@ -254,7 +257,25 @@ class RevisionNotFoundError(HfHubHTTPError):
254
257
 
255
258
 
256
259
  # ENTRY ERRORS
257
- class EntryNotFoundError(HfHubHTTPError):
260
+ class EntryNotFoundError(Exception):
261
+ """
262
+ Raised when entry not found, either locally or remotely.
263
+
264
+ Example:
265
+
266
+ ```py
267
+ >>> from huggingface_hub import hf_hub_download
268
+ >>> hf_hub_download('bert-base-cased', '<non-existent-file>')
269
+ (...)
270
+ huggingface_hub.errors.RemoteEntryNotFoundError (...)
271
+ >>> hf_hub_download('bert-base-cased', '<non-existent-file>', local_files_only=True)
272
+ (...)
273
+ huggingface_hub.utils.errors.LocalEntryNotFoundError (...)
274
+ ```
275
+ """
276
+
277
+
278
+ class RemoteEntryNotFoundError(HfHubHTTPError, EntryNotFoundError):
258
279
  """
259
280
  Raised when trying to access a hf.co URL with a valid repository and revision
260
281
  but an invalid filename.
@@ -265,34 +286,30 @@ class EntryNotFoundError(HfHubHTTPError):
265
286
  >>> from huggingface_hub import hf_hub_download
266
287
  >>> hf_hub_download('bert-base-cased', '<non-existent-file>')
267
288
  (...)
268
- huggingface_hub.utils._errors.EntryNotFoundError: 404 Client Error. (Request ID: 53pNl6M0MxsnG5Sw8JA6x)
289
+ huggingface_hub.errors.EntryNotFoundError: 404 Client Error. (Request ID: 53pNl6M0MxsnG5Sw8JA6x)
269
290
 
270
291
  Entry Not Found for url: https://huggingface.co/bert-base-cased/resolve/main/%3Cnon-existent-file%3E.
271
292
  ```
272
293
  """
273
294
 
274
295
 
275
- class LocalEntryNotFoundError(EntryNotFoundError, FileNotFoundError, ValueError):
296
+ class LocalEntryNotFoundError(FileNotFoundError, EntryNotFoundError):
276
297
  """
277
298
  Raised when trying to access a file or snapshot that is not on the disk when network is
278
299
  disabled or unavailable (connection issue). The entry may exist on the Hub.
279
300
 
280
- Note: `ValueError` type is to ensure backward compatibility.
281
- Note: `LocalEntryNotFoundError` derives from `HTTPError` because of `EntryNotFoundError`
282
- even when it is not a network issue.
283
-
284
301
  Example:
285
302
 
286
303
  ```py
287
304
  >>> from huggingface_hub import hf_hub_download
288
305
  >>> hf_hub_download('bert-base-cased', '<non-cached-file>', local_files_only=True)
289
306
  (...)
290
- huggingface_hub.utils._errors.LocalEntryNotFoundError: Cannot find the requested files in the disk cache and outgoing traffic has been disabled. To enable hf.co look-ups and downloads online, set 'local_files_only' to False.
307
+ huggingface_hub.errors.LocalEntryNotFoundError: Cannot find the requested files in the disk cache and outgoing traffic has been disabled. To enable hf.co look-ups and downloads online, set 'local_files_only' to False.
291
308
  ```
292
309
  """
293
310
 
294
311
  def __init__(self, message: str):
295
- super().__init__(message, response=None)
312
+ super().__init__(message)
296
313
 
297
314
 
298
315
  # REQUEST ERROR
@@ -303,9 +320,9 @@ class BadRequestError(HfHubHTTPError, ValueError):
303
320
  Example:
304
321
 
305
322
  ```py
306
- >>> resp = requests.post("hf.co/api/check", ...)
323
+ >>> resp = httpx.post("hf.co/api/check", ...)
307
324
  >>> hf_raise_for_status(resp, endpoint_name="check")
308
- huggingface_hub.utils._errors.BadRequestError: Bad request for check endpoint: {details} (Request ID: XXX)
325
+ huggingface_hub.errors.BadRequestError: Bad request for check endpoint: {details} (Request ID: XXX)
309
326
  ```
310
327
  """
311
328
 
@@ -2,7 +2,7 @@ import json
2
2
  import os
3
3
  from pathlib import Path
4
4
  from pickle import DEFAULT_PROTOCOL, PicklingError
5
- from typing import Any, Dict, List, Optional, Union
5
+ from typing import Any, Optional, Union
6
6
 
7
7
  from packaging import version
8
8
 
@@ -16,7 +16,6 @@ from huggingface_hub.utils import (
16
16
  )
17
17
 
18
18
  from .utils import logging, validate_hf_hub_args
19
- from .utils._runtime import _PY_VERSION # noqa: F401 # for backward compatibility...
20
19
 
21
20
 
22
21
  logger = logging.get_logger(__name__)
@@ -237,7 +236,7 @@ def _create_model_pyproject(repo_dir: Path):
237
236
  def _save_pretrained_fastai(
238
237
  learner,
239
238
  save_directory: Union[str, Path],
240
- config: Optional[Dict[str, Any]] = None,
239
+ config: Optional[dict[str, Any]] = None,
241
240
  ):
242
241
  """
243
242
  Saves a fastai learner to `save_directory` in pickle format using the default pickle protocol for the version of python used.
@@ -343,9 +342,9 @@ def push_to_hub_fastai(
343
342
  config: Optional[dict] = None,
344
343
  branch: Optional[str] = None,
345
344
  create_pr: Optional[bool] = None,
346
- allow_patterns: Optional[Union[List[str], str]] = None,
347
- ignore_patterns: Optional[Union[List[str], str]] = None,
348
- delete_patterns: Optional[Union[List[str], str]] = None,
345
+ allow_patterns: Optional[Union[list[str], str]] = None,
346
+ ignore_patterns: Optional[Union[list[str], str]] = None,
347
+ delete_patterns: Optional[Union[list[str], str]] = None,
349
348
  api_endpoint: Optional[str] = None,
350
349
  ):
351
350
  """
@@ -378,11 +377,11 @@ def push_to_hub_fastai(
378
377
  Defaults to `False`.
379
378
  api_endpoint (`str`, *optional*):
380
379
  The API endpoint to use when pushing the model to the hub.
381
- allow_patterns (`List[str]` or `str`, *optional*):
380
+ allow_patterns (`list[str]` or `str`, *optional*):
382
381
  If provided, only files matching at least one pattern are pushed.
383
- ignore_patterns (`List[str]` or `str`, *optional*):
382
+ ignore_patterns (`list[str]` or `str`, *optional*):
384
383
  If provided, files matching any of the patterns are not pushed.
385
- delete_patterns (`List[str]` or `str`, *optional*):
384
+ delete_patterns (`list[str]` or `str`, *optional*):
386
385
  If provided, remote files matching any of the patterns will be deleted from the repo.
387
386
 
388
387
  Returns: