huggingface-hub 0.22.2__py3-none-any.whl → 0.23.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 (45) hide show
  1. huggingface_hub/__init__.py +51 -19
  2. huggingface_hub/_commit_api.py +9 -8
  3. huggingface_hub/_commit_scheduler.py +2 -2
  4. huggingface_hub/_inference_endpoints.py +10 -17
  5. huggingface_hub/_local_folder.py +229 -0
  6. huggingface_hub/_login.py +4 -3
  7. huggingface_hub/_multi_commits.py +1 -1
  8. huggingface_hub/_snapshot_download.py +16 -38
  9. huggingface_hub/_tensorboard_logger.py +16 -6
  10. huggingface_hub/_webhooks_payload.py +22 -1
  11. huggingface_hub/_webhooks_server.py +24 -20
  12. huggingface_hub/commands/download.py +11 -34
  13. huggingface_hub/commands/huggingface_cli.py +2 -0
  14. huggingface_hub/commands/tag.py +159 -0
  15. huggingface_hub/constants.py +3 -5
  16. huggingface_hub/errors.py +58 -0
  17. huggingface_hub/file_download.py +545 -376
  18. huggingface_hub/hf_api.py +756 -622
  19. huggingface_hub/hf_file_system.py +14 -5
  20. huggingface_hub/hub_mixin.py +127 -43
  21. huggingface_hub/inference/_client.py +402 -183
  22. huggingface_hub/inference/_common.py +19 -29
  23. huggingface_hub/inference/_generated/_async_client.py +402 -184
  24. huggingface_hub/inference/_generated/types/__init__.py +23 -6
  25. huggingface_hub/inference/_generated/types/chat_completion.py +197 -43
  26. huggingface_hub/inference/_generated/types/text_generation.py +57 -79
  27. huggingface_hub/inference/_templating.py +2 -4
  28. huggingface_hub/keras_mixin.py +0 -3
  29. huggingface_hub/lfs.py +9 -1
  30. huggingface_hub/repository.py +1 -0
  31. huggingface_hub/utils/__init__.py +12 -6
  32. huggingface_hub/utils/_fixes.py +1 -0
  33. huggingface_hub/utils/_headers.py +2 -4
  34. huggingface_hub/utils/_http.py +2 -4
  35. huggingface_hub/utils/_paths.py +13 -1
  36. huggingface_hub/utils/_runtime.py +10 -0
  37. huggingface_hub/utils/_safetensors.py +0 -13
  38. huggingface_hub/utils/_validators.py +2 -7
  39. huggingface_hub/utils/tqdm.py +124 -46
  40. {huggingface_hub-0.22.2.dist-info → huggingface_hub-0.23.0.dist-info}/METADATA +5 -1
  41. {huggingface_hub-0.22.2.dist-info → huggingface_hub-0.23.0.dist-info}/RECORD +45 -43
  42. {huggingface_hub-0.22.2.dist-info → huggingface_hub-0.23.0.dist-info}/LICENSE +0 -0
  43. {huggingface_hub-0.22.2.dist-info → huggingface_hub-0.23.0.dist-info}/WHEEL +0 -0
  44. {huggingface_hub-0.22.2.dist-info → huggingface_hub-0.23.0.dist-info}/entry_points.txt +0 -0
  45. {huggingface_hub-0.22.2.dist-info → huggingface_hub-0.23.0.dist-info}/top_level.txt +0 -0
huggingface_hub/hf_api.py CHANGED
@@ -104,7 +104,7 @@ from .constants import (
104
104
  from .file_download import HfFileMetadata, get_hf_file_metadata, hf_hub_url
105
105
  from .repocard_data import DatasetCardData, ModelCardData, SpaceCardData
106
106
  from .utils import ( # noqa: F401 # imported for backward compatibility
107
- IGNORE_GIT_FOLDER_PATTERNS,
107
+ DEFAULT_IGNORE_PATTERNS,
108
108
  BadRequestError,
109
109
  EntryNotFoundError,
110
110
  GatedRepoError,
@@ -130,7 +130,7 @@ from .utils import ( # noqa: F401 # imported for backward compatibility
130
130
  validate_hf_hub_args,
131
131
  )
132
132
  from .utils import tqdm as hf_tqdm
133
- from .utils._deprecation import _deprecate_arguments, _deprecate_method
133
+ from .utils._deprecation import _deprecate_arguments
134
134
  from .utils._typing import CallableT
135
135
  from .utils.endpoint_helpers import (
136
136
  DatasetFilter,
@@ -500,10 +500,10 @@ class RepoFile:
500
500
  lfs (`BlobLfsInfo`):
501
501
  The file's LFS metadata.
502
502
  last_commit (`LastCommitInfo`, *optional*):
503
- The file's last commit metadata. Only defined if [`list_files_info`], [`list_repo_tree`] and [`get_paths_info`]
503
+ The file's last commit metadata. Only defined if [`list_repo_tree`] and [`get_paths_info`]
504
504
  are called with `expand=True`.
505
505
  security (`BlobSecurityInfo`, *optional*):
506
- The file's security scan metadata. Only defined if [`list_files_info`], [`list_repo_tree`] and [`get_paths_info`]
506
+ The file's security scan metadata. Only defined if [`list_repo_tree`] and [`get_paths_info`]
507
507
  are called with `expand=True`.
508
508
  """
509
509
 
@@ -603,7 +603,7 @@ class ModelInfo:
603
603
  Is the repo gated.
604
604
  If so, whether there is manual or automatic approval.
605
605
  downloads (`int`):
606
- Number of downloads of the model.
606
+ Number of downloads of the model over the last 30 days.
607
607
  likes (`int`):
608
608
  Number of likes of the model.
609
609
  library_name (`str`, *optional*):
@@ -707,7 +707,14 @@ class ModelInfo:
707
707
  )
708
708
  self.spaces = kwargs.pop("spaces", None)
709
709
  safetensors = kwargs.pop("safetensors", None)
710
- self.safetensors = SafeTensorsInfo(**safetensors) if safetensors else None
710
+ self.safetensors = (
711
+ SafeTensorsInfo(
712
+ parameters=safetensors["parameters"],
713
+ total=safetensors["total"],
714
+ )
715
+ if safetensors
716
+ else None
717
+ )
711
718
 
712
719
  # backwards compatibility
713
720
  self.lastModified = self.last_modified
@@ -749,7 +756,7 @@ class DatasetInfo:
749
756
  Is the repo gated.
750
757
  If so, whether there is manual or automatic approval.
751
758
  downloads (`int`):
752
- Number of downloads of the dataset.
759
+ Number of downloads of the dataset over the last 30 days.
753
760
  likes (`int`):
754
761
  Number of likes of the dataset.
755
762
  tags (`List[str]`):
@@ -1192,12 +1199,61 @@ class User:
1192
1199
  Name of the user on the Hub (unique).
1193
1200
  fullname (`str`):
1194
1201
  User's full name.
1202
+ is_pro (`bool`, *optional*):
1203
+ Whether the user is a pro user.
1204
+ num_models (`int`, *optional*):
1205
+ Number of models created by the user.
1206
+ num_datasets (`int`, *optional*):
1207
+ Number of datasets created by the user.
1208
+ num_spaces (`int`, *optional*):
1209
+ Number of spaces created by the user.
1210
+ num_discussions (`int`, *optional*):
1211
+ Number of discussions initiated by the user.
1212
+ num_papers (`int`, *optional*):
1213
+ Number of papers authored by the user.
1214
+ num_upvotes (`int`, *optional*):
1215
+ Number of upvotes received by the user.
1216
+ num_likes (`int`, *optional*):
1217
+ Number of likes given by the user.
1218
+ is_following (`bool`, *optional*):
1219
+ Whether the authenticated user is following this user.
1220
+ details (`str`, *optional*):
1221
+ User's details.
1195
1222
  """
1196
1223
 
1197
1224
  # Metadata
1198
1225
  avatar_url: str
1199
1226
  username: str
1200
1227
  fullname: str
1228
+ is_pro: Optional[bool] = None
1229
+ num_models: Optional[int] = None
1230
+ num_datasets: Optional[int] = None
1231
+ num_spaces: Optional[int] = None
1232
+ num_discussions: Optional[int] = None
1233
+ num_papers: Optional[int] = None
1234
+ num_upvotes: Optional[int] = None
1235
+ num_likes: Optional[int] = None
1236
+ is_following: Optional[bool] = None
1237
+ details: Optional[str] = None
1238
+
1239
+ def __init__(self, **kwargs) -> None:
1240
+ self.avatar_url = kwargs.get("avatarUrl", "")
1241
+ self.username = kwargs.get("user", "")
1242
+ self.fullname = kwargs.get("fullname", "")
1243
+ self.is_pro = kwargs.get("isPro")
1244
+ self.num_models = kwargs.get("numModels")
1245
+ self.num_datasets = kwargs.get("numDatasets")
1246
+ self.num_spaces = kwargs.get("numSpaces")
1247
+ self.num_discussions = kwargs.get("numDiscussions")
1248
+ self.num_papers = kwargs.get("numPapers")
1249
+ self.num_upvotes = kwargs.get("numUpvotes")
1250
+ self.num_likes = kwargs.get("numLikes")
1251
+ self.user_type = kwargs.get("type")
1252
+ self.is_following = kwargs.get("isFollowing")
1253
+ self.details = kwargs.get("details")
1254
+
1255
+ # forward compatibility
1256
+ self.__dict__.update(**kwargs)
1201
1257
 
1202
1258
 
1203
1259
  def future_compatible(fn: CallableT) -> CallableT:
@@ -1251,9 +1307,11 @@ class HfApi:
1251
1307
  directly at the root of `huggingface_hub`.
1252
1308
 
1253
1309
  Args:
1254
- token (`str` or `bool`, *optional*):
1255
- Hugging Face token. Will default to the locally saved token if not provided.
1256
- Pass `token=False` if you don't want to send your token to the server.
1310
+ token (Union[bool, str, None], optional):
1311
+ A valid user access token (string). Defaults to the locally saved
1312
+ token, which is the recommended method for authentication (see
1313
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
1314
+ To disable authentication, pass `False`.
1257
1315
  library_name (`str`, *optional*):
1258
1316
  The name of the library that is making the HTTP request. Will be added to
1259
1317
  the user-agent header. Example: `"transformers"`.
@@ -1316,14 +1374,16 @@ class HfApi:
1316
1374
  return self._thread_pool.submit(fn, *args, **kwargs)
1317
1375
 
1318
1376
  @validate_hf_hub_args
1319
- def whoami(self, token: Optional[str] = None) -> Dict:
1377
+ def whoami(self, token: Union[bool, str, None] = None) -> Dict:
1320
1378
  """
1321
1379
  Call HF API to know "whoami".
1322
1380
 
1323
1381
  Args:
1324
- token (`str`, *optional*):
1325
- Hugging Face token. Will default to the locally saved token if
1326
- not provided.
1382
+ token (Union[bool, str, None], optional):
1383
+ A valid user access token (string). Defaults to the locally saved
1384
+ token, which is the recommended method for authentication (see
1385
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
1386
+ To disable authentication, pass `False`.
1327
1387
  """
1328
1388
  r = get_session().get(
1329
1389
  f"{self.endpoint}/api/whoami-v2",
@@ -1345,15 +1405,18 @@ class HfApi:
1345
1405
  ) from e
1346
1406
  return r.json()
1347
1407
 
1348
- def get_token_permission(self, token: Optional[str] = None) -> Literal["read", "write", None]:
1408
+ def get_token_permission(self, token: Union[bool, str, None] = None) -> Literal["read", "write", None]:
1349
1409
  """
1350
1410
  Check if a given `token` is valid and return its permissions.
1351
1411
 
1352
1412
  For more details about tokens, please refer to https://huggingface.co/docs/hub/security-tokens#what-are-user-access-tokens.
1353
1413
 
1354
1414
  Args:
1355
- token (`str`, *optional*):
1356
- The token to check for validity. Defaults to the one saved locally.
1415
+ token (Union[bool, str, None], optional):
1416
+ A valid user access token (string). Defaults to the locally saved
1417
+ token, which is the recommended method for authentication (see
1418
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
1419
+ To disable authentication, pass `False`.
1357
1420
 
1358
1421
  Returns:
1359
1422
  `Literal["read", "write", None]`: Permission granted by the token ("read" or "write"). Returns `None` if no
@@ -1402,7 +1465,7 @@ class HfApi:
1402
1465
  full: Optional[bool] = None,
1403
1466
  cardData: bool = False,
1404
1467
  fetch_config: bool = False,
1405
- token: Optional[Union[bool, str]] = None,
1468
+ token: Union[bool, str, None] = None,
1406
1469
  pipeline_tag: Optional[str] = None,
1407
1470
  ) -> Iterable[ModelInfo]:
1408
1471
  """
@@ -1458,11 +1521,11 @@ class HfApi:
1458
1521
  fetch_config (`bool`, *optional*):
1459
1522
  Whether to fetch the model configs as well. This is not included
1460
1523
  in `full` due to its size.
1461
- token (`bool` or `str`, *optional*):
1462
- A valid authentication token (see https://huggingface.co/settings/token).
1463
- If `None` or `True` and machine is logged in (through `huggingface-cli login`
1464
- or [`~huggingface_hub.login`]), token will be retrieved from the cache.
1465
- If `False`, token is not sent in the request header.
1524
+ token (Union[bool, str, None], optional):
1525
+ A valid user access token (string). Defaults to the locally saved
1526
+ token, which is the recommended method for authentication (see
1527
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
1528
+ To disable authentication, pass `False`.
1466
1529
  pipeline_tag (`str`, *optional*):
1467
1530
  A string pipeline tag to filter models on the Hub by, such as `summarization`
1468
1531
 
@@ -1642,7 +1705,7 @@ class HfApi:
1642
1705
  direction: Optional[Literal[-1]] = None,
1643
1706
  limit: Optional[int] = None,
1644
1707
  full: Optional[bool] = None,
1645
- token: Optional[str] = None,
1708
+ token: Union[bool, str, None] = None,
1646
1709
  ) -> Iterable[DatasetInfo]:
1647
1710
  """
1648
1711
  List datasets hosted on the Huggingface Hub, given some filters.
@@ -1696,11 +1759,11 @@ class HfApi:
1696
1759
  Whether to fetch all dataset data, including the `last_modified`,
1697
1760
  the `card_data` and the files. Can contain useful information such as the
1698
1761
  PapersWithCode ID.
1699
- token (`bool` or `str`, *optional*):
1700
- A valid authentication token (see https://huggingface.co/settings/token).
1701
- If `None` or `True` and machine is logged in (through `huggingface-cli login`
1702
- or [`~huggingface_hub.login`]), token will be retrieved from the cache.
1703
- If `False`, token is not sent in the request header.
1762
+ token (Union[bool, str, None], optional):
1763
+ A valid user access token (string). Defaults to the locally saved
1764
+ token, which is the recommended method for authentication (see
1765
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
1766
+ To disable authentication, pass `False`.
1704
1767
 
1705
1768
  Returns:
1706
1769
  `Iterable[DatasetInfo]`: an iterable of [`huggingface_hub.hf_api.DatasetInfo`] objects.
@@ -1868,7 +1931,7 @@ class HfApi:
1868
1931
  models: Union[str, Iterable[str], None] = None,
1869
1932
  linked: bool = False,
1870
1933
  full: Optional[bool] = None,
1871
- token: Optional[str] = None,
1934
+ token: Union[bool, str, None] = None,
1872
1935
  ) -> Iterable[SpaceInfo]:
1873
1936
  """
1874
1937
  List spaces hosted on the Huggingface Hub, given some filters.
@@ -1900,11 +1963,11 @@ class HfApi:
1900
1963
  full (`bool`, *optional*):
1901
1964
  Whether to fetch all Spaces data, including the `last_modified`, `siblings`
1902
1965
  and `card_data` fields.
1903
- token (`bool` or `str`, *optional*):
1904
- A valid authentication token (see https://huggingface.co/settings/token).
1905
- If `None` or `True` and machine is logged in (through `huggingface-cli login`
1906
- or [`~huggingface_hub.login`]), token will be retrieved from the cache.
1907
- If `False`, token is not sent in the request header.
1966
+ token (Union[bool, str, None], optional):
1967
+ A valid user access token (string). Defaults to the locally saved
1968
+ token, which is the recommended method for authentication (see
1969
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
1970
+ To disable authentication, pass `False`.
1908
1971
 
1909
1972
  Returns:
1910
1973
  `Iterable[SpaceInfo]`: an iterable of [`huggingface_hub.hf_api.SpaceInfo`] objects.
@@ -1946,7 +2009,7 @@ class HfApi:
1946
2009
  self,
1947
2010
  repo_id: str,
1948
2011
  *,
1949
- token: Optional[str] = None,
2012
+ token: Union[bool, str, None] = None,
1950
2013
  repo_type: Optional[str] = None,
1951
2014
  ) -> None:
1952
2015
  """
@@ -1958,8 +2021,11 @@ class HfApi:
1958
2021
  repo_id (`str`):
1959
2022
  The repository to like. Example: `"user/my-cool-model"`.
1960
2023
 
1961
- token (`str`, *optional*):
1962
- Authentication token. Will default to the stored token.
2024
+ token (Union[bool, str, None], optional):
2025
+ A valid user access token (string). Defaults to the locally saved
2026
+ token, which is the recommended method for authentication (see
2027
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
2028
+ To disable authentication, pass `False`.
1963
2029
 
1964
2030
  repo_type (`str`, *optional*):
1965
2031
  Set to `"dataset"` or `"space"` if liking a dataset or space, `None` or
@@ -1994,7 +2060,7 @@ class HfApi:
1994
2060
  self,
1995
2061
  repo_id: str,
1996
2062
  *,
1997
- token: Optional[str] = None,
2063
+ token: Union[bool, str, None] = None,
1998
2064
  repo_type: Optional[str] = None,
1999
2065
  ) -> None:
2000
2066
  """
@@ -2006,8 +2072,11 @@ class HfApi:
2006
2072
  repo_id (`str`):
2007
2073
  The repository to unlike. Example: `"user/my-cool-model"`.
2008
2074
 
2009
- token (`str`, *optional*):
2010
- Authentication token. Will default to the stored token.
2075
+ token (Union[bool, str, None], optional):
2076
+ A valid user access token (string). Defaults to the locally saved
2077
+ token, which is the recommended method for authentication (see
2078
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
2079
+ To disable authentication, pass `False`.
2011
2080
 
2012
2081
  repo_type (`str`, *optional*):
2013
2082
  Set to `"dataset"` or `"space"` if unliking a dataset or space, `None` or
@@ -2041,7 +2110,7 @@ class HfApi:
2041
2110
  self,
2042
2111
  user: Optional[str] = None,
2043
2112
  *,
2044
- token: Optional[str] = None,
2113
+ token: Union[bool, str, None] = None,
2045
2114
  ) -> UserLikes:
2046
2115
  """
2047
2116
  List all public repos liked by a user on huggingface.co.
@@ -2054,10 +2123,11 @@ class HfApi:
2054
2123
  Args:
2055
2124
  user (`str`, *optional*):
2056
2125
  Name of the user for which you want to fetch the likes.
2057
- token (`str`, *optional*):
2058
- A valid authentication token (see https://huggingface.co/settings/token).
2059
- Used only if `user` is not passed to implicitly determine the current
2060
- user name.
2126
+ token (Union[bool, str, None], optional):
2127
+ A valid user access token (string). Defaults to the locally saved
2128
+ token, which is the recommended method for authentication (see
2129
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
2130
+ To disable authentication, pass `False`.
2061
2131
 
2062
2132
  Returns:
2063
2133
  [`UserLikes`]: object containing the user name and 3 lists of repo ids (1 for
@@ -2117,7 +2187,7 @@ class HfApi:
2117
2187
  repo_id: str,
2118
2188
  *,
2119
2189
  repo_type: Optional[str] = None,
2120
- token: Optional[str] = None,
2190
+ token: Union[bool, str, None] = None,
2121
2191
  ) -> List[User]:
2122
2192
  """
2123
2193
  List all users who liked a given repo on the hugging Face Hub.
@@ -2128,8 +2198,11 @@ class HfApi:
2128
2198
  repo_id (`str`):
2129
2199
  The repository to retrieve . Example: `"user/my-cool-model"`.
2130
2200
 
2131
- token (`str`, *optional*):
2132
- Authentication token. Will default to the stored token.
2201
+ token (Union[bool, str, None], optional):
2202
+ A valid user access token (string). Defaults to the locally saved
2203
+ token, which is the recommended method for authentication (see
2204
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
2205
+ To disable authentication, pass `False`.
2133
2206
 
2134
2207
  repo_type (`str`, *optional*):
2135
2208
  Set to `"dataset"` or `"space"` if uploading to a dataset or
@@ -2170,7 +2243,7 @@ class HfApi:
2170
2243
  timeout: Optional[float] = None,
2171
2244
  securityStatus: Optional[bool] = None,
2172
2245
  files_metadata: bool = False,
2173
- token: Optional[Union[bool, str]] = None,
2246
+ token: Union[bool, str, None] = None,
2174
2247
  ) -> ModelInfo:
2175
2248
  """
2176
2249
  Get info on one specific model on huggingface.co
@@ -2192,11 +2265,11 @@ class HfApi:
2192
2265
  files_metadata (`bool`, *optional*):
2193
2266
  Whether or not to retrieve metadata for files in the repository
2194
2267
  (size, LFS metadata, etc). Defaults to `False`.
2195
- token (`bool` or `str`, *optional*):
2196
- A valid authentication token (see https://huggingface.co/settings/token).
2197
- If `None` or `True` and machine is logged in (through `huggingface-cli login`
2198
- or [`~huggingface_hub.login`]), token will be retrieved from the cache.
2199
- If `False`, token is not sent in the request header.
2268
+ token (Union[bool, str, None], optional):
2269
+ A valid user access token (string). Defaults to the locally saved
2270
+ token, which is the recommended method for authentication (see
2271
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
2272
+ To disable authentication, pass `False`.
2200
2273
 
2201
2274
  Returns:
2202
2275
  [`huggingface_hub.hf_api.ModelInfo`]: The model repository information.
@@ -2237,7 +2310,7 @@ class HfApi:
2237
2310
  revision: Optional[str] = None,
2238
2311
  timeout: Optional[float] = None,
2239
2312
  files_metadata: bool = False,
2240
- token: Optional[Union[bool, str]] = None,
2313
+ token: Union[bool, str, None] = None,
2241
2314
  ) -> DatasetInfo:
2242
2315
  """
2243
2316
  Get info on one specific dataset on huggingface.co.
@@ -2256,11 +2329,11 @@ class HfApi:
2256
2329
  files_metadata (`bool`, *optional*):
2257
2330
  Whether or not to retrieve metadata for files in the repository
2258
2331
  (size, LFS metadata, etc). Defaults to `False`.
2259
- token (`bool` or `str`, *optional*):
2260
- A valid authentication token (see https://huggingface.co/settings/token).
2261
- If `None` or `True` and machine is logged in (through `huggingface-cli login`
2262
- or [`~huggingface_hub.login`]), token will be retrieved from the cache.
2263
- If `False`, token is not sent in the request header.
2332
+ token (Union[bool, str, None], optional):
2333
+ A valid user access token (string). Defaults to the locally saved
2334
+ token, which is the recommended method for authentication (see
2335
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
2336
+ To disable authentication, pass `False`.
2264
2337
 
2265
2338
  Returns:
2266
2339
  [`hf_api.DatasetInfo`]: The dataset repository information.
@@ -2300,7 +2373,7 @@ class HfApi:
2300
2373
  revision: Optional[str] = None,
2301
2374
  timeout: Optional[float] = None,
2302
2375
  files_metadata: bool = False,
2303
- token: Optional[Union[bool, str]] = None,
2376
+ token: Union[bool, str, None] = None,
2304
2377
  ) -> SpaceInfo:
2305
2378
  """
2306
2379
  Get info on one specific Space on huggingface.co.
@@ -2319,11 +2392,11 @@ class HfApi:
2319
2392
  files_metadata (`bool`, *optional*):
2320
2393
  Whether or not to retrieve metadata for files in the repository
2321
2394
  (size, LFS metadata, etc). Defaults to `False`.
2322
- token (`bool` or `str`, *optional*):
2323
- A valid authentication token (see https://huggingface.co/settings/token).
2324
- If `None` or `True` and machine is logged in (through `huggingface-cli login`
2325
- or [`~huggingface_hub.login`]), token will be retrieved from the cache.
2326
- If `False`, token is not sent in the request header.
2395
+ token (Union[bool, str, None], optional):
2396
+ A valid user access token (string). Defaults to the locally saved
2397
+ token, which is the recommended method for authentication (see
2398
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
2399
+ To disable authentication, pass `False`.
2327
2400
 
2328
2401
  Returns:
2329
2402
  [`~hf_api.SpaceInfo`]: The space repository information.
@@ -2364,7 +2437,7 @@ class HfApi:
2364
2437
  repo_type: Optional[str] = None,
2365
2438
  timeout: Optional[float] = None,
2366
2439
  files_metadata: bool = False,
2367
- token: Optional[Union[bool, str]] = None,
2440
+ token: Union[bool, str, None] = None,
2368
2441
  ) -> Union[ModelInfo, DatasetInfo, SpaceInfo]:
2369
2442
  """
2370
2443
  Get the info object for a given repo of a given type.
@@ -2384,11 +2457,11 @@ class HfApi:
2384
2457
  files_metadata (`bool`, *optional*):
2385
2458
  Whether or not to retrieve metadata for files in the repository
2386
2459
  (size, LFS metadata, etc). Defaults to `False`.
2387
- token (`bool` or `str`, *optional*):
2388
- A valid authentication token (see https://huggingface.co/settings/token).
2389
- If `None` or `True` and machine is logged in (through `huggingface-cli login`
2390
- or [`~huggingface_hub.login`]), token will be retrieved from the cache.
2391
- If `False`, token is not sent in the request header.
2460
+ token (Union[bool, str, None], optional):
2461
+ A valid user access token (string). Defaults to the locally saved
2462
+ token, which is the recommended method for authentication (see
2463
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
2464
+ To disable authentication, pass `False`.
2392
2465
 
2393
2466
  Returns:
2394
2467
  `Union[SpaceInfo, DatasetInfo, ModelInfo]`: The repository information, as a
@@ -2429,7 +2502,7 @@ class HfApi:
2429
2502
  repo_id: str,
2430
2503
  *,
2431
2504
  repo_type: Optional[str] = None,
2432
- token: Optional[str] = None,
2505
+ token: Union[str, bool, None] = None,
2433
2506
  ) -> bool:
2434
2507
  """
2435
2508
  Checks if a repository exists on the Hugging Face Hub.
@@ -2441,11 +2514,11 @@ class HfApi:
2441
2514
  repo_type (`str`, *optional*):
2442
2515
  Set to `"dataset"` or `"space"` if getting repository info from a dataset or a space,
2443
2516
  `None` or `"model"` if getting repository info from a model. Default is `None`.
2444
- token (`bool` or `str`, *optional*):
2445
- A valid authentication token (see https://huggingface.co/settings/token).
2446
- If `None` or `True` and machine is logged in (through `huggingface-cli login`
2447
- or [`~huggingface_hub.login`]), token will be retrieved from the cache.
2448
- If `False`, token is not sent in the request header.
2517
+ token (Union[bool, str, None], optional):
2518
+ A valid user access token (string). Defaults to the locally saved
2519
+ token, which is the recommended method for authentication (see
2520
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
2521
+ To disable authentication, pass `False`.
2449
2522
 
2450
2523
  Returns:
2451
2524
  True if the repository exists, False otherwise.
@@ -2474,7 +2547,7 @@ class HfApi:
2474
2547
  revision: str,
2475
2548
  *,
2476
2549
  repo_type: Optional[str] = None,
2477
- token: Optional[str] = None,
2550
+ token: Union[str, bool, None] = None,
2478
2551
  ) -> bool:
2479
2552
  """
2480
2553
  Checks if a specific revision exists on a repo on the Hugging Face Hub.
@@ -2488,11 +2561,11 @@ class HfApi:
2488
2561
  repo_type (`str`, *optional*):
2489
2562
  Set to `"dataset"` or `"space"` if getting repository info from a dataset or a space,
2490
2563
  `None` or `"model"` if getting repository info from a model. Default is `None`.
2491
- token (`bool` or `str`, *optional*):
2492
- A valid authentication token (see https://huggingface.co/settings/token).
2493
- If `None` or `True` and machine is logged in (through `huggingface-cli login`
2494
- or [`~huggingface_hub.login`]), token will be retrieved from the cache.
2495
- If `False`, token is not sent in the request header.
2564
+ token (Union[bool, str, None], optional):
2565
+ A valid user access token (string). Defaults to the locally saved
2566
+ token, which is the recommended method for authentication (see
2567
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
2568
+ To disable authentication, pass `False`.
2496
2569
 
2497
2570
  Returns:
2498
2571
  True if the repository and the revision exists, False otherwise.
@@ -2539,11 +2612,11 @@ class HfApi:
2539
2612
  `None` or `"model"` if getting repository info from a model. Default is `None`.
2540
2613
  revision (`str`, *optional*):
2541
2614
  The revision of the repository from which to get the information. Defaults to `"main"` branch.
2542
- token (`bool` or `str`, *optional*):
2543
- A valid authentication token (see https://huggingface.co/settings/token).
2544
- If `None` or `True` and machine is logged in (through `huggingface-cli login`
2545
- or [`~huggingface_hub.login`]), token will be retrieved from the cache.
2546
- If `False`, token is not sent in the request header.
2615
+ token (Union[bool, str, None], optional):
2616
+ A valid user access token (string). Defaults to the locally saved
2617
+ token, which is the recommended method for authentication (see
2618
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
2619
+ To disable authentication, pass `False`.
2547
2620
 
2548
2621
  Returns:
2549
2622
  True if the file exists, False otherwise.
@@ -2572,190 +2645,6 @@ class HfApi:
2572
2645
  except (RepositoryNotFoundError, EntryNotFoundError, RevisionNotFoundError):
2573
2646
  return False
2574
2647
 
2575
- @validate_hf_hub_args
2576
- @_deprecate_method(version="0.23", message="Use `list_repo_tree` and `get_paths_info` instead.")
2577
- def list_files_info(
2578
- self,
2579
- repo_id: str,
2580
- paths: Union[List[str], str, None] = None,
2581
- *,
2582
- expand: bool = False,
2583
- revision: Optional[str] = None,
2584
- repo_type: Optional[str] = None,
2585
- token: Optional[Union[bool, str]] = None,
2586
- ) -> Iterable[RepoFile]:
2587
- """
2588
- List files on a repo and get information about them.
2589
-
2590
- Takes as input a list of paths. Those paths can be either files or folders. Two server endpoints are called:
2591
- 1. POST "/paths-info" to get information about the provided paths. Called once.
2592
- 2. GET "/tree?recursive=True" to paginate over the input folders. Called only if a folder path is provided as
2593
- input. Will be called multiple times to follow pagination.
2594
- If no path is provided as input, step 1. is ignored and all files from the repo are listed.
2595
-
2596
- Args:
2597
- repo_id (`str`):
2598
- A namespace (user or an organization) and a repo name separated by a `/`.
2599
- paths (`Union[List[str], str, None]`, *optional*):
2600
- The paths to get information about. Paths to files are directly resolved. Paths to folders are resolved
2601
- recursively which means that information is returned about all files in the folder and its subfolders.
2602
- If `None`, all files are returned (the default). If a path do not exist, it is ignored without raising
2603
- an exception.
2604
- expand (`bool`, *optional*, defaults to `False`):
2605
- Whether to fetch more information about the files (e.g. last commit and security scan results). This
2606
- operation is more expensive for the server so only 50 results are returned per page (instead of 1000).
2607
- As pagination is implemented in `huggingface_hub`, this is transparent for you except for the time it
2608
- takes to get the results.
2609
- revision (`str`, *optional*):
2610
- The revision of the repository from which to get the information. Defaults to `"main"` branch.
2611
- repo_type (`str`, *optional*):
2612
- The type of the repository from which to get the information (`"model"`, `"dataset"` or `"space"`.
2613
- Defaults to `"model"`.
2614
- token (`bool` or `str`, *optional*):
2615
- A valid authentication token (see https://huggingface.co/settings/token). If `None` or `True` and
2616
- machine is logged in (through `huggingface-cli login` or [`~huggingface_hub.login`]), token will be
2617
- retrieved from the cache. If `False`, token is not sent in the request header.
2618
-
2619
- Returns:
2620
- `Iterable[RepoFile]`:
2621
- The information about the files, as an iterable of [`RepoFile`] objects. The order of the files is
2622
- not guaranteed.
2623
-
2624
- Raises:
2625
- [`~utils.RepositoryNotFoundError`]:
2626
- If repository is not found (error 404): wrong repo_id/repo_type, private but not authenticated or repo
2627
- does not exist.
2628
- [`~utils.RevisionNotFoundError`]:
2629
- If revision is not found (error 404) on the repo.
2630
-
2631
- Examples:
2632
-
2633
- Get information about files on a repo.
2634
- ```py
2635
- >>> from huggingface_hub import list_files_info
2636
- >>> files_info = list_files_info("lysandre/arxiv-nlp", ["README.md", "config.json"])
2637
- >>> files_info
2638
- <generator object HfApi.list_files_info at 0x7f93b848e730>
2639
- >>> list(files_info)
2640
- [
2641
- RepoFile(path='README.md', size=391, blob_id='43bd404b159de6fba7c2f4d3264347668d43af25', lfs=None, last_commit=None, security=None),
2642
- RepoFile(path='config.json', size=554, blob_id='2f9618c3a19b9a61add74f70bfb121335aeef666', lfs=None, last_commit=None, security=None)
2643
- ]
2644
- ```
2645
-
2646
- Get even more information about files on a repo (last commit and security scan results)
2647
- ```py
2648
- >>> from huggingface_hub import list_files_info
2649
- >>> files_info = list_files_info("prompthero/openjourney-v4", expand=True)
2650
- >>> list(files_info)
2651
- [
2652
- RepoFile(
2653
- path='safety_checker/pytorch_model.bin',
2654
- size=1216064769,
2655
- blob_id='c8835557a0d3af583cb06c7c154b7e54a069c41d',
2656
- lfs={
2657
- 'size': 1216064769,
2658
- 'sha256': '16d28f2b37109f222cdc33620fdd262102ac32112be0352a7f77e9614b35a394',
2659
- 'pointer_size': 135
2660
- },
2661
- last_commit={
2662
- 'oid': '47b62b20b20e06b9de610e840282b7e6c3d51190',
2663
- 'title': 'Upload diffusers weights (#48)',
2664
- 'date': datetime.datetime(2023, 3, 21, 10, 5, 27, tzinfo=datetime.timezone.utc)
2665
- },
2666
- security={
2667
- 'safe': True,
2668
- 'av_scan': {
2669
- 'virusFound': False,
2670
- 'virusNames': None
2671
- },
2672
- 'pickle_import_scan': {
2673
- 'highestSafetyLevel': 'innocuous',
2674
- 'imports': [
2675
- {'module': 'torch', 'name': 'FloatStorage', 'safety': 'innocuous'},
2676
- {'module': 'collections', 'name': 'OrderedDict', 'safety': 'innocuous'},
2677
- {'module': 'torch', 'name': 'LongStorage', 'safety': 'innocuous'},
2678
- {'module': 'torch._utils', 'name': '_rebuild_tensor_v2', 'safety': 'innocuous'}
2679
- ]
2680
- }
2681
- }
2682
- ),
2683
- RepoFile(
2684
- path='scheduler/scheduler_config.json',
2685
- size=465,
2686
- blob_id='70d55e3e9679f41cbc66222831b38d5abce683dd',
2687
- lfs=None,
2688
- last_commit={
2689
- 'oid': '47b62b20b20e06b9de610e840282b7e6c3d51190',
2690
- 'title': 'Upload diffusers weights (#48)',
2691
- 'date': datetime.datetime(2023, 3, 21, 10, 5, 27, tzinfo=datetime.timezone.utc)},
2692
- security={
2693
- 'safe': True,
2694
- 'av_scan': {
2695
- 'virusFound': False,
2696
- 'virusNames': None
2697
- },
2698
- 'pickle_import_scan': None
2699
- }
2700
- ),
2701
- ...
2702
- ]
2703
- ```
2704
-
2705
- List LFS files from the "vae/" folder in "stabilityai/stable-diffusion-2" repository.
2706
-
2707
- ```py
2708
- >>> from huggingface_hub import list_files_info
2709
- >>> [info.path for info in list_files_info("stabilityai/stable-diffusion-2", "vae") if info.lfs is not None]
2710
- ['vae/diffusion_pytorch_model.bin', 'vae/diffusion_pytorch_model.safetensors']
2711
- ```
2712
-
2713
- List all files on a repo.
2714
- ```py
2715
- >>> from huggingface_hub import list_files_info
2716
- >>> [info.path for info in list_files_info("glue", repo_type="dataset")]
2717
- ['.gitattributes', 'README.md', 'dataset_infos.json', 'glue.py']
2718
- ```
2719
- """
2720
- repo_type = repo_type or REPO_TYPE_MODEL
2721
- revision = quote(revision, safe="") if revision is not None else DEFAULT_REVISION
2722
- headers = self._build_hf_headers(token=token)
2723
-
2724
- folder_paths = []
2725
- if paths is None:
2726
- # `paths` is not provided => list all files from the repo
2727
- folder_paths.append("")
2728
- elif paths == []:
2729
- # corner case: server would return a 400 error if `paths` is an empty list. Let's return early.
2730
- return
2731
- else:
2732
- # `paths` is provided => get info about those
2733
- response = get_session().post(
2734
- f"{self.endpoint}/api/{repo_type}s/{repo_id}/paths-info/{revision}",
2735
- data={
2736
- "paths": paths if isinstance(paths, list) else [paths],
2737
- "expand": expand,
2738
- },
2739
- headers=headers,
2740
- )
2741
- hf_raise_for_status(response)
2742
- paths_info = response.json()
2743
-
2744
- # List top-level files first
2745
- for path_info in paths_info:
2746
- if path_info["type"] == "file":
2747
- yield RepoFile(**path_info)
2748
- else:
2749
- folder_paths.append(path_info["path"])
2750
-
2751
- # List files in subdirectories
2752
- for path in folder_paths:
2753
- encoded_path = "/" + quote(path, safe="") if path else ""
2754
- tree_url = f"{self.endpoint}/api/{repo_type}s/{repo_id}/tree/{revision}{encoded_path}"
2755
- for subpath_info in paginate(path=tree_url, headers=headers, params={"recursive": True, "expand": expand}):
2756
- if subpath_info["type"] == "file":
2757
- yield RepoFile(**subpath_info)
2758
-
2759
2648
  @validate_hf_hub_args
2760
2649
  def list_repo_files(
2761
2650
  self,
@@ -2763,7 +2652,7 @@ class HfApi:
2763
2652
  *,
2764
2653
  revision: Optional[str] = None,
2765
2654
  repo_type: Optional[str] = None,
2766
- token: Optional[Union[bool, str]] = None,
2655
+ token: Union[str, bool, None] = None,
2767
2656
  ) -> List[str]:
2768
2657
  """
2769
2658
  Get the list of files in a given repo.
@@ -2776,10 +2665,11 @@ class HfApi:
2776
2665
  repo_type (`str`, *optional*):
2777
2666
  Set to `"dataset"` or `"space"` if uploading to a dataset or space, `None` or `"model"` if uploading to
2778
2667
  a model. Default is `None`.
2779
- token (`bool` or `str`, *optional*):
2780
- A valid authentication token (see https://huggingface.co/settings/token). If `None` or `True` and
2781
- machine is logged in (through `huggingface-cli login` or [`~huggingface_hub.login`]), token will be
2782
- retrieved from the cache. If `False`, token is not sent in the request header.
2668
+ token (Union[bool, str, None], optional):
2669
+ A valid user access token (string). Defaults to the locally saved
2670
+ token, which is the recommended method for authentication (see
2671
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
2672
+ To disable authentication, pass `False`.
2783
2673
 
2784
2674
  Returns:
2785
2675
  `List[str]`: the list of files in a given repository.
@@ -2802,7 +2692,7 @@ class HfApi:
2802
2692
  expand: bool = False,
2803
2693
  revision: Optional[str] = None,
2804
2694
  repo_type: Optional[str] = None,
2805
- token: Optional[Union[bool, str]] = None,
2695
+ token: Union[str, bool, None] = None,
2806
2696
  ) -> Iterable[Union[RepoFile, RepoFolder]]:
2807
2697
  """
2808
2698
  List a repo tree's files and folders and get information about them.
@@ -2825,10 +2715,11 @@ class HfApi:
2825
2715
  repo_type (`str`, *optional*):
2826
2716
  The type of the repository from which to get the tree (`"model"`, `"dataset"` or `"space"`.
2827
2717
  Defaults to `"model"`.
2828
- token (`bool` or `str`, *optional*):
2829
- A valid authentication token (see https://huggingface.co/settings/token). If `None` or `True` and
2830
- machine is logged in (through `huggingface-cli login` or [`~huggingface_hub.login`]), token will be
2831
- retrieved from the cache. If `False`, token is not sent in the request header.
2718
+ token (Union[bool, str, None], optional):
2719
+ A valid user access token (string). Defaults to the locally saved
2720
+ token, which is the recommended method for authentication (see
2721
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
2722
+ To disable authentication, pass `False`.
2832
2723
 
2833
2724
  Returns:
2834
2725
  `Iterable[Union[RepoFile, RepoFolder]]`:
@@ -2930,7 +2821,7 @@ class HfApi:
2930
2821
  *,
2931
2822
  repo_type: Optional[str] = None,
2932
2823
  include_pull_requests: bool = False,
2933
- token: Optional[Union[bool, str]] = None,
2824
+ token: Union[str, bool, None] = None,
2934
2825
  ) -> GitRefs:
2935
2826
  """
2936
2827
  Get the list of refs of a given repo (both tags and branches).
@@ -2944,11 +2835,11 @@ class HfApi:
2944
2835
  `None` or `"model"` if listing from a model. Default is `None`.
2945
2836
  include_pull_requests (`bool`, *optional*):
2946
2837
  Whether to include refs from pull requests in the list. Defaults to `False`.
2947
- token (`bool` or `str`, *optional*):
2948
- A valid authentication token (see https://huggingface.co/settings/token).
2949
- If `None` or `True` and machine is logged in (through `huggingface-cli login`
2950
- or [`~huggingface_hub.login`]), token will be retrieved from the cache.
2951
- If `False`, token is not sent in the request header.
2838
+ token (Union[bool, str, None], optional):
2839
+ A valid user access token (string). Defaults to the locally saved
2840
+ token, which is the recommended method for authentication (see
2841
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
2842
+ To disable authentication, pass `False`.
2952
2843
 
2953
2844
  Example:
2954
2845
  ```py
@@ -3001,7 +2892,7 @@ class HfApi:
3001
2892
  repo_id: str,
3002
2893
  *,
3003
2894
  repo_type: Optional[str] = None,
3004
- token: Optional[Union[bool, str]] = None,
2895
+ token: Union[bool, str, None] = None,
3005
2896
  revision: Optional[str] = None,
3006
2897
  formatted: bool = False,
3007
2898
  ) -> List[GitCommitInfo]:
@@ -3016,11 +2907,11 @@ class HfApi:
3016
2907
  repo_type (`str`, *optional*):
3017
2908
  Set to `"dataset"` or `"space"` if listing commits from a dataset or a Space, `None` or `"model"` if
3018
2909
  listing from a model. Default is `None`.
3019
- token (`bool` or `str`, *optional*):
3020
- A valid authentication token (see https://huggingface.co/settings/token).
3021
- If `None` or `True` and machine is logged in (through `huggingface-cli login`
3022
- or [`~huggingface_hub.login`]), token will be retrieved from the cache.
3023
- If `False`, token is not sent in the request header.
2910
+ token (Union[bool, str, None], optional):
2911
+ A valid user access token (string). Defaults to the locally saved
2912
+ token, which is the recommended method for authentication (see
2913
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
2914
+ To disable authentication, pass `False`.
3024
2915
  revision (`str`, *optional*):
3025
2916
  The git revision to commit from. Defaults to the head of the `"main"` branch.
3026
2917
  formatted (`bool`):
@@ -3090,7 +2981,7 @@ class HfApi:
3090
2981
  expand: bool = False,
3091
2982
  revision: Optional[str] = None,
3092
2983
  repo_type: Optional[str] = None,
3093
- token: Optional[Union[bool, str]] = None,
2984
+ token: Union[str, bool, None] = None,
3094
2985
  ) -> List[Union[RepoFile, RepoFolder]]:
3095
2986
  """
3096
2987
  Get information about a repo's paths.
@@ -3111,10 +3002,11 @@ class HfApi:
3111
3002
  repo_type (`str`, *optional*):
3112
3003
  The type of the repository from which to get the information (`"model"`, `"dataset"` or `"space"`.
3113
3004
  Defaults to `"model"`.
3114
- token (`bool` or `str`, *optional*):
3115
- A valid authentication token (see https://huggingface.co/settings/token). If `None` or `True` and
3116
- machine is logged in (through `huggingface-cli login` or [`~huggingface_hub.login`]), token will be
3117
- retrieved from the cache. If `False`, token is not sent in the request header.
3005
+ token (Union[bool, str, None], optional):
3006
+ A valid user access token (string). Defaults to the locally saved
3007
+ token, which is the recommended method for authentication (see
3008
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
3009
+ To disable authentication, pass `False`.
3118
3010
 
3119
3011
  Returns:
3120
3012
  `List[Union[RepoFile, RepoFolder]]`:
@@ -3165,7 +3057,7 @@ class HfApi:
3165
3057
  branch: Optional[str] = None,
3166
3058
  commit_message: Optional[str] = None,
3167
3059
  repo_type: Optional[str] = None,
3168
- token: Optional[str] = None,
3060
+ token: Union[str, bool, None] = None,
3169
3061
  ) -> None:
3170
3062
  """Squash commit history on a branch for a repo on the Hub.
3171
3063
 
@@ -3195,10 +3087,11 @@ class HfApi:
3195
3087
  repo_type (`str`, *optional*):
3196
3088
  Set to `"dataset"` or `"space"` if listing commits from a dataset or a Space, `None` or `"model"` if
3197
3089
  listing from a model. Default is `None`.
3198
- token (`str`, *optional*):
3199
- A valid authentication token (see https://huggingface.co/settings/token). If the machine is logged in
3200
- (through `huggingface-cli login` or [`~huggingface_hub.login`]), token can be automatically retrieved
3201
- from the cache.
3090
+ token (Union[bool, str, None], optional):
3091
+ A valid user access token (string). Defaults to the locally saved
3092
+ token, which is the recommended method for authentication (see
3093
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
3094
+ To disable authentication, pass `False`.
3202
3095
 
3203
3096
  Raises:
3204
3097
  [`~utils.RepositoryNotFoundError`]:
@@ -3247,7 +3140,7 @@ class HfApi:
3247
3140
  self,
3248
3141
  repo_id: str,
3249
3142
  *,
3250
- token: Optional[str] = None,
3143
+ token: Union[str, bool, None] = None,
3251
3144
  private: bool = False,
3252
3145
  repo_type: Optional[str] = None,
3253
3146
  exist_ok: bool = False,
@@ -3264,8 +3157,11 @@ class HfApi:
3264
3157
  repo_id (`str`):
3265
3158
  A namespace (user or an organization) and a repo name separated
3266
3159
  by a `/`.
3267
- token (`str`, *optional*):
3268
- An authentication token (See https://huggingface.co/settings/token)
3160
+ token (Union[bool, str, None], optional):
3161
+ A valid user access token (string). Defaults to the locally saved
3162
+ token, which is the recommended method for authentication (see
3163
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
3164
+ To disable authentication, pass `False`.
3269
3165
  private (`bool`, *optional*, defaults to `False`):
3270
3166
  Whether the model repo should be private.
3271
3167
  repo_type (`str`, *optional*):
@@ -3370,7 +3266,7 @@ class HfApi:
3370
3266
  return RepoUrl(f"{self.endpoint}/{repo_id}")
3371
3267
  return RepoUrl(f"{self.endpoint}/{repo_type}/{repo_id}")
3372
3268
  except HfHubHTTPError:
3373
- raise
3269
+ raise err
3374
3270
  else:
3375
3271
  raise
3376
3272
 
@@ -3382,7 +3278,7 @@ class HfApi:
3382
3278
  self,
3383
3279
  repo_id: str,
3384
3280
  *,
3385
- token: Optional[str] = None,
3281
+ token: Union[str, bool, None] = None,
3386
3282
  repo_type: Optional[str] = None,
3387
3283
  missing_ok: bool = False,
3388
3284
  ) -> None:
@@ -3393,8 +3289,11 @@ class HfApi:
3393
3289
  repo_id (`str`):
3394
3290
  A namespace (user or an organization) and a repo name separated
3395
3291
  by a `/`.
3396
- token (`str`, *optional*):
3397
- An authentication token (See https://huggingface.co/settings/token)
3292
+ token (Union[bool, str, None], optional):
3293
+ A valid user access token (string). Defaults to the locally saved
3294
+ token, which is the recommended method for authentication (see
3295
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
3296
+ To disable authentication, pass `False`.
3398
3297
  repo_type (`str`, *optional*):
3399
3298
  Set to `"dataset"` or `"space"` if uploading to a dataset or
3400
3299
  space, `None` or `"model"` if uploading to a model.
@@ -3433,7 +3332,7 @@ class HfApi:
3433
3332
  repo_id: str,
3434
3333
  private: bool = False,
3435
3334
  *,
3436
- token: Optional[str] = None,
3335
+ token: Union[str, bool, None] = None,
3437
3336
  organization: Optional[str] = None,
3438
3337
  repo_type: Optional[str] = None,
3439
3338
  name: Optional[str] = None,
@@ -3446,8 +3345,11 @@ class HfApi:
3446
3345
  by a `/`.
3447
3346
  private (`bool`, *optional*, defaults to `False`):
3448
3347
  Whether the model repo should be private.
3449
- token (`str`, *optional*):
3450
- An authentication token (See https://huggingface.co/settings/token)
3348
+ token (Union[bool, str, None], optional):
3349
+ A valid user access token (string). Defaults to the locally saved
3350
+ token, which is the recommended method for authentication (see
3351
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
3352
+ To disable authentication, pass `False`.
3451
3353
  repo_type (`str`, *optional*):
3452
3354
  Set to `"dataset"` or `"space"` if uploading to a dataset or
3453
3355
  space, `None` or `"model"` if uploading to a model. Default is
@@ -3493,7 +3395,7 @@ class HfApi:
3493
3395
  to_id: str,
3494
3396
  *,
3495
3397
  repo_type: Optional[str] = None,
3496
- token: Optional[str] = None,
3398
+ token: Union[str, bool, None] = None,
3497
3399
  ):
3498
3400
  """
3499
3401
  Moving a repository from namespace1/repo_name1 to namespace2/repo_name2
@@ -3513,8 +3415,11 @@ class HfApi:
3513
3415
  Set to `"dataset"` or `"space"` if uploading to a dataset or
3514
3416
  space, `None` or `"model"` if uploading to a model. Default is
3515
3417
  `None`.
3516
- token (`str`, *optional*):
3517
- An authentication token (See https://huggingface.co/settings/token)
3418
+ token (Union[bool, str, None], optional):
3419
+ A valid user access token (string). Defaults to the locally saved
3420
+ token, which is the recommended method for authentication (see
3421
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
3422
+ To disable authentication, pass `False`.
3518
3423
 
3519
3424
  <Tip>
3520
3425
 
@@ -3557,7 +3462,7 @@ class HfApi:
3557
3462
  *,
3558
3463
  commit_message: str,
3559
3464
  commit_description: Optional[str] = None,
3560
- token: Optional[str] = None,
3465
+ token: Union[str, bool, None] = None,
3561
3466
  repo_type: Optional[str] = None,
3562
3467
  revision: Optional[str] = None,
3563
3468
  create_pr: Optional[bool] = None,
@@ -3574,7 +3479,7 @@ class HfApi:
3574
3479
  *,
3575
3480
  commit_message: str,
3576
3481
  commit_description: Optional[str] = None,
3577
- token: Optional[str] = None,
3482
+ token: Union[str, bool, None] = None,
3578
3483
  repo_type: Optional[str] = None,
3579
3484
  revision: Optional[str] = None,
3580
3485
  create_pr: Optional[bool] = None,
@@ -3592,7 +3497,7 @@ class HfApi:
3592
3497
  *,
3593
3498
  commit_message: str,
3594
3499
  commit_description: Optional[str] = None,
3595
- token: Optional[str] = None,
3500
+ token: Union[str, bool, None] = None,
3596
3501
  repo_type: Optional[str] = None,
3597
3502
  revision: Optional[str] = None,
3598
3503
  create_pr: Optional[bool] = None,
@@ -3646,9 +3551,11 @@ class HfApi:
3646
3551
  commit_description (`str`, *optional*):
3647
3552
  The description of the commit that will be created
3648
3553
 
3649
- token (`str`, *optional*):
3650
- Authentication token, obtained with `HfApi.login` method. Will
3651
- default to the stored token.
3554
+ token (Union[bool, str, None], optional):
3555
+ A valid user access token (string). Defaults to the locally saved
3556
+ token, which is the recommended method for authentication (see
3557
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
3558
+ To disable authentication, pass `False`.
3652
3559
 
3653
3560
  repo_type (`str`, *optional*):
3654
3561
  Set to `"dataset"` or `"space"` if uploading to a dataset or
@@ -3844,7 +3751,7 @@ class HfApi:
3844
3751
  deletion_commits: List[List[CommitOperationDelete]],
3845
3752
  commit_message: str,
3846
3753
  commit_description: Optional[str] = None,
3847
- token: Optional[str] = None,
3754
+ token: Union[str, bool, None] = None,
3848
3755
  repo_type: Optional[str] = None,
3849
3756
  merge_pr: bool = True,
3850
3757
  num_threads: int = 5, # TODO: use to multithread uploads
@@ -3892,8 +3799,11 @@ class HfApi:
3892
3799
  commit_description (`str`, *optional*):
3893
3800
  The description of the commit that will be created. The description will be added to the PR.
3894
3801
 
3895
- token (`str`, *optional*):
3896
- Authentication token, obtained with `HfApi.login` method. Will default to the stored token.
3802
+ token (Union[bool, str, None], optional):
3803
+ A valid user access token (string). Defaults to the locally saved
3804
+ token, which is the recommended method for authentication (see
3805
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
3806
+ To disable authentication, pass `False`.
3897
3807
 
3898
3808
  repo_type (`str`, *optional*):
3899
3809
  Set to `"dataset"` or `"space"` if uploading to a dataset or space, `None` or `"model"` if uploading to
@@ -4139,7 +4049,7 @@ class HfApi:
4139
4049
  repo_id: str,
4140
4050
  additions: Iterable[CommitOperationAdd],
4141
4051
  *,
4142
- token: Optional[str] = None,
4052
+ token: Union[str, bool, None] = None,
4143
4053
  repo_type: Optional[str] = None,
4144
4054
  revision: Optional[str] = None,
4145
4055
  create_pr: Optional[bool] = None,
@@ -4176,8 +4086,11 @@ class HfApi:
4176
4086
  The list of files to upload. Warning: the objects in this list will be mutated to include information
4177
4087
  relative to the upload. Do not reuse the same objects for multiple commits.
4178
4088
 
4179
- token (`str`, *optional*):
4180
- Authentication token. Will default to the stored token.
4089
+ token (Union[bool, str, None], optional):
4090
+ A valid user access token (string). Defaults to the locally saved
4091
+ token, which is the recommended method for authentication (see
4092
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
4093
+ To disable authentication, pass `False`.
4181
4094
 
4182
4095
  repo_type (`str`, *optional*):
4183
4096
  The type of repository to upload to (e.g. `"model"` -default-, `"dataset"` or `"space"`).
@@ -4292,7 +4205,7 @@ class HfApi:
4292
4205
  path_or_fileobj: Union[str, Path, bytes, BinaryIO],
4293
4206
  path_in_repo: str,
4294
4207
  repo_id: str,
4295
- token: Optional[str] = None,
4208
+ token: Union[str, bool, None] = None,
4296
4209
  repo_type: Optional[str] = None,
4297
4210
  revision: Optional[str] = None,
4298
4211
  commit_message: Optional[str] = None,
@@ -4309,7 +4222,7 @@ class HfApi:
4309
4222
  path_or_fileobj: Union[str, Path, bytes, BinaryIO],
4310
4223
  path_in_repo: str,
4311
4224
  repo_id: str,
4312
- token: Optional[str] = None,
4225
+ token: Union[str, bool, None] = None,
4313
4226
  repo_type: Optional[str] = None,
4314
4227
  revision: Optional[str] = None,
4315
4228
  commit_message: Optional[str] = None,
@@ -4327,7 +4240,7 @@ class HfApi:
4327
4240
  path_or_fileobj: Union[str, Path, bytes, BinaryIO],
4328
4241
  path_in_repo: str,
4329
4242
  repo_id: str,
4330
- token: Optional[str] = None,
4243
+ token: Union[str, bool, None] = None,
4331
4244
  repo_type: Optional[str] = None,
4332
4245
  revision: Optional[str] = None,
4333
4246
  commit_message: Optional[str] = None,
@@ -4351,9 +4264,11 @@ class HfApi:
4351
4264
  repo_id (`str`):
4352
4265
  The repository to which the file will be uploaded, for example:
4353
4266
  `"username/custom_transformers"`
4354
- token (`str`, *optional*):
4355
- Authentication token, obtained with `HfApi.login` method. Will
4356
- default to the stored token.
4267
+ token (Union[bool, str, None], optional):
4268
+ A valid user access token (string). Defaults to the locally saved
4269
+ token, which is the recommended method for authentication (see
4270
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
4271
+ To disable authentication, pass `False`.
4357
4272
  repo_type (`str`, *optional*):
4358
4273
  Set to `"dataset"` or `"space"` if uploading to a dataset or
4359
4274
  space, `None` or `"model"` if uploading to a model. Default is
@@ -4494,7 +4409,7 @@ class HfApi:
4494
4409
  path_in_repo: Optional[str] = None,
4495
4410
  commit_message: Optional[str] = None,
4496
4411
  commit_description: Optional[str] = None,
4497
- token: Optional[str] = None,
4412
+ token: Union[str, bool, None] = None,
4498
4413
  repo_type: Optional[str] = None,
4499
4414
  revision: Optional[str] = None,
4500
4415
  create_pr: Optional[bool] = None,
@@ -4516,7 +4431,7 @@ class HfApi:
4516
4431
  path_in_repo: Optional[str] = None,
4517
4432
  commit_message: Optional[str] = None,
4518
4433
  commit_description: Optional[str] = None,
4519
- token: Optional[str] = None,
4434
+ token: Union[str, bool, None] = None,
4520
4435
  repo_type: Optional[str] = None,
4521
4436
  revision: Optional[str] = None,
4522
4437
  create_pr: Optional[bool] = None,
@@ -4539,7 +4454,7 @@ class HfApi:
4539
4454
  path_in_repo: Optional[str] = None,
4540
4455
  commit_message: Optional[str] = None,
4541
4456
  commit_description: Optional[str] = None,
4542
- token: Optional[str] = None,
4457
+ token: Union[str, bool, None] = None,
4543
4458
  repo_type: Optional[str] = None,
4544
4459
  revision: Optional[str] = None,
4545
4460
  create_pr: Optional[bool] = None,
@@ -4561,7 +4476,7 @@ class HfApi:
4561
4476
  path_in_repo: Optional[str] = None,
4562
4477
  commit_message: Optional[str] = None,
4563
4478
  commit_description: Optional[str] = None,
4564
- token: Optional[str] = None,
4479
+ token: Union[str, bool, None] = None,
4565
4480
  repo_type: Optional[str] = None,
4566
4481
  revision: Optional[str] = None,
4567
4482
  create_pr: Optional[bool] = None,
@@ -4585,7 +4500,7 @@ class HfApi:
4585
4500
  path_in_repo: Optional[str] = None,
4586
4501
  commit_message: Optional[str] = None,
4587
4502
  commit_description: Optional[str] = None,
4588
- token: Optional[str] = None,
4503
+ token: Union[str, bool, None] = None,
4589
4504
  repo_type: Optional[str] = None,
4590
4505
  revision: Optional[str] = None,
4591
4506
  create_pr: Optional[bool] = None,
@@ -4629,9 +4544,11 @@ class HfApi:
4629
4544
  path_in_repo (`str`, *optional*):
4630
4545
  Relative path of the directory in the repo, for example:
4631
4546
  `"checkpoints/1fec34a/results"`. Will default to the root folder of the repository.
4632
- token (`str`, *optional*):
4633
- Authentication token, obtained with `HfApi.login` method. Will
4634
- default to the stored token.
4547
+ token (Union[bool, str, None], optional):
4548
+ A valid user access token (string). Defaults to the locally saved
4549
+ token, which is the recommended method for authentication (see
4550
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
4551
+ To disable authentication, pass `False`.
4635
4552
  repo_type (`str`, *optional*):
4636
4553
  Set to `"dataset"` or `"space"` if uploading to a dataset or
4637
4554
  space, `None` or `"model"` if uploading to a model. Default is
@@ -4761,7 +4678,7 @@ class HfApi:
4761
4678
  ignore_patterns = []
4762
4679
  elif isinstance(ignore_patterns, str):
4763
4680
  ignore_patterns = [ignore_patterns]
4764
- ignore_patterns += IGNORE_GIT_FOLDER_PATTERNS
4681
+ ignore_patterns += DEFAULT_IGNORE_PATTERNS
4765
4682
 
4766
4683
  delete_operations = self._prepare_upload_folder_deletions(
4767
4684
  repo_id=repo_id,
@@ -4840,7 +4757,7 @@ class HfApi:
4840
4757
  path_in_repo: str,
4841
4758
  repo_id: str,
4842
4759
  *,
4843
- token: Optional[str] = None,
4760
+ token: Union[str, bool, None] = None,
4844
4761
  repo_type: Optional[str] = None,
4845
4762
  revision: Optional[str] = None,
4846
4763
  commit_message: Optional[str] = None,
@@ -4858,9 +4775,11 @@ class HfApi:
4858
4775
  repo_id (`str`):
4859
4776
  The repository from which the file will be deleted, for example:
4860
4777
  `"username/custom_transformers"`
4861
- token (`str`, *optional*):
4862
- Authentication token, obtained with `HfApi.login` method. Will
4863
- default to the stored token.
4778
+ token (Union[bool, str, None], optional):
4779
+ A valid user access token (string). Defaults to the locally saved
4780
+ token, which is the recommended method for authentication (see
4781
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
4782
+ To disable authentication, pass `False`.
4864
4783
  repo_type (`str`, *optional*):
4865
4784
  Set to `"dataset"` or `"space"` if the file is in a dataset or
4866
4785
  space, `None` or `"model"` if in a model. Default is `None`.
@@ -4928,7 +4847,7 @@ class HfApi:
4928
4847
  path_in_repo: str,
4929
4848
  repo_id: str,
4930
4849
  *,
4931
- token: Optional[str] = None,
4850
+ token: Union[bool, str, None] = None,
4932
4851
  repo_type: Optional[str] = None,
4933
4852
  revision: Optional[str] = None,
4934
4853
  commit_message: Optional[str] = None,
@@ -4947,8 +4866,11 @@ class HfApi:
4947
4866
  repo_id (`str`):
4948
4867
  The repository from which the folder will be deleted, for example:
4949
4868
  `"username/custom_transformers"`
4950
- token (`str`, *optional*):
4951
- Authentication token, obtained with `HfApi.login` method. Will default
4869
+ token (Union[bool, str, None], optional):
4870
+ A valid user access token (string). Defaults to the locally saved
4871
+ token, which is the recommended method for authentication (see
4872
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
4873
+ To disable authentication, pass `False`.
4952
4874
  to the stored token.
4953
4875
  repo_type (`str`, *optional*):
4954
4876
  Set to `"dataset"` or `"space"` if the folder is in a dataset or
@@ -5001,12 +4923,11 @@ class HfApi:
5001
4923
  Args:
5002
4924
  url (`str`):
5003
4925
  File url, for example returned by [`hf_hub_url`].
5004
- token (`str` or `bool`, *optional*):
5005
- A token to be used for the download.
5006
- - If `True`, the token is read from the HuggingFace config
5007
- folder.
5008
- - If `False` or `None`, no token is provided.
5009
- - If a string, it's used as the authentication token.
4926
+ token (Union[bool, str, None], optional):
4927
+ A valid user access token (string). Defaults to the locally saved
4928
+ token, which is the recommended method for authentication (see
4929
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
4930
+ To disable authentication, pass `False`.
5010
4931
  proxies (`dict`, *optional*):
5011
4932
  Dictionary mapping protocol to the URL of the proxy passed to `requests.request`.
5012
4933
  timeout (`float`, *optional*, defaults to 10):
@@ -5040,15 +4961,16 @@ class HfApi:
5040
4961
  revision: Optional[str] = None,
5041
4962
  cache_dir: Union[str, Path, None] = None,
5042
4963
  local_dir: Union[str, Path, None] = None,
5043
- local_dir_use_symlinks: Union[bool, Literal["auto"]] = "auto",
5044
4964
  force_download: bool = False,
5045
- force_filename: Optional[str] = None,
5046
4965
  proxies: Optional[Dict] = None,
5047
4966
  etag_timeout: float = DEFAULT_ETAG_TIMEOUT,
5048
- resume_download: bool = False,
5049
- token: Optional[Union[str, bool]] = None,
4967
+ token: Union[bool, str, None] = None,
5050
4968
  local_files_only: bool = False,
4969
+ # Deprecated args
4970
+ resume_download: Optional[bool] = None,
5051
4971
  legacy_cache_layout: bool = False,
4972
+ force_filename: Optional[str] = None,
4973
+ local_dir_use_symlinks: Union[bool, Literal["auto"]] = "auto",
5052
4974
  ) -> str:
5053
4975
  """Download a given file if it's not already present in the local cache.
5054
4976
 
@@ -5062,21 +4984,6 @@ class HfApi:
5062
4984
  that have been resolved at that particular commit. Each filename is a symlink to the blob
5063
4985
  at that particular commit.
5064
4986
 
5065
- If `local_dir` is provided, the file structure from the repo will be replicated in this location. You can configure
5066
- how you want to move those files:
5067
- - If `local_dir_use_symlinks="auto"` (default), files are downloaded and stored in the cache directory as blob
5068
- files. Small files (<5MB) are duplicated in `local_dir` while a symlink is created for bigger files. The goal
5069
- is to be able to manually edit and save small files without corrupting the cache while saving disk space for
5070
- binary files. The 5MB threshold can be configured with the `HF_HUB_LOCAL_DIR_AUTO_SYMLINK_THRESHOLD`
5071
- environment variable.
5072
- - If `local_dir_use_symlinks=True`, files are downloaded, stored in the cache directory and symlinked in `local_dir`.
5073
- This is optimal in term of disk usage but files must not be manually edited.
5074
- - If `local_dir_use_symlinks=False` and the blob files exist in the cache directory, they are duplicated in the
5075
- local dir. This means disk usage is not optimized.
5076
- - Finally, if `local_dir_use_symlinks=False` and the blob files do not exist in the cache directory, then the
5077
- files are downloaded and directly placed under `local_dir`. This means if you need to download them again later,
5078
- they will be re-downloaded entirely.
5079
-
5080
4987
  ```
5081
4988
  [ 96] .
5082
4989
  └── [ 160] models--julien-c--EsperBERTo-small
@@ -5095,6 +5002,11 @@ class HfApi:
5095
5002
  └── [ 76] pytorch_model.bin -> ../../blobs/403450e234d65943a7dcf7e05a771ce3c92faa84dd07db4ac20f592037a1e4bd
5096
5003
  ```
5097
5004
 
5005
+ If `local_dir` is provided, the file structure from the repo will be replicated in this location. When using this
5006
+ option, the `cache_dir` will not be used and a `.huggingface/` folder will be created at the root of `local_dir`
5007
+ to store some metadata related to the downloaded files. While this mechanism is not as robust as the main
5008
+ cache-system, it's optimized for regularly pulling the latest version of a repository.
5009
+
5098
5010
  Args:
5099
5011
  repo_id (`str`):
5100
5012
  A user or an organization name and a repo name separated by a `/`.
@@ -5111,13 +5023,7 @@ class HfApi:
5111
5023
  cache_dir (`str`, `Path`, *optional*):
5112
5024
  Path to the folder where cached files are stored.
5113
5025
  local_dir (`str` or `Path`, *optional*):
5114
- If provided, the downloaded file will be placed under this directory, either as a symlink (default) or
5115
- a regular file (see description for more details).
5116
- local_dir_use_symlinks (`"auto"` or `bool`, defaults to `"auto"`):
5117
- To be used with `local_dir`. If set to "auto", the cache directory will be used and the file will be either
5118
- duplicated or symlinked to the local directory depending on its size. It set to `True`, a symlink will be
5119
- created, no matter the file size. If set to `False`, the file will either be duplicated from cache (if
5120
- already exists) or downloaded from the Hub and not cached. See description for more details.
5026
+ If provided, the downloaded file will be placed under this directory.
5121
5027
  force_download (`bool`, *optional*, defaults to `False`):
5122
5028
  Whether the file should be downloaded even if it already exists in
5123
5029
  the local cache.
@@ -5127,29 +5033,19 @@ class HfApi:
5127
5033
  etag_timeout (`float`, *optional*, defaults to `10`):
5128
5034
  When fetching ETag, how many seconds to wait for the server to send
5129
5035
  data before giving up which is passed to `requests.request`.
5130
- resume_download (`bool`, *optional*, defaults to `False`):
5131
- If `True`, resume a previously interrupted download.
5132
- token (`bool` or `str`, *optional*):
5133
- A valid authentication token (see https://huggingface.co/settings/token).
5134
- If `None` or `True` and machine is logged in (through `huggingface-cli login`
5135
- or [`~huggingface_hub.login`]), token will be retrieved from the cache.
5136
- If `False`, token is not sent in the request header.
5036
+ token (Union[bool, str, None], optional):
5037
+ A valid user access token (string). Defaults to the locally saved
5038
+ token, which is the recommended method for authentication (see
5039
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
5040
+ To disable authentication, pass `False`.
5137
5041
  local_files_only (`bool`, *optional*, defaults to `False`):
5138
5042
  If `True`, avoid downloading the file and return the path to the
5139
5043
  local cached file if it exists.
5140
- legacy_cache_layout (`bool`, *optional*, defaults to `False`):
5141
- If `True`, uses the legacy file cache layout i.e. just call [`hf_hub_url`]
5142
- then `cached_download`. This is deprecated as the new cache layout is
5143
- more powerful.
5144
5044
 
5145
5045
  Returns:
5146
- Local path (string) of file or if networking is off, last version of
5147
- file cached on disk.
5148
-
5149
- <Tip>
5150
-
5151
- Raises the following errors:
5046
+ `str`: Local path of file or if networking is off, last version of file cached on disk.
5152
5047
 
5048
+ Raises:
5153
5049
  - [`EnvironmentError`](https://docs.python.org/3/library/exceptions.html#EnvironmentError)
5154
5050
  if `token=True` and the token cannot be found.
5155
5051
  - [`OSError`](https://docs.python.org/3/library/exceptions.html#OSError)
@@ -5165,8 +5061,6 @@ class HfApi:
5165
5061
  If the file to download cannot be found.
5166
5062
  - [`~utils.LocalEntryNotFoundError`]
5167
5063
  If network is disabled or unavailable and file is not found in cache.
5168
-
5169
- </Tip>
5170
5064
  """
5171
5065
  from .file_download import hf_hub_download
5172
5066
 
@@ -5207,17 +5101,18 @@ class HfApi:
5207
5101
  revision: Optional[str] = None,
5208
5102
  cache_dir: Union[str, Path, None] = None,
5209
5103
  local_dir: Union[str, Path, None] = None,
5210
- local_dir_use_symlinks: Union[bool, Literal["auto"]] = "auto",
5211
5104
  proxies: Optional[Dict] = None,
5212
5105
  etag_timeout: float = DEFAULT_ETAG_TIMEOUT,
5213
- resume_download: bool = False,
5214
5106
  force_download: bool = False,
5215
- token: Optional[Union[str, bool]] = None,
5107
+ token: Union[bool, str, None] = None,
5216
5108
  local_files_only: bool = False,
5217
5109
  allow_patterns: Optional[Union[List[str], str]] = None,
5218
5110
  ignore_patterns: Optional[Union[List[str], str]] = None,
5219
5111
  max_workers: int = 8,
5220
5112
  tqdm_class: Optional[base_tqdm] = None,
5113
+ # Deprecated args
5114
+ local_dir_use_symlinks: Union[bool, Literal["auto"]] = "auto",
5115
+ resume_download: Optional[bool] = None,
5221
5116
  ) -> str:
5222
5117
  """Download repo files.
5223
5118
 
@@ -5226,20 +5121,10 @@ class HfApi:
5226
5121
  to keep their actual filename relative to that folder. You can also filter which files to download using
5227
5122
  `allow_patterns` and `ignore_patterns`.
5228
5123
 
5229
- If `local_dir` is provided, the file structure from the repo will be replicated in this location. You can configure
5230
- how you want to move those files:
5231
- - If `local_dir_use_symlinks="auto"` (default), files are downloaded and stored in the cache directory as blob
5232
- files. Small files (<5MB) are duplicated in `local_dir` while a symlink is created for bigger files. The goal
5233
- is to be able to manually edit and save small files without corrupting the cache while saving disk space for
5234
- binary files. The 5MB threshold can be configured with the `HF_HUB_LOCAL_DIR_AUTO_SYMLINK_THRESHOLD`
5235
- environment variable.
5236
- - If `local_dir_use_symlinks=True`, files are downloaded, stored in the cache directory and symlinked in `local_dir`.
5237
- This is optimal in term of disk usage but files must not be manually edited.
5238
- - If `local_dir_use_symlinks=False` and the blob files exist in the cache directory, they are duplicated in the
5239
- local dir. This means disk usage is not optimized.
5240
- - Finally, if `local_dir_use_symlinks=False` and the blob files do not exist in the cache directory, then the
5241
- files are downloaded and directly placed under `local_dir`. This means if you need to download them again later,
5242
- they will be re-downloaded entirely.
5124
+ If `local_dir` is provided, the file structure from the repo will be replicated in this location. When using this
5125
+ option, the `cache_dir` will not be used and a `.huggingface/` folder will be created at the root of `local_dir`
5126
+ to store some metadata related to the downloaded files.While this mechanism is not as robust as the main
5127
+ cache-system, it's optimized for regularly pulling the latest version of a repository.
5243
5128
 
5244
5129
  An alternative would be to clone the repo but this requires git and git-lfs to be installed and properly
5245
5130
  configured. It is also not possible to filter which files to download when cloning a repository using git.
@@ -5256,28 +5141,20 @@ class HfApi:
5256
5141
  cache_dir (`str`, `Path`, *optional*):
5257
5142
  Path to the folder where cached files are stored.
5258
5143
  local_dir (`str` or `Path`, *optional*):
5259
- If provided, the downloaded files will be placed under this directory, either as symlinks (default) or
5260
- regular files (see description for more details).
5261
- local_dir_use_symlinks (`"auto"` or `bool`, defaults to `"auto"`):
5262
- To be used with `local_dir`. If set to "auto", the cache directory will be used and the file will be either
5263
- duplicated or symlinked to the local directory depending on its size. It set to `True`, a symlink will be
5264
- created, no matter the file size. If set to `False`, the file will either be duplicated from cache (if
5265
- already exists) or downloaded from the Hub and not cached. See description for more details.
5144
+ If provided, the downloaded files will be placed under this directory.
5266
5145
  proxies (`dict`, *optional*):
5267
5146
  Dictionary mapping protocol to the URL of the proxy passed to
5268
5147
  `requests.request`.
5269
5148
  etag_timeout (`float`, *optional*, defaults to `10`):
5270
5149
  When fetching ETag, how many seconds to wait for the server to send
5271
5150
  data before giving up which is passed to `requests.request`.
5272
- resume_download (`bool`, *optional*, defaults to `False):
5273
- If `True`, resume a previously interrupted download.
5274
5151
  force_download (`bool`, *optional*, defaults to `False`):
5275
5152
  Whether the file should be downloaded even if it already exists in the local cache.
5276
- token (`bool` or `str`, *optional*):
5277
- A valid authentication token (see https://huggingface.co/settings/token).
5278
- If `None` or `True` and machine is logged in (through `huggingface-cli login`
5279
- or [`~huggingface_hub.login`]), token will be retrieved from the cache.
5280
- If `False`, token is not sent in the request header.
5153
+ token (Union[bool, str, None], optional):
5154
+ A valid user access token (string). Defaults to the locally saved
5155
+ token, which is the recommended method for authentication (see
5156
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
5157
+ To disable authentication, pass `False`.
5281
5158
  local_files_only (`bool`, *optional*, defaults to `False`):
5282
5159
  If `True`, avoid downloading the file and return the path to the
5283
5160
  local cached file if it exists.
@@ -5296,20 +5173,15 @@ class HfApi:
5296
5173
  `HF_HUB_DISABLE_PROGRESS_BARS` environment variable.
5297
5174
 
5298
5175
  Returns:
5299
- Local folder path (string) of repo snapshot
5300
-
5301
- <Tip>
5176
+ `str`: folder path of the repo snapshot.
5302
5177
 
5303
- Raises the following errors:
5304
-
5305
- - [`EnvironmentError`](https://docs.python.org/3/library/exceptions.html#EnvironmentError)
5306
- if `token=True` and the token cannot be found.
5307
- - [`OSError`](https://docs.python.org/3/library/exceptions.html#OSError) if
5308
- ETag cannot be determined.
5309
- - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
5310
- if some parameter value is invalid
5311
-
5312
- </Tip>
5178
+ Raises:
5179
+ - [`EnvironmentError`](https://docs.python.org/3/library/exceptions.html#EnvironmentError)
5180
+ if `token=True` and the token cannot be found.
5181
+ - [`OSError`](https://docs.python.org/3/library/exceptions.html#OSError) if
5182
+ ETag cannot be determined.
5183
+ - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
5184
+ if some parameter value is invalid
5313
5185
  """
5314
5186
  from ._snapshot_download import snapshot_download
5315
5187
 
@@ -5346,7 +5218,7 @@ class HfApi:
5346
5218
  *,
5347
5219
  repo_type: Optional[str] = None,
5348
5220
  revision: Optional[str] = None,
5349
- token: Optional[str] = None,
5221
+ token: Union[bool, str, None] = None,
5350
5222
  ) -> SafetensorsRepoMetadata:
5351
5223
  """
5352
5224
  Parse metadata for a safetensors repo on the Hub.
@@ -5370,10 +5242,11 @@ class HfApi:
5370
5242
  revision (`str`, *optional*):
5371
5243
  The git revision to fetch the file from. Can be a branch name, a tag, or a commit hash. Defaults to the
5372
5244
  head of the `"main"` branch.
5373
- token (`bool` or `str`, *optional*):
5374
- A valid authentication token (see https://huggingface.co/settings/token). If `None` or `True` and
5375
- machine is logged in (through `huggingface-cli login` or [`~huggingface_hub.login`]), token will be
5376
- retrieved from the cache. If `False`, token is not sent in the request header.
5245
+ token (Union[bool, str, None], optional):
5246
+ A valid user access token (string). Defaults to the locally saved
5247
+ token, which is the recommended method for authentication (see
5248
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
5249
+ To disable authentication, pass `False`.
5377
5250
 
5378
5251
  Returns:
5379
5252
  [`SafetensorsRepoMetadata`]: information related to safetensors repo.
@@ -5468,7 +5341,7 @@ class HfApi:
5468
5341
  *,
5469
5342
  repo_type: Optional[str] = None,
5470
5343
  revision: Optional[str] = None,
5471
- token: Optional[str] = None,
5344
+ token: Union[bool, str, None] = None,
5472
5345
  ) -> SafetensorsFileMetadata:
5473
5346
  """
5474
5347
  Parse metadata from a safetensors file on the Hub.
@@ -5488,10 +5361,11 @@ class HfApi:
5488
5361
  revision (`str`, *optional*):
5489
5362
  The git revision to fetch the file from. Can be a branch name, a tag, or a commit hash. Defaults to the
5490
5363
  head of the `"main"` branch.
5491
- token (`bool` or `str`, *optional*):
5492
- A valid authentication token (see https://huggingface.co/settings/token). If `None` or `True` and
5493
- machine is logged in (through `huggingface-cli login` or [`~huggingface_hub.login`]), token will be
5494
- retrieved from the cache. If `False`, token is not sent in the request header.
5364
+ token (Union[bool, str, None], optional):
5365
+ A valid user access token (string). Defaults to the locally saved
5366
+ token, which is the recommended method for authentication (see
5367
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
5368
+ To disable authentication, pass `False`.
5495
5369
 
5496
5370
  Returns:
5497
5371
  [`SafetensorsFileMetadata`]: information related to a safetensors file.
@@ -5568,7 +5442,7 @@ class HfApi:
5568
5442
  *,
5569
5443
  branch: str,
5570
5444
  revision: Optional[str] = None,
5571
- token: Optional[str] = None,
5445
+ token: Union[bool, str, None] = None,
5572
5446
  repo_type: Optional[str] = None,
5573
5447
  exist_ok: bool = False,
5574
5448
  ) -> None:
@@ -5589,8 +5463,11 @@ class HfApi:
5589
5463
  the OID/SHA of a commit, as a hexadecimal string. Defaults to the head
5590
5464
  of the `"main"` branch.
5591
5465
 
5592
- token (`str`, *optional*):
5593
- Authentication token. Will default to the stored token.
5466
+ token (Union[bool, str, None], optional):
5467
+ A valid user access token (string). Defaults to the locally saved
5468
+ token, which is the recommended method for authentication (see
5469
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
5470
+ To disable authentication, pass `False`.
5594
5471
 
5595
5472
  repo_type (`str`, *optional*):
5596
5473
  Set to `"dataset"` or `"space"` if creating a branch on a dataset or
@@ -5634,7 +5511,7 @@ class HfApi:
5634
5511
  repo_id: str,
5635
5512
  *,
5636
5513
  branch: str,
5637
- token: Optional[str] = None,
5514
+ token: Union[bool, str, None] = None,
5638
5515
  repo_type: Optional[str] = None,
5639
5516
  ) -> None:
5640
5517
  """
@@ -5648,8 +5525,11 @@ class HfApi:
5648
5525
  branch (`str`):
5649
5526
  The name of the branch to delete.
5650
5527
 
5651
- token (`str`, *optional*):
5652
- Authentication token. Will default to the stored token.
5528
+ token (Union[bool, str, None], optional):
5529
+ A valid user access token (string). Defaults to the locally saved
5530
+ token, which is the recommended method for authentication (see
5531
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
5532
+ To disable authentication, pass `False`.
5653
5533
 
5654
5534
  repo_type (`str`, *optional*):
5655
5535
  Set to `"dataset"` or `"space"` if creating a branch on a dataset or
@@ -5685,7 +5565,7 @@ class HfApi:
5685
5565
  tag: str,
5686
5566
  tag_message: Optional[str] = None,
5687
5567
  revision: Optional[str] = None,
5688
- token: Optional[str] = None,
5568
+ token: Union[bool, str, None] = None,
5689
5569
  repo_type: Optional[str] = None,
5690
5570
  exist_ok: bool = False,
5691
5571
  ) -> None:
@@ -5708,8 +5588,11 @@ class HfApi:
5708
5588
  commit, as a hexadecimal string. Shorthands (7 first characters) are
5709
5589
  also supported. Defaults to the head of the `"main"` branch.
5710
5590
 
5711
- token (`str`, *optional*):
5712
- Authentication token. Will default to the stored token.
5591
+ token (Union[bool, str, None], optional):
5592
+ A valid user access token (string). Defaults to the locally saved
5593
+ token, which is the recommended method for authentication (see
5594
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
5595
+ To disable authentication, pass `False`.
5713
5596
 
5714
5597
  repo_type (`str`, *optional*):
5715
5598
  Set to `"dataset"` or `"space"` if tagging a dataset or
@@ -5754,7 +5637,7 @@ class HfApi:
5754
5637
  repo_id: str,
5755
5638
  *,
5756
5639
  tag: str,
5757
- token: Optional[str] = None,
5640
+ token: Union[bool, str, None] = None,
5758
5641
  repo_type: Optional[str] = None,
5759
5642
  ) -> None:
5760
5643
  """
@@ -5768,8 +5651,11 @@ class HfApi:
5768
5651
  tag (`str`):
5769
5652
  The name of the tag to delete.
5770
5653
 
5771
- token (`str`, *optional*):
5772
- Authentication token. Will default to the stored token.
5654
+ token (Union[bool, str, None], optional):
5655
+ A valid user access token (string). Defaults to the locally saved
5656
+ token, which is the recommended method for authentication (see
5657
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
5658
+ To disable authentication, pass `False`.
5773
5659
 
5774
5660
  repo_type (`str`, *optional*):
5775
5661
  Set to `"dataset"` or `"space"` if tagging a dataset or space, `None` or
@@ -5800,7 +5686,7 @@ class HfApi:
5800
5686
  model_id: str,
5801
5687
  *,
5802
5688
  organization: Optional[str] = None,
5803
- token: Optional[Union[bool, str]] = None,
5689
+ token: Union[bool, str, None] = None,
5804
5690
  ):
5805
5691
  """
5806
5692
  Returns the repository name for a given model ID and optional
@@ -5812,11 +5698,11 @@ class HfApi:
5812
5698
  organization (`str`, *optional*):
5813
5699
  If passed, the repository name will be in the organization
5814
5700
  namespace instead of the user namespace.
5815
- token (`bool` or `str`, *optional*):
5816
- A valid authentication token (see https://huggingface.co/settings/token).
5817
- If `None` or `True` and machine is logged in (through `huggingface-cli login`
5818
- or [`~huggingface_hub.login`]), token will be retrieved from the cache.
5819
- If `False`, token is not sent in the request header.
5701
+ token (Union[bool, str, None], optional):
5702
+ A valid user access token (string). Defaults to the locally saved
5703
+ token, which is the recommended method for authentication (see
5704
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
5705
+ To disable authentication, pass `False`.
5820
5706
 
5821
5707
  Returns:
5822
5708
  `str`: The repository name in the user's namespace
@@ -5841,7 +5727,7 @@ class HfApi:
5841
5727
  discussion_type: Optional[DiscussionTypeFilter] = None,
5842
5728
  discussion_status: Optional[DiscussionStatusFilter] = None,
5843
5729
  repo_type: Optional[str] = None,
5844
- token: Optional[str] = None,
5730
+ token: Union[bool, str, None] = None,
5845
5731
  ) -> Iterator[Discussion]:
5846
5732
  """
5847
5733
  Fetches Discussions and Pull Requests for the given repo.
@@ -5866,8 +5752,11 @@ class HfApi:
5866
5752
  Set to `"dataset"` or `"space"` if fetching from a dataset or
5867
5753
  space, `None` or `"model"` if fetching from a model. Default is
5868
5754
  `None`.
5869
- token (`str`, *optional*):
5870
- An authentication token (See https://huggingface.co/settings/token).
5755
+ token (Union[bool, str, None], optional):
5756
+ A valid user access token (string). Defaults to the locally saved
5757
+ token, which is the recommended method for authentication (see
5758
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
5759
+ To disable authentication, pass `False`.
5871
5760
 
5872
5761
  Returns:
5873
5762
  `Iterator[Discussion]`: An iterator of [`Discussion`] objects.
@@ -5944,7 +5833,7 @@ class HfApi:
5944
5833
  discussion_num: int,
5945
5834
  *,
5946
5835
  repo_type: Optional[str] = None,
5947
- token: Optional[str] = None,
5836
+ token: Union[bool, str, None] = None,
5948
5837
  ) -> DiscussionWithDetails:
5949
5838
  """Fetches a Discussion's / Pull Request 's details from the Hub.
5950
5839
 
@@ -5958,8 +5847,11 @@ class HfApi:
5958
5847
  Set to `"dataset"` or `"space"` if uploading to a dataset or
5959
5848
  space, `None` or `"model"` if uploading to a model. Default is
5960
5849
  `None`.
5961
- token (`str`, *optional*):
5962
- An authentication token (See https://huggingface.co/settings/token)
5850
+ token (Union[bool, str, None], optional):
5851
+ A valid user access token (string). Defaults to the locally saved
5852
+ token, which is the recommended method for authentication (see
5853
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
5854
+ To disable authentication, pass `False`.
5963
5855
 
5964
5856
  Returns: [`DiscussionWithDetails`]
5965
5857
 
@@ -6019,7 +5911,7 @@ class HfApi:
6019
5911
  repo_id: str,
6020
5912
  title: str,
6021
5913
  *,
6022
- token: Optional[str] = None,
5914
+ token: Union[bool, str, None] = None,
6023
5915
  description: Optional[str] = None,
6024
5916
  repo_type: Optional[str] = None,
6025
5917
  pull_request: bool = False,
@@ -6038,8 +5930,11 @@ class HfApi:
6038
5930
  The title of the discussion. It can be up to 200 characters long,
6039
5931
  and must be at least 3 characters long. Leading and trailing whitespaces
6040
5932
  will be stripped.
6041
- token (`str`, *optional*):
6042
- An authentication token (See https://huggingface.co/settings/token)
5933
+ token (Union[bool, str, None], optional):
5934
+ A valid user access token (string). Defaults to the locally saved
5935
+ token, which is the recommended method for authentication (see
5936
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
5937
+ To disable authentication, pass `False`.
6043
5938
  description (`str`, *optional*):
6044
5939
  An optional description for the Pull Request.
6045
5940
  Defaults to `"Discussion opened with the huggingface_hub Python library"`
@@ -6108,7 +6003,7 @@ class HfApi:
6108
6003
  repo_id: str,
6109
6004
  title: str,
6110
6005
  *,
6111
- token: Optional[str] = None,
6006
+ token: Union[bool, str, None] = None,
6112
6007
  description: Optional[str] = None,
6113
6008
  repo_type: Optional[str] = None,
6114
6009
  ) -> DiscussionWithDetails:
@@ -6126,8 +6021,11 @@ class HfApi:
6126
6021
  The title of the discussion. It can be up to 200 characters long,
6127
6022
  and must be at least 3 characters long. Leading and trailing whitespaces
6128
6023
  will be stripped.
6129
- token (`str`, *optional*):
6130
- An authentication token (See https://huggingface.co/settings/token)
6024
+ token (Union[bool, str, None], optional):
6025
+ A valid user access token (string). Defaults to the locally saved
6026
+ token, which is the recommended method for authentication (see
6027
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
6028
+ To disable authentication, pass `False`.
6131
6029
  description (`str`, *optional*):
6132
6030
  An optional description for the Pull Request.
6133
6031
  Defaults to `"Discussion opened with the huggingface_hub Python library"`
@@ -6167,7 +6065,7 @@ class HfApi:
6167
6065
  discussion_num: int,
6168
6066
  resource: str,
6169
6067
  body: Optional[dict] = None,
6170
- token: Optional[str] = None,
6068
+ token: Union[bool, str, None] = None,
6171
6069
  repo_type: Optional[str] = None,
6172
6070
  ) -> requests.Response:
6173
6071
  """Internal utility to POST changes to a Discussion or Pull Request"""
@@ -6193,7 +6091,7 @@ class HfApi:
6193
6091
  discussion_num: int,
6194
6092
  comment: str,
6195
6093
  *,
6196
- token: Optional[str] = None,
6094
+ token: Union[bool, str, None] = None,
6197
6095
  repo_type: Optional[str] = None,
6198
6096
  ) -> DiscussionComment:
6199
6097
  """Creates a new comment on the given Discussion.
@@ -6210,8 +6108,11 @@ class HfApi:
6210
6108
  Set to `"dataset"` or `"space"` if uploading to a dataset or
6211
6109
  space, `None` or `"model"` if uploading to a model. Default is
6212
6110
  `None`.
6213
- token (`str`, *optional*):
6214
- An authentication token (See https://huggingface.co/settings/token)
6111
+ token (Union[bool, str, None], optional):
6112
+ A valid user access token (string). Defaults to the locally saved
6113
+ token, which is the recommended method for authentication (see
6114
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
6115
+ To disable authentication, pass `False`.
6215
6116
 
6216
6117
  Returns:
6217
6118
  [`DiscussionComment`]: the newly created comment
@@ -6269,7 +6170,7 @@ class HfApi:
6269
6170
  discussion_num: int,
6270
6171
  new_title: str,
6271
6172
  *,
6272
- token: Optional[str] = None,
6173
+ token: Union[bool, str, None] = None,
6273
6174
  repo_type: Optional[str] = None,
6274
6175
  ) -> DiscussionTitleChange:
6275
6176
  """Renames a Discussion.
@@ -6286,8 +6187,11 @@ class HfApi:
6286
6187
  Set to `"dataset"` or `"space"` if uploading to a dataset or
6287
6188
  space, `None` or `"model"` if uploading to a model. Default is
6288
6189
  `None`.
6289
- token (`str`, *optional*):
6290
- An authentication token (See https://huggingface.co/settings/token)
6190
+ token (Union[bool, str, None], optional):
6191
+ A valid user access token (string). Defaults to the locally saved
6192
+ token, which is the recommended method for authentication (see
6193
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
6194
+ To disable authentication, pass `False`.
6291
6195
 
6292
6196
  Returns:
6293
6197
  [`DiscussionTitleChange`]: the title change event
@@ -6336,7 +6240,7 @@ class HfApi:
6336
6240
  discussion_num: int,
6337
6241
  new_status: Literal["open", "closed"],
6338
6242
  *,
6339
- token: Optional[str] = None,
6243
+ token: Union[bool, str, None] = None,
6340
6244
  comment: Optional[str] = None,
6341
6245
  repo_type: Optional[str] = None,
6342
6246
  ) -> DiscussionStatusChange:
@@ -6356,8 +6260,11 @@ class HfApi:
6356
6260
  Set to `"dataset"` or `"space"` if uploading to a dataset or
6357
6261
  space, `None` or `"model"` if uploading to a model. Default is
6358
6262
  `None`.
6359
- token (`str`, *optional*):
6360
- An authentication token (See https://huggingface.co/settings/token)
6263
+ token (Union[bool, str, None], optional):
6264
+ A valid user access token (string). Defaults to the locally saved
6265
+ token, which is the recommended method for authentication (see
6266
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
6267
+ To disable authentication, pass `False`.
6361
6268
 
6362
6269
  Returns:
6363
6270
  [`DiscussionStatusChange`]: the status change event
@@ -6410,7 +6317,7 @@ class HfApi:
6410
6317
  repo_id: str,
6411
6318
  discussion_num: int,
6412
6319
  *,
6413
- token: Optional[str] = None,
6320
+ token: Union[bool, str, None] = None,
6414
6321
  comment: Optional[str] = None,
6415
6322
  repo_type: Optional[str] = None,
6416
6323
  ):
@@ -6428,8 +6335,11 @@ class HfApi:
6428
6335
  Set to `"dataset"` or `"space"` if uploading to a dataset or
6429
6336
  space, `None` or `"model"` if uploading to a model. Default is
6430
6337
  `None`.
6431
- token (`str`, *optional*):
6432
- An authentication token (See https://huggingface.co/settings/token)
6338
+ token (Union[bool, str, None], optional):
6339
+ A valid user access token (string). Defaults to the locally saved
6340
+ token, which is the recommended method for authentication (see
6341
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
6342
+ To disable authentication, pass `False`.
6433
6343
 
6434
6344
  Returns:
6435
6345
  [`DiscussionStatusChange`]: the status change event
@@ -6465,7 +6375,7 @@ class HfApi:
6465
6375
  comment_id: str,
6466
6376
  new_content: str,
6467
6377
  *,
6468
- token: Optional[str] = None,
6378
+ token: Union[bool, str, None] = None,
6469
6379
  repo_type: Optional[str] = None,
6470
6380
  ) -> DiscussionComment:
6471
6381
  """Edits a comment on a Discussion / Pull Request.
@@ -6484,8 +6394,11 @@ class HfApi:
6484
6394
  Set to `"dataset"` or `"space"` if uploading to a dataset or
6485
6395
  space, `None` or `"model"` if uploading to a model. Default is
6486
6396
  `None`.
6487
- token (`str`, *optional*):
6488
- An authentication token (See https://huggingface.co/settings/token)
6397
+ token (Union[bool, str, None], optional):
6398
+ A valid user access token (string). Defaults to the locally saved
6399
+ token, which is the recommended method for authentication (see
6400
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
6401
+ To disable authentication, pass `False`.
6489
6402
 
6490
6403
  Returns:
6491
6404
  [`DiscussionComment`]: the edited comment
@@ -6521,7 +6434,7 @@ class HfApi:
6521
6434
  discussion_num: int,
6522
6435
  comment_id: str,
6523
6436
  *,
6524
- token: Optional[str] = None,
6437
+ token: Union[bool, str, None] = None,
6525
6438
  repo_type: Optional[str] = None,
6526
6439
  ) -> DiscussionComment:
6527
6440
  """Hides a comment on a Discussion / Pull Request.
@@ -6542,8 +6455,11 @@ class HfApi:
6542
6455
  Set to `"dataset"` or `"space"` if uploading to a dataset or
6543
6456
  space, `None` or `"model"` if uploading to a model. Default is
6544
6457
  `None`.
6545
- token (`str`, *optional*):
6546
- An authentication token (See https://huggingface.co/settings/token)
6458
+ token (Union[bool, str, None], optional):
6459
+ A valid user access token (string). Defaults to the locally saved
6460
+ token, which is the recommended method for authentication (see
6461
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
6462
+ To disable authentication, pass `False`.
6547
6463
 
6548
6464
  Returns:
6549
6465
  [`DiscussionComment`]: the hidden comment
@@ -6577,7 +6493,13 @@ class HfApi:
6577
6493
 
6578
6494
  @validate_hf_hub_args
6579
6495
  def add_space_secret(
6580
- self, repo_id: str, key: str, value: str, *, description: Optional[str] = None, token: Optional[str] = None
6496
+ self,
6497
+ repo_id: str,
6498
+ key: str,
6499
+ value: str,
6500
+ *,
6501
+ description: Optional[str] = None,
6502
+ token: Union[bool, str, None] = None,
6581
6503
  ) -> None:
6582
6504
  """Adds or updates a secret in a Space.
6583
6505
 
@@ -6593,8 +6515,11 @@ class HfApi:
6593
6515
  Secret value. Example: `"your_github_api_key"`.
6594
6516
  description (`str`, *optional*):
6595
6517
  Secret description. Example: `"Github API key to access the Github API"`.
6596
- token (`str`, *optional*):
6597
- Hugging Face token. Will default to the locally saved token if not provided.
6518
+ token (Union[bool, str, None], optional):
6519
+ A valid user access token (string). Defaults to the locally saved
6520
+ token, which is the recommended method for authentication (see
6521
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
6522
+ To disable authentication, pass `False`.
6598
6523
  """
6599
6524
  payload = {"key": key, "value": value}
6600
6525
  if description is not None:
@@ -6607,7 +6532,7 @@ class HfApi:
6607
6532
  hf_raise_for_status(r)
6608
6533
 
6609
6534
  @validate_hf_hub_args
6610
- def delete_space_secret(self, repo_id: str, key: str, *, token: Optional[str] = None) -> None:
6535
+ def delete_space_secret(self, repo_id: str, key: str, *, token: Union[bool, str, None] = None) -> None:
6611
6536
  """Deletes a secret from a Space.
6612
6537
 
6613
6538
  Secrets allow to set secret keys or tokens to a Space without hardcoding them.
@@ -6618,8 +6543,11 @@ class HfApi:
6618
6543
  ID of the repo to update. Example: `"bigcode/in-the-stack"`.
6619
6544
  key (`str`):
6620
6545
  Secret key. Example: `"GITHUB_API_KEY"`.
6621
- token (`str`, *optional*):
6622
- Hugging Face token. Will default to the locally saved token if not provided.
6546
+ token (Union[bool, str, None], optional):
6547
+ A valid user access token (string). Defaults to the locally saved
6548
+ token, which is the recommended method for authentication (see
6549
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
6550
+ To disable authentication, pass `False`.
6623
6551
  """
6624
6552
  r = get_session().delete(
6625
6553
  f"{self.endpoint}/api/spaces/{repo_id}/secrets",
@@ -6629,7 +6557,7 @@ class HfApi:
6629
6557
  hf_raise_for_status(r)
6630
6558
 
6631
6559
  @validate_hf_hub_args
6632
- def get_space_variables(self, repo_id: str, *, token: Optional[str] = None) -> Dict[str, SpaceVariable]:
6560
+ def get_space_variables(self, repo_id: str, *, token: Union[bool, str, None] = None) -> Dict[str, SpaceVariable]:
6633
6561
  """Gets all variables from a Space.
6634
6562
 
6635
6563
  Variables allow to set environment variables to a Space without hardcoding them.
@@ -6638,8 +6566,11 @@ class HfApi:
6638
6566
  Args:
6639
6567
  repo_id (`str`):
6640
6568
  ID of the repo to query. Example: `"bigcode/in-the-stack"`.
6641
- token (`str`, *optional*):
6642
- Hugging Face token. Will default to the locally saved token if not provided.
6569
+ token (Union[bool, str, None], optional):
6570
+ A valid user access token (string). Defaults to the locally saved
6571
+ token, which is the recommended method for authentication (see
6572
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
6573
+ To disable authentication, pass `False`.
6643
6574
  """
6644
6575
  r = get_session().get(
6645
6576
  f"{self.endpoint}/api/spaces/{repo_id}/variables",
@@ -6650,7 +6581,13 @@ class HfApi:
6650
6581
 
6651
6582
  @validate_hf_hub_args
6652
6583
  def add_space_variable(
6653
- self, repo_id: str, key: str, value: str, *, description: Optional[str] = None, token: Optional[str] = None
6584
+ self,
6585
+ repo_id: str,
6586
+ key: str,
6587
+ value: str,
6588
+ *,
6589
+ description: Optional[str] = None,
6590
+ token: Union[bool, str, None] = None,
6654
6591
  ) -> Dict[str, SpaceVariable]:
6655
6592
  """Adds or updates a variable in a Space.
6656
6593
 
@@ -6666,8 +6603,11 @@ class HfApi:
6666
6603
  Variable value. Example: `"the_model_repo_id"`.
6667
6604
  description (`str`):
6668
6605
  Description of the variable. Example: `"Model Repo ID of the implemented model"`.
6669
- token (`str`, *optional*):
6670
- Hugging Face token. Will default to the locally saved token if not provided.
6606
+ token (Union[bool, str, None], optional):
6607
+ A valid user access token (string). Defaults to the locally saved
6608
+ token, which is the recommended method for authentication (see
6609
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
6610
+ To disable authentication, pass `False`.
6671
6611
  """
6672
6612
  payload = {"key": key, "value": value}
6673
6613
  if description is not None:
@@ -6682,7 +6622,7 @@ class HfApi:
6682
6622
 
6683
6623
  @validate_hf_hub_args
6684
6624
  def delete_space_variable(
6685
- self, repo_id: str, key: str, *, token: Optional[str] = None
6625
+ self, repo_id: str, key: str, *, token: Union[bool, str, None] = None
6686
6626
  ) -> Dict[str, SpaceVariable]:
6687
6627
  """Deletes a variable from a Space.
6688
6628
 
@@ -6694,8 +6634,11 @@ class HfApi:
6694
6634
  ID of the repo to update. Example: `"bigcode/in-the-stack"`.
6695
6635
  key (`str`):
6696
6636
  Variable key. Example: `"MODEL_REPO_ID"`
6697
- token (`str`, *optional*):
6698
- Hugging Face token. Will default to the locally saved token if not provided.
6637
+ token (Union[bool, str, None], optional):
6638
+ A valid user access token (string). Defaults to the locally saved
6639
+ token, which is the recommended method for authentication (see
6640
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
6641
+ To disable authentication, pass `False`.
6699
6642
  """
6700
6643
  r = get_session().delete(
6701
6644
  f"{self.endpoint}/api/spaces/{repo_id}/variables",
@@ -6706,15 +6649,17 @@ class HfApi:
6706
6649
  return {k: SpaceVariable(k, v) for k, v in r.json().items()}
6707
6650
 
6708
6651
  @validate_hf_hub_args
6709
- def get_space_runtime(self, repo_id: str, *, token: Optional[str] = None) -> SpaceRuntime:
6652
+ def get_space_runtime(self, repo_id: str, *, token: Union[bool, str, None] = None) -> SpaceRuntime:
6710
6653
  """Gets runtime information about a Space.
6711
6654
 
6712
6655
  Args:
6713
6656
  repo_id (`str`):
6714
6657
  ID of the repo to update. Example: `"bigcode/in-the-stack"`.
6715
- token (`str`, *optional*):
6716
- Hugging Face token. Will default to the locally saved token if
6717
- not provided.
6658
+ token (Union[bool, str, None], optional):
6659
+ A valid user access token (string). Defaults to the locally saved
6660
+ token, which is the recommended method for authentication (see
6661
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
6662
+ To disable authentication, pass `False`.
6718
6663
  Returns:
6719
6664
  [`SpaceRuntime`]: Runtime information about a Space including Space stage and hardware.
6720
6665
  """
@@ -6730,7 +6675,7 @@ class HfApi:
6730
6675
  repo_id: str,
6731
6676
  hardware: SpaceHardware,
6732
6677
  *,
6733
- token: Optional[str] = None,
6678
+ token: Union[bool, str, None] = None,
6734
6679
  sleep_time: Optional[int] = None,
6735
6680
  ) -> SpaceRuntime:
6736
6681
  """Request new hardware for a Space.
@@ -6740,8 +6685,11 @@ class HfApi:
6740
6685
  ID of the repo to update. Example: `"bigcode/in-the-stack"`.
6741
6686
  hardware (`str` or [`SpaceHardware`]):
6742
6687
  Hardware on which to run the Space. Example: `"t4-medium"`.
6743
- token (`str`, *optional*):
6744
- Hugging Face token. Will default to the locally saved token if not provided.
6688
+ token (Union[bool, str, None], optional):
6689
+ A valid user access token (string). Defaults to the locally saved
6690
+ token, which is the recommended method for authentication (see
6691
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
6692
+ To disable authentication, pass `False`.
6745
6693
  sleep_time (`int`, *optional*):
6746
6694
  Number of seconds of inactivity to wait before a Space is put to sleep. Set to `-1` if you don't want
6747
6695
  your Space to sleep (default behavior for upgraded hardware). For free hardware, you can't configure
@@ -6775,7 +6723,9 @@ class HfApi:
6775
6723
  return SpaceRuntime(r.json())
6776
6724
 
6777
6725
  @validate_hf_hub_args
6778
- def set_space_sleep_time(self, repo_id: str, sleep_time: int, *, token: Optional[str] = None) -> SpaceRuntime:
6726
+ def set_space_sleep_time(
6727
+ self, repo_id: str, sleep_time: int, *, token: Union[bool, str, None] = None
6728
+ ) -> SpaceRuntime:
6779
6729
  """Set a custom sleep time for a Space running on upgraded hardware..
6780
6730
 
6781
6731
  Your Space will go to sleep after X seconds of inactivity. You are not billed when your Space is in "sleep"
@@ -6791,8 +6741,11 @@ class HfApi:
6791
6741
  your Space to pause (default behavior for upgraded hardware). For free hardware, you can't configure
6792
6742
  the sleep time (value is fixed to 48 hours of inactivity).
6793
6743
  See https://huggingface.co/docs/hub/spaces-gpus#sleep-time for more details.
6794
- token (`str`, *optional*):
6795
- Hugging Face token. Will default to the locally saved token if not provided.
6744
+ token (Union[bool, str, None], optional):
6745
+ A valid user access token (string). Defaults to the locally saved
6746
+ token, which is the recommended method for authentication (see
6747
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
6748
+ To disable authentication, pass `False`.
6796
6749
  Returns:
6797
6750
  [`SpaceRuntime`]: Runtime information about a Space including Space stage and hardware.
6798
6751
 
@@ -6821,7 +6774,7 @@ class HfApi:
6821
6774
  return runtime
6822
6775
 
6823
6776
  @validate_hf_hub_args
6824
- def pause_space(self, repo_id: str, *, token: Optional[str] = None) -> SpaceRuntime:
6777
+ def pause_space(self, repo_id: str, *, token: Union[bool, str, None] = None) -> SpaceRuntime:
6825
6778
  """Pause your Space.
6826
6779
 
6827
6780
  A paused Space stops executing until manually restarted by its owner. This is different from the sleeping
@@ -6833,8 +6786,11 @@ class HfApi:
6833
6786
  Args:
6834
6787
  repo_id (`str`):
6835
6788
  ID of the Space to pause. Example: `"Salesforce/BLIP2"`.
6836
- token (`str`, *optional*):
6837
- Hugging Face token. Will default to the locally saved token if not provided.
6789
+ token (Union[bool, str, None], optional):
6790
+ A valid user access token (string). Defaults to the locally saved
6791
+ token, which is the recommended method for authentication (see
6792
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
6793
+ To disable authentication, pass `False`.
6838
6794
 
6839
6795
  Returns:
6840
6796
  [`SpaceRuntime`]: Runtime information about your Space including `stage=PAUSED` and requested hardware.
@@ -6858,7 +6814,7 @@ class HfApi:
6858
6814
 
6859
6815
  @validate_hf_hub_args
6860
6816
  def restart_space(
6861
- self, repo_id: str, *, token: Optional[str] = None, factory_reboot: bool = False
6817
+ self, repo_id: str, *, token: Union[bool, str, None] = None, factory_reboot: bool = False
6862
6818
  ) -> SpaceRuntime:
6863
6819
  """Restart your Space.
6864
6820
 
@@ -6871,8 +6827,11 @@ class HfApi:
6871
6827
  Args:
6872
6828
  repo_id (`str`):
6873
6829
  ID of the Space to restart. Example: `"Salesforce/BLIP2"`.
6874
- token (`str`, *optional*):
6875
- Hugging Face token. Will default to the locally saved token if not provided.
6830
+ token (Union[bool, str, None], optional):
6831
+ A valid user access token (string). Defaults to the locally saved
6832
+ token, which is the recommended method for authentication (see
6833
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
6834
+ To disable authentication, pass `False`.
6876
6835
  factory_reboot (`bool`, *optional*):
6877
6836
  If `True`, the Space will be rebuilt from scratch without caching any requirements.
6878
6837
 
@@ -6906,7 +6865,7 @@ class HfApi:
6906
6865
  to_id: Optional[str] = None,
6907
6866
  *,
6908
6867
  private: Optional[bool] = None,
6909
- token: Optional[str] = None,
6868
+ token: Union[bool, str, None] = None,
6910
6869
  exist_ok: bool = False,
6911
6870
  hardware: Optional[SpaceHardware] = None,
6912
6871
  storage: Optional[SpaceStorage] = None,
@@ -6927,8 +6886,11 @@ class HfApi:
6927
6886
  name as the original Space, but in your account.
6928
6887
  private (`bool`, *optional*):
6929
6888
  Whether the new Space should be private or not. Defaults to the same privacy as the original Space.
6930
- token (`str`, *optional*):
6931
- Hugging Face token. Will default to the locally saved token if not provided.
6889
+ token (Union[bool, str, None], optional):
6890
+ A valid user access token (string). Defaults to the locally saved
6891
+ token, which is the recommended method for authentication (see
6892
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
6893
+ To disable authentication, pass `False`.
6932
6894
  exist_ok (`bool`, *optional*, defaults to `False`):
6933
6895
  If `True`, do not raise an error if repo already exists.
6934
6896
  hardware (`SpaceHardware` or `str`, *optional*):
@@ -7020,7 +6982,7 @@ class HfApi:
7020
6982
  repo_id: str,
7021
6983
  storage: SpaceStorage,
7022
6984
  *,
7023
- token: Optional[str] = None,
6985
+ token: Union[bool, str, None] = None,
7024
6986
  ) -> SpaceRuntime:
7025
6987
  """Request persistent storage for a Space.
7026
6988
 
@@ -7029,8 +6991,11 @@ class HfApi:
7029
6991
  ID of the Space to update. Example: `"HuggingFaceH4/open_llm_leaderboard"`.
7030
6992
  storage (`str` or [`SpaceStorage`]):
7031
6993
  Storage tier. Either 'small', 'medium', or 'large'.
7032
- token (`str`, *optional*):
7033
- Hugging Face token. Will default to the locally saved token if not provided.
6994
+ token (Union[bool, str, None], optional):
6995
+ A valid user access token (string). Defaults to the locally saved
6996
+ token, which is the recommended method for authentication (see
6997
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
6998
+ To disable authentication, pass `False`.
7034
6999
  Returns:
7035
7000
  [`SpaceRuntime`]: Runtime information about a Space including Space stage and hardware.
7036
7001
 
@@ -7055,15 +7020,18 @@ class HfApi:
7055
7020
  self,
7056
7021
  repo_id: str,
7057
7022
  *,
7058
- token: Optional[str] = None,
7023
+ token: Union[bool, str, None] = None,
7059
7024
  ) -> SpaceRuntime:
7060
7025
  """Delete persistent storage for a Space.
7061
7026
 
7062
7027
  Args:
7063
7028
  repo_id (`str`):
7064
7029
  ID of the Space to update. Example: `"HuggingFaceH4/open_llm_leaderboard"`.
7065
- token (`str`, *optional*):
7066
- Hugging Face token. Will default to the locally saved token if not provided.
7030
+ token (Union[bool, str, None], optional):
7031
+ A valid user access token (string). Defaults to the locally saved
7032
+ token, which is the recommended method for authentication (see
7033
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
7034
+ To disable authentication, pass `False`.
7067
7035
  Returns:
7068
7036
  [`SpaceRuntime`]: Runtime information about a Space including Space stage and hardware.
7069
7037
  Raises:
@@ -7083,7 +7051,7 @@ class HfApi:
7083
7051
  #######################
7084
7052
 
7085
7053
  def list_inference_endpoints(
7086
- self, namespace: Optional[str] = None, *, token: Optional[str] = None
7054
+ self, namespace: Optional[str] = None, *, token: Union[bool, str, None] = None
7087
7055
  ) -> List[InferenceEndpoint]:
7088
7056
  """Lists all inference endpoints for the given namespace.
7089
7057
 
@@ -7091,8 +7059,11 @@ class HfApi:
7091
7059
  namespace (`str`, *optional*):
7092
7060
  The namespace to list endpoints for. Defaults to the current user. Set to `"*"` to list all endpoints
7093
7061
  from all namespaces (i.e. personal namespace and all orgs the user belongs to).
7094
- token (`str`, *optional*):
7095
- An authentication token (See https://huggingface.co/settings/token).
7062
+ token (Union[bool, str, None], optional):
7063
+ A valid user access token (string). Defaults to the locally saved
7064
+ token, which is the recommended method for authentication (see
7065
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
7066
+ To disable authentication, pass `False`.
7096
7067
 
7097
7068
  Returns:
7098
7069
  List[`InferenceEndpoint`]: A list of all inference endpoints for the given namespace.
@@ -7156,7 +7127,7 @@ class HfApi:
7156
7127
  custom_image: Optional[Dict] = None,
7157
7128
  type: InferenceEndpointType = InferenceEndpointType.PROTECTED,
7158
7129
  namespace: Optional[str] = None,
7159
- token: Optional[str] = None,
7130
+ token: Union[bool, str, None] = None,
7160
7131
  ) -> InferenceEndpoint:
7161
7132
  """Create a new Inference Endpoint.
7162
7133
 
@@ -7194,8 +7165,11 @@ class HfApi:
7194
7165
  The type of the Inference Endpoint, which can be `"protected"` (default), `"public"` or `"private"`.
7195
7166
  namespace (`str`, *optional*):
7196
7167
  The namespace where the Inference Endpoint will be created. Defaults to the current user's namespace.
7197
- token (`str`, *optional*):
7198
- An authentication token (See https://huggingface.co/settings/token).
7168
+ token (Union[bool, str, None], optional):
7169
+ A valid user access token (string). Defaults to the locally saved
7170
+ token, which is the recommended method for authentication (see
7171
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
7172
+ To disable authentication, pass `False`.
7199
7173
 
7200
7174
  Returns:
7201
7175
  [`InferenceEndpoint`]: information about the updated Inference Endpoint.
@@ -7292,7 +7266,7 @@ class HfApi:
7292
7266
  return InferenceEndpoint.from_raw(response.json(), namespace=namespace, token=token)
7293
7267
 
7294
7268
  def get_inference_endpoint(
7295
- self, name: str, *, namespace: Optional[str] = None, token: Optional[str] = None
7269
+ self, name: str, *, namespace: Optional[str] = None, token: Union[bool, str, None] = None
7296
7270
  ) -> InferenceEndpoint:
7297
7271
  """Get information about an Inference Endpoint.
7298
7272
 
@@ -7301,8 +7275,11 @@ class HfApi:
7301
7275
  The name of the Inference Endpoint to retrieve information about.
7302
7276
  namespace (`str`, *optional*):
7303
7277
  The namespace in which the Inference Endpoint is located. Defaults to the current user.
7304
- token (`str`, *optional*):
7305
- An authentication token (See https://huggingface.co/settings/token).
7278
+ token (Union[bool, str, None], optional):
7279
+ A valid user access token (string). Defaults to the locally saved
7280
+ token, which is the recommended method for authentication (see
7281
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
7282
+ To disable authentication, pass `False`.
7306
7283
 
7307
7284
  Returns:
7308
7285
  [`InferenceEndpoint`]: information about the requested Inference Endpoint.
@@ -7352,7 +7329,7 @@ class HfApi:
7352
7329
  task: Optional[str] = None,
7353
7330
  # Other
7354
7331
  namespace: Optional[str] = None,
7355
- token: Optional[str] = None,
7332
+ token: Union[bool, str, None] = None,
7356
7333
  ) -> InferenceEndpoint:
7357
7334
  """Update an Inference Endpoint.
7358
7335
 
@@ -7387,8 +7364,11 @@ class HfApi:
7387
7364
 
7388
7365
  namespace (`str`, *optional*):
7389
7366
  The namespace where the Inference Endpoint will be updated. Defaults to the current user's namespace.
7390
- token (`str`, *optional*):
7391
- An authentication token (See https://huggingface.co/settings/token).
7367
+ token (Union[bool, str, None], optional):
7368
+ A valid user access token (string). Defaults to the locally saved
7369
+ token, which is the recommended method for authentication (see
7370
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
7371
+ To disable authentication, pass `False`.
7392
7372
 
7393
7373
  Returns:
7394
7374
  [`InferenceEndpoint`]: information about the updated Inference Endpoint.
@@ -7425,7 +7405,7 @@ class HfApi:
7425
7405
  return InferenceEndpoint.from_raw(response.json(), namespace=namespace, token=token)
7426
7406
 
7427
7407
  def delete_inference_endpoint(
7428
- self, name: str, *, namespace: Optional[str] = None, token: Optional[str] = None
7408
+ self, name: str, *, namespace: Optional[str] = None, token: Union[bool, str, None] = None
7429
7409
  ) -> None:
7430
7410
  """Delete an Inference Endpoint.
7431
7411
 
@@ -7439,8 +7419,11 @@ class HfApi:
7439
7419
  The name of the Inference Endpoint to delete.
7440
7420
  namespace (`str`, *optional*):
7441
7421
  The namespace in which the Inference Endpoint is located. Defaults to the current user.
7442
- token (`str`, *optional*):
7443
- An authentication token (See https://huggingface.co/settings/token).
7422
+ token (Union[bool, str, None], optional):
7423
+ A valid user access token (string). Defaults to the locally saved
7424
+ token, which is the recommended method for authentication (see
7425
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
7426
+ To disable authentication, pass `False`.
7444
7427
  """
7445
7428
  namespace = namespace or self._get_namespace(token=token)
7446
7429
  response = get_session().delete(
@@ -7450,7 +7433,7 @@ class HfApi:
7450
7433
  hf_raise_for_status(response)
7451
7434
 
7452
7435
  def pause_inference_endpoint(
7453
- self, name: str, *, namespace: Optional[str] = None, token: Optional[str] = None
7436
+ self, name: str, *, namespace: Optional[str] = None, token: Union[bool, str, None] = None
7454
7437
  ) -> InferenceEndpoint:
7455
7438
  """Pause an Inference Endpoint.
7456
7439
 
@@ -7465,8 +7448,11 @@ class HfApi:
7465
7448
  The name of the Inference Endpoint to pause.
7466
7449
  namespace (`str`, *optional*):
7467
7450
  The namespace in which the Inference Endpoint is located. Defaults to the current user.
7468
- token (`str`, *optional*):
7469
- An authentication token (See https://huggingface.co/settings/token).
7451
+ token (Union[bool, str, None], optional):
7452
+ A valid user access token (string). Defaults to the locally saved
7453
+ token, which is the recommended method for authentication (see
7454
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
7455
+ To disable authentication, pass `False`.
7470
7456
 
7471
7457
  Returns:
7472
7458
  [`InferenceEndpoint`]: information about the paused Inference Endpoint.
@@ -7482,7 +7468,7 @@ class HfApi:
7482
7468
  return InferenceEndpoint.from_raw(response.json(), namespace=namespace, token=token)
7483
7469
 
7484
7470
  def resume_inference_endpoint(
7485
- self, name: str, *, namespace: Optional[str] = None, token: Optional[str] = None
7471
+ self, name: str, *, namespace: Optional[str] = None, token: Union[bool, str, None] = None
7486
7472
  ) -> InferenceEndpoint:
7487
7473
  """Resume an Inference Endpoint.
7488
7474
 
@@ -7493,8 +7479,11 @@ class HfApi:
7493
7479
  The name of the Inference Endpoint to resume.
7494
7480
  namespace (`str`, *optional*):
7495
7481
  The namespace in which the Inference Endpoint is located. Defaults to the current user.
7496
- token (`str`, *optional*):
7497
- An authentication token (See https://huggingface.co/settings/token).
7482
+ token (Union[bool, str, None], optional):
7483
+ A valid user access token (string). Defaults to the locally saved
7484
+ token, which is the recommended method for authentication (see
7485
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
7486
+ To disable authentication, pass `False`.
7498
7487
 
7499
7488
  Returns:
7500
7489
  [`InferenceEndpoint`]: information about the resumed Inference Endpoint.
@@ -7510,7 +7499,7 @@ class HfApi:
7510
7499
  return InferenceEndpoint.from_raw(response.json(), namespace=namespace, token=token)
7511
7500
 
7512
7501
  def scale_to_zero_inference_endpoint(
7513
- self, name: str, *, namespace: Optional[str] = None, token: Optional[str] = None
7502
+ self, name: str, *, namespace: Optional[str] = None, token: Union[bool, str, None] = None
7514
7503
  ) -> InferenceEndpoint:
7515
7504
  """Scale Inference Endpoint to zero.
7516
7505
 
@@ -7525,8 +7514,11 @@ class HfApi:
7525
7514
  The name of the Inference Endpoint to scale to zero.
7526
7515
  namespace (`str`, *optional*):
7527
7516
  The namespace in which the Inference Endpoint is located. Defaults to the current user.
7528
- token (`str`, *optional*):
7529
- An authentication token (See https://huggingface.co/settings/token).
7517
+ token (Union[bool, str, None], optional):
7518
+ A valid user access token (string). Defaults to the locally saved
7519
+ token, which is the recommended method for authentication (see
7520
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
7521
+ To disable authentication, pass `False`.
7530
7522
 
7531
7523
  Returns:
7532
7524
  [`InferenceEndpoint`]: information about the scaled-to-zero Inference Endpoint.
@@ -7541,7 +7533,7 @@ class HfApi:
7541
7533
 
7542
7534
  return InferenceEndpoint.from_raw(response.json(), namespace=namespace, token=token)
7543
7535
 
7544
- def _get_namespace(self, token: Optional[str] = None) -> str:
7536
+ def _get_namespace(self, token: Union[bool, str, None] = None) -> str:
7545
7537
  """Get the default namespace for the current user."""
7546
7538
  me = self.whoami(token=token)
7547
7539
  if me["type"] == "user":
@@ -7563,7 +7555,7 @@ class HfApi:
7563
7555
  item: Union[List[str], str, None] = None,
7564
7556
  sort: Optional[Literal["lastModified", "trending", "upvotes"]] = None,
7565
7557
  limit: Optional[int] = None,
7566
- token: Optional[Union[bool, str]] = None,
7558
+ token: Union[bool, str, None] = None,
7567
7559
  ) -> Iterable[Collection]:
7568
7560
  """List collections on the Huggingface Hub, given some filters.
7569
7561
 
@@ -7583,8 +7575,11 @@ class HfApi:
7583
7575
  Sort collections by last modified, trending or upvotes.
7584
7576
  limit (`int`, *optional*):
7585
7577
  Maximum number of collections to be returned.
7586
- token (`bool` or `str`, *optional*):
7587
- An authentication token (see https://huggingface.co/settings/token).
7578
+ token (Union[bool, str, None], optional):
7579
+ A valid user access token (string). Defaults to the locally saved
7580
+ token, which is the recommended method for authentication (see
7581
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
7582
+ To disable authentication, pass `False`.
7588
7583
 
7589
7584
  Returns:
7590
7585
  `Iterable[Collection]`: an iterable of [`Collection`] objects.
@@ -7611,14 +7606,17 @@ class HfApi:
7611
7606
  for position, collection_data in enumerate(items):
7612
7607
  yield Collection(position=position, **collection_data)
7613
7608
 
7614
- def get_collection(self, collection_slug: str, *, token: Optional[str] = None) -> Collection:
7609
+ def get_collection(self, collection_slug: str, *, token: Union[bool, str, None] = None) -> Collection:
7615
7610
  """Gets information about a Collection on the Hub.
7616
7611
 
7617
7612
  Args:
7618
7613
  collection_slug (`str`):
7619
7614
  Slug of the collection of the Hub. Example: `"TheBloke/recent-models-64f9a55bb3115b4f513ec026"`.
7620
- token (`str`, *optional*):
7621
- Hugging Face token. Will default to the locally saved token if not provided.
7615
+ token (Union[bool, str, None], optional):
7616
+ A valid user access token (string). Defaults to the locally saved
7617
+ token, which is the recommended method for authentication (see
7618
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
7619
+ To disable authentication, pass `False`.
7622
7620
 
7623
7621
  Returns: [`Collection`]
7624
7622
 
@@ -7655,7 +7653,7 @@ class HfApi:
7655
7653
  description: Optional[str] = None,
7656
7654
  private: bool = False,
7657
7655
  exists_ok: bool = False,
7658
- token: Optional[str] = None,
7656
+ token: Union[bool, str, None] = None,
7659
7657
  ) -> Collection:
7660
7658
  """Create a new Collection on the Hub.
7661
7659
 
@@ -7670,8 +7668,11 @@ class HfApi:
7670
7668
  Whether the collection should be private or not. Defaults to `False` (i.e. public collection).
7671
7669
  exists_ok (`bool`, *optional*):
7672
7670
  If `True`, do not raise an error if collection already exists.
7673
- token (`str`, *optional*):
7674
- Hugging Face token. Will default to the locally saved token if not provided.
7671
+ token (Union[bool, str, None], optional):
7672
+ A valid user access token (string). Defaults to the locally saved
7673
+ token, which is the recommended method for authentication (see
7674
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
7675
+ To disable authentication, pass `False`.
7675
7676
 
7676
7677
  Returns: [`Collection`]
7677
7678
 
@@ -7721,7 +7722,7 @@ class HfApi:
7721
7722
  position: Optional[int] = None,
7722
7723
  private: Optional[bool] = None,
7723
7724
  theme: Optional[str] = None,
7724
- token: Optional[str] = None,
7725
+ token: Union[bool, str, None] = None,
7725
7726
  ) -> Collection:
7726
7727
  """Update metadata of a collection on the Hub.
7727
7728
 
@@ -7740,8 +7741,11 @@ class HfApi:
7740
7741
  Whether the collection should be private or not.
7741
7742
  theme (`str`, *optional*):
7742
7743
  Theme of the collection on the Hub.
7743
- token (`str`, *optional*):
7744
- Hugging Face token. Will default to the locally saved token if not provided.
7744
+ token (Union[bool, str, None], optional):
7745
+ A valid user access token (string). Defaults to the locally saved
7746
+ token, which is the recommended method for authentication (see
7747
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
7748
+ To disable authentication, pass `False`.
7745
7749
 
7746
7750
  Returns: [`Collection`]
7747
7751
 
@@ -7778,7 +7782,7 @@ class HfApi:
7778
7782
  return Collection(**{**r.json()["data"], "endpoint": self.endpoint})
7779
7783
 
7780
7784
  def delete_collection(
7781
- self, collection_slug: str, *, missing_ok: bool = False, token: Optional[str] = None
7785
+ self, collection_slug: str, *, missing_ok: bool = False, token: Union[bool, str, None] = None
7782
7786
  ) -> None:
7783
7787
  """Delete a collection on the Hub.
7784
7788
 
@@ -7787,8 +7791,11 @@ class HfApi:
7787
7791
  Slug of the collection to delete. Example: `"TheBloke/recent-models-64f9a55bb3115b4f513ec026"`.
7788
7792
  missing_ok (`bool`, *optional*):
7789
7793
  If `True`, do not raise an error if collection doesn't exists.
7790
- token (`str`, *optional*):
7791
- Hugging Face token. Will default to the locally saved token if not provided.
7794
+ token (Union[bool, str, None], optional):
7795
+ A valid user access token (string). Defaults to the locally saved
7796
+ token, which is the recommended method for authentication (see
7797
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
7798
+ To disable authentication, pass `False`.
7792
7799
 
7793
7800
  Example:
7794
7801
 
@@ -7823,7 +7830,7 @@ class HfApi:
7823
7830
  *,
7824
7831
  note: Optional[str] = None,
7825
7832
  exists_ok: bool = False,
7826
- token: Optional[str] = None,
7833
+ token: Union[bool, str, None] = None,
7827
7834
  ) -> Collection:
7828
7835
  """Add an item to a collection on the Hub.
7829
7836
 
@@ -7839,8 +7846,11 @@ class HfApi:
7839
7846
  A note to attach to the item in the collection. The maximum size for a note is 500 characters.
7840
7847
  exists_ok (`bool`, *optional*):
7841
7848
  If `True`, do not raise an error if item already exists.
7842
- token (`str`, *optional*):
7843
- Hugging Face token. Will default to the locally saved token if not provided.
7849
+ token (Union[bool, str, None], optional):
7850
+ A valid user access token (string). Defaults to the locally saved
7851
+ token, which is the recommended method for authentication (see
7852
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
7853
+ To disable authentication, pass `False`.
7844
7854
 
7845
7855
  Returns: [`Collection`]
7846
7856
 
@@ -7901,7 +7911,7 @@ class HfApi:
7901
7911
  *,
7902
7912
  note: Optional[str] = None,
7903
7913
  position: Optional[int] = None,
7904
- token: Optional[str] = None,
7914
+ token: Union[bool, str, None] = None,
7905
7915
  ) -> None:
7906
7916
  """Update an item in a collection.
7907
7917
 
@@ -7915,8 +7925,11 @@ class HfApi:
7915
7925
  A note to attach to the item in the collection. The maximum size for a note is 500 characters.
7916
7926
  position (`int`, *optional*):
7917
7927
  New position of the item in the collection.
7918
- token (`str`, *optional*):
7919
- Hugging Face token. Will default to the locally saved token if not provided.
7928
+ token (Union[bool, str, None], optional):
7929
+ A valid user access token (string). Defaults to the locally saved
7930
+ token, which is the recommended method for authentication (see
7931
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
7932
+ To disable authentication, pass `False`.
7920
7933
 
7921
7934
  Example:
7922
7935
 
@@ -7950,7 +7963,7 @@ class HfApi:
7950
7963
  item_object_id: str,
7951
7964
  *,
7952
7965
  missing_ok: bool = False,
7953
- token: Optional[str] = None,
7966
+ token: Union[bool, str, None] = None,
7954
7967
  ) -> None:
7955
7968
  """Delete an item from a collection.
7956
7969
 
@@ -7962,8 +7975,11 @@ class HfApi:
7962
7975
  It must be retrieved from a [`CollectionItem`] object. Example: `collection.items[0]._id`.
7963
7976
  missing_ok (`bool`, *optional*):
7964
7977
  If `True`, do not raise an error if item doesn't exists.
7965
- token (`str`, *optional*):
7966
- Hugging Face token. Will default to the locally saved token if not provided.
7978
+ token (Union[bool, str, None], optional):
7979
+ A valid user access token (string). Defaults to the locally saved
7980
+ token, which is the recommended method for authentication (see
7981
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
7982
+ To disable authentication, pass `False`.
7967
7983
 
7968
7984
  Example:
7969
7985
 
@@ -7999,7 +8015,7 @@ class HfApi:
7999
8015
 
8000
8016
  @validate_hf_hub_args
8001
8017
  def list_pending_access_requests(
8002
- self, repo_id: str, *, repo_type: Optional[str] = None, token: Optional[str] = None
8018
+ self, repo_id: str, *, repo_type: Optional[str] = None, token: Union[bool, str, None] = None
8003
8019
  ) -> List[AccessRequest]:
8004
8020
  """
8005
8021
  Get pending access requests for a given gated repo.
@@ -8016,8 +8032,11 @@ class HfApi:
8016
8032
  repo_type (`str`, *optional*):
8017
8033
  The type of the repo to get access requests for. Must be one of `model`, `dataset` or `space`.
8018
8034
  Defaults to `model`.
8019
- token (`str`, *optional*):
8020
- A valid authentication token (see https://huggingface.co/settings/token).
8035
+ token (Union[bool, str, None], optional):
8036
+ A valid user access token (string). Defaults to the locally saved
8037
+ token, which is the recommended method for authentication (see
8038
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
8039
+ To disable authentication, pass `False`.
8021
8040
 
8022
8041
  Returns:
8023
8042
  `List[AccessRequest]`: A list of [`AccessRequest`] objects. Each time contains a `username`, `email`,
@@ -8060,7 +8079,7 @@ class HfApi:
8060
8079
 
8061
8080
  @validate_hf_hub_args
8062
8081
  def list_accepted_access_requests(
8063
- self, repo_id: str, *, repo_type: Optional[str] = None, token: Optional[str] = None
8082
+ self, repo_id: str, *, repo_type: Optional[str] = None, token: Union[bool, str, None] = None
8064
8083
  ) -> List[AccessRequest]:
8065
8084
  """
8066
8085
  Get accepted access requests for a given gated repo.
@@ -8079,8 +8098,11 @@ class HfApi:
8079
8098
  repo_type (`str`, *optional*):
8080
8099
  The type of the repo to get access requests for. Must be one of `model`, `dataset` or `space`.
8081
8100
  Defaults to `model`.
8082
- token (`str`, *optional*):
8083
- A valid authentication token (see https://huggingface.co/settings/token).
8101
+ token (Union[bool, str, None], optional):
8102
+ A valid user access token (string). Defaults to the locally saved
8103
+ token, which is the recommended method for authentication (see
8104
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
8105
+ To disable authentication, pass `False`.
8084
8106
 
8085
8107
  Returns:
8086
8108
  `List[AccessRequest]`: A list of [`AccessRequest`] objects. Each time contains a `username`, `email`,
@@ -8119,7 +8141,7 @@ class HfApi:
8119
8141
 
8120
8142
  @validate_hf_hub_args
8121
8143
  def list_rejected_access_requests(
8122
- self, repo_id: str, *, repo_type: Optional[str] = None, token: Optional[str] = None
8144
+ self, repo_id: str, *, repo_type: Optional[str] = None, token: Union[bool, str, None] = None
8123
8145
  ) -> List[AccessRequest]:
8124
8146
  """
8125
8147
  Get rejected access requests for a given gated repo.
@@ -8138,8 +8160,11 @@ class HfApi:
8138
8160
  repo_type (`str`, *optional*):
8139
8161
  The type of the repo to get access requests for. Must be one of `model`, `dataset` or `space`.
8140
8162
  Defaults to `model`.
8141
- token (`str`, *optional*):
8142
- A valid authentication token (see https://huggingface.co/settings/token).
8163
+ token (Union[bool, str, None], optional):
8164
+ A valid user access token (string). Defaults to the locally saved
8165
+ token, which is the recommended method for authentication (see
8166
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
8167
+ To disable authentication, pass `False`.
8143
8168
 
8144
8169
  Returns:
8145
8170
  `List[AccessRequest]`: A list of [`AccessRequest`] objects. Each time contains a `username`, `email`,
@@ -8181,7 +8206,7 @@ class HfApi:
8181
8206
  repo_id: str,
8182
8207
  status: Literal["accepted", "rejected", "pending"],
8183
8208
  repo_type: Optional[str] = None,
8184
- token: Optional[str] = None,
8209
+ token: Union[bool, str, None] = None,
8185
8210
  ) -> List[AccessRequest]:
8186
8211
  if repo_type not in REPO_TYPES:
8187
8212
  raise ValueError(f"Invalid repo type, must be one of {REPO_TYPES}")
@@ -8207,7 +8232,7 @@ class HfApi:
8207
8232
 
8208
8233
  @validate_hf_hub_args
8209
8234
  def cancel_access_request(
8210
- self, repo_id: str, user: str, *, repo_type: Optional[str] = None, token: Optional[str] = None
8235
+ self, repo_id: str, user: str, *, repo_type: Optional[str] = None, token: Union[bool, str, None] = None
8211
8236
  ) -> None:
8212
8237
  """
8213
8238
  Cancel an access request from a user for a given gated repo.
@@ -8224,8 +8249,11 @@ class HfApi:
8224
8249
  repo_type (`str`, *optional*):
8225
8250
  The type of the repo to cancel access request for. Must be one of `model`, `dataset` or `space`.
8226
8251
  Defaults to `model`.
8227
- token (`str`, *optional*):
8228
- A valid authentication token (see https://huggingface.co/settings/token).
8252
+ token (Union[bool, str, None], optional):
8253
+ A valid user access token (string). Defaults to the locally saved
8254
+ token, which is the recommended method for authentication (see
8255
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
8256
+ To disable authentication, pass `False`.
8229
8257
 
8230
8258
  Raises:
8231
8259
  `HTTPError`:
@@ -8244,7 +8272,7 @@ class HfApi:
8244
8272
 
8245
8273
  @validate_hf_hub_args
8246
8274
  def accept_access_request(
8247
- self, repo_id: str, user: str, *, repo_type: Optional[str] = None, token: Optional[str] = None
8275
+ self, repo_id: str, user: str, *, repo_type: Optional[str] = None, token: Union[bool, str, None] = None
8248
8276
  ) -> None:
8249
8277
  """
8250
8278
  Accept an access request from a user for a given gated repo.
@@ -8263,8 +8291,11 @@ class HfApi:
8263
8291
  repo_type (`str`, *optional*):
8264
8292
  The type of the repo to accept access request for. Must be one of `model`, `dataset` or `space`.
8265
8293
  Defaults to `model`.
8266
- token (`str`, *optional*):
8267
- A valid authentication token (see https://huggingface.co/settings/token).
8294
+ token (Union[bool, str, None], optional):
8295
+ A valid user access token (string). Defaults to the locally saved
8296
+ token, which is the recommended method for authentication (see
8297
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
8298
+ To disable authentication, pass `False`.
8268
8299
 
8269
8300
  Raises:
8270
8301
  `HTTPError`:
@@ -8283,7 +8314,7 @@ class HfApi:
8283
8314
 
8284
8315
  @validate_hf_hub_args
8285
8316
  def reject_access_request(
8286
- self, repo_id: str, user: str, *, repo_type: Optional[str] = None, token: Optional[str] = None
8317
+ self, repo_id: str, user: str, *, repo_type: Optional[str] = None, token: Union[bool, str, None] = None
8287
8318
  ) -> None:
8288
8319
  """
8289
8320
  Reject an access request from a user for a given gated repo.
@@ -8302,8 +8333,11 @@ class HfApi:
8302
8333
  repo_type (`str`, *optional*):
8303
8334
  The type of the repo to reject access request for. Must be one of `model`, `dataset` or `space`.
8304
8335
  Defaults to `model`.
8305
- token (`str`, *optional*):
8306
- A valid authentication token (see https://huggingface.co/settings/token).
8336
+ token (Union[bool, str, None], optional):
8337
+ A valid user access token (string). Defaults to the locally saved
8338
+ token, which is the recommended method for authentication (see
8339
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
8340
+ To disable authentication, pass `False`.
8307
8341
 
8308
8342
  Raises:
8309
8343
  `HTTPError`:
@@ -8327,7 +8361,7 @@ class HfApi:
8327
8361
  user: str,
8328
8362
  status: Literal["accepted", "rejected", "pending"],
8329
8363
  repo_type: Optional[str] = None,
8330
- token: Optional[str] = None,
8364
+ token: Union[bool, str, None] = None,
8331
8365
  ) -> None:
8332
8366
  if repo_type not in REPO_TYPES:
8333
8367
  raise ValueError(f"Invalid repo type, must be one of {REPO_TYPES}")
@@ -8343,7 +8377,7 @@ class HfApi:
8343
8377
 
8344
8378
  @validate_hf_hub_args
8345
8379
  def grant_access(
8346
- self, repo_id: str, user: str, *, repo_type: Optional[str] = None, token: Optional[str] = None
8380
+ self, repo_id: str, user: str, *, repo_type: Optional[str] = None, token: Union[bool, str, None] = None
8347
8381
  ) -> None:
8348
8382
  """
8349
8383
  Grant access to a user for a given gated repo.
@@ -8362,8 +8396,11 @@ class HfApi:
8362
8396
  repo_type (`str`, *optional*):
8363
8397
  The type of the repo to grant access to. Must be one of `model`, `dataset` or `space`.
8364
8398
  Defaults to `model`.
8365
- token (`str`, *optional*):
8366
- A valid authentication token (see https://huggingface.co/settings/token).
8399
+ token (Union[bool, str, None], optional):
8400
+ A valid user access token (string). Defaults to the locally saved
8401
+ token, which is the recommended method for authentication (see
8402
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
8403
+ To disable authentication, pass `False`.
8367
8404
 
8368
8405
  Raises:
8369
8406
  `HTTPError`:
@@ -8395,7 +8432,7 @@ class HfApi:
8395
8432
 
8396
8433
  def _build_hf_headers(
8397
8434
  self,
8398
- token: Optional[Union[bool, str]] = None,
8435
+ token: Union[bool, str, None] = None,
8399
8436
  is_write_action: bool = False,
8400
8437
  library_name: Optional[str] = None,
8401
8438
  library_version: Optional[str] = None,
@@ -8422,9 +8459,9 @@ class HfApi:
8422
8459
  repo_id: str,
8423
8460
  repo_type: Optional[str],
8424
8461
  revision: Optional[str],
8425
- token: Optional[str],
8426
8462
  path_in_repo: str,
8427
8463
  delete_patterns: Optional[Union[List[str], str]],
8464
+ token: Union[bool, str, None] = None,
8428
8465
  ) -> List[CommitOperationDelete]:
8429
8466
  """Generate the list of Delete operations for a commit to delete files from a repo.
8430
8467
 
@@ -8457,6 +8494,98 @@ class HfApi:
8457
8494
  if relpath_to_abspath[relpath] != ".gitattributes"
8458
8495
  ]
8459
8496
 
8497
+ def get_user_overview(self, username: str) -> User:
8498
+ """
8499
+ Get an overview of a user on the Hub.
8500
+
8501
+ Args:
8502
+ username (`str`):
8503
+ Username of the user to get an overview of.
8504
+
8505
+ Returns:
8506
+ `User`: A [`User`] object with the user's overview.
8507
+
8508
+ Raises:
8509
+ `HTTPError`:
8510
+ HTTP 404 If the user does not exist on the Hub.
8511
+ """
8512
+ r = get_session().get(f"{ENDPOINT}/api/users/{username}/overview")
8513
+
8514
+ hf_raise_for_status(r)
8515
+ return User(**r.json())
8516
+
8517
+ def list_organization_members(self, organization: str) -> Iterable[User]:
8518
+ """
8519
+ List of members of an organization on the Hub.
8520
+
8521
+ Args:
8522
+ organization (`str`):
8523
+ Name of the organization to get the members of.
8524
+
8525
+ Returns:
8526
+ `Iterable[User]`: A list of [`User`] objects with the members of the organization.
8527
+
8528
+ Raises:
8529
+ `HTTPError`:
8530
+ HTTP 404 If the organization does not exist on the Hub.
8531
+
8532
+ """
8533
+
8534
+ r = get_session().get(f"{ENDPOINT}/api/organizations/{organization}/members")
8535
+
8536
+ hf_raise_for_status(r)
8537
+
8538
+ for member in r.json():
8539
+ yield User(**member)
8540
+
8541
+ def list_user_followers(self, username: str) -> Iterable[User]:
8542
+ """
8543
+ Get the list of followers of a user on the Hub.
8544
+
8545
+ Args:
8546
+ username (`str`):
8547
+ Username of the user to get the followers of.
8548
+
8549
+ Returns:
8550
+ `Iterable[User]`: A list of [`User`] objects with the followers of the user.
8551
+
8552
+ Raises:
8553
+ `HTTPError`:
8554
+ HTTP 404 If the user does not exist on the Hub.
8555
+
8556
+ """
8557
+
8558
+ r = get_session().get(f"{ENDPOINT}/api/users/{username}/followers")
8559
+
8560
+ hf_raise_for_status(r)
8561
+
8562
+ for follower in r.json():
8563
+ yield User(**follower)
8564
+
8565
+ def list_user_following(self, username: str) -> Iterable[User]:
8566
+ """
8567
+ Get the list of users followed by a user on the Hub.
8568
+
8569
+ Args:
8570
+ username (`str`):
8571
+ Username of the user to get the users followed by.
8572
+
8573
+ Returns:
8574
+ `Iterable[User]`: A list of [`User`] objects with the users followed by the user.
8575
+
8576
+ Raises:
8577
+ `HTTPError`:
8578
+ HTTP 404 If the user does not exist on the Hub.
8579
+
8580
+ """
8581
+
8582
+ r = get_session().get(f"{ENDPOINT}/api/users/{username}/following")
8583
+
8584
+ hf_raise_for_status(r)
8585
+
8586
+ for followed_user in r.json():
8587
+ yield User(**followed_user)
8588
+
8460
8589
 
8461
8590
  def _prepare_upload_folder_additions(
8462
8591
  folder_path: Union[str, Path],
@@ -8530,7 +8659,6 @@ repo_info = api.repo_info
8530
8659
  list_repo_files = api.list_repo_files
8531
8660
  list_repo_refs = api.list_repo_refs
8532
8661
  list_repo_commits = api.list_repo_commits
8533
- list_files_info = api.list_files_info
8534
8662
  list_repo_tree = api.list_repo_tree
8535
8663
  get_paths_info = api.get_paths_info
8536
8664
 
@@ -8625,3 +8753,9 @@ cancel_access_request = api.cancel_access_request
8625
8753
  accept_access_request = api.accept_access_request
8626
8754
  reject_access_request = api.reject_access_request
8627
8755
  grant_access = api.grant_access
8756
+
8757
+ # User API
8758
+ get_user_overview = api.get_user_overview
8759
+ list_organization_members = api.list_organization_members
8760
+ list_user_followers = api.list_user_followers
8761
+ list_user_following = api.list_user_following