huggingface-hub 0.35.3__py3-none-any.whl → 0.36.0rc0__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 (42) hide show
  1. huggingface_hub/__init__.py +7 -1
  2. huggingface_hub/_commit_api.py +125 -65
  3. huggingface_hub/_commit_scheduler.py +4 -7
  4. huggingface_hub/_jobs_api.py +1 -1
  5. huggingface_hub/_login.py +9 -15
  6. huggingface_hub/_tensorboard_logger.py +2 -5
  7. huggingface_hub/_webhooks_server.py +9 -21
  8. huggingface_hub/cli/download.py +2 -2
  9. huggingface_hub/cli/repo_files.py +1 -1
  10. huggingface_hub/cli/upload.py +1 -1
  11. huggingface_hub/cli/upload_large_folder.py +1 -1
  12. huggingface_hub/community.py +16 -8
  13. huggingface_hub/fastai_utils.py +22 -32
  14. huggingface_hub/file_download.py +17 -20
  15. huggingface_hub/hf_api.py +514 -541
  16. huggingface_hub/hf_file_system.py +45 -40
  17. huggingface_hub/inference/_client.py +28 -49
  18. huggingface_hub/inference/_generated/_async_client.py +28 -49
  19. huggingface_hub/inference/_generated/types/image_to_image.py +6 -2
  20. huggingface_hub/inference/_mcp/agent.py +2 -5
  21. huggingface_hub/inference/_mcp/mcp_client.py +2 -5
  22. huggingface_hub/inference/_providers/__init__.py +5 -0
  23. huggingface_hub/inference/_providers/_common.py +1 -0
  24. huggingface_hub/inference/_providers/clarifai.py +13 -0
  25. huggingface_hub/keras_mixin.py +3 -6
  26. huggingface_hub/lfs.py +12 -4
  27. huggingface_hub/repocard.py +12 -16
  28. huggingface_hub/repository.py +15 -21
  29. huggingface_hub/serialization/_base.py +3 -6
  30. huggingface_hub/serialization/_tensorflow.py +3 -6
  31. huggingface_hub/serialization/_torch.py +17 -35
  32. huggingface_hub/utils/_cache_manager.py +41 -71
  33. huggingface_hub/utils/_chunk_utils.py +2 -3
  34. huggingface_hub/utils/_http.py +29 -34
  35. huggingface_hub/utils/_validators.py +2 -2
  36. huggingface_hub/utils/logging.py +8 -11
  37. {huggingface_hub-0.35.3.dist-info → huggingface_hub-0.36.0rc0.dist-info}/METADATA +2 -2
  38. {huggingface_hub-0.35.3.dist-info → huggingface_hub-0.36.0rc0.dist-info}/RECORD +42 -41
  39. {huggingface_hub-0.35.3.dist-info → huggingface_hub-0.36.0rc0.dist-info}/LICENSE +0 -0
  40. {huggingface_hub-0.35.3.dist-info → huggingface_hub-0.36.0rc0.dist-info}/WHEEL +0 -0
  41. {huggingface_hub-0.35.3.dist-info → huggingface_hub-0.36.0rc0.dist-info}/entry_points.txt +0 -0
  42. {huggingface_hub-0.35.3.dist-info → huggingface_hub-0.36.0rc0.dist-info}/top_level.txt +0 -0
huggingface_hub/hf_api.py CHANGED
@@ -15,7 +15,6 @@
15
15
  from __future__ import annotations
16
16
 
17
17
  import inspect
18
- import io
19
18
  import json
20
19
  import re
21
20
  import struct
@@ -46,7 +45,7 @@ from typing import (
46
45
  Union,
47
46
  overload,
48
47
  )
49
- from urllib.parse import quote, unquote
48
+ from urllib.parse import quote
50
49
 
51
50
  import requests
52
51
  from requests.exceptions import HTTPError
@@ -62,12 +61,11 @@ from ._commit_api import (
62
61
  _fetch_files_to_copy,
63
62
  _fetch_upload_modes,
64
63
  _prepare_commit_payload,
65
- _upload_lfs_files,
66
- _upload_xet_files,
64
+ _upload_files,
67
65
  _warn_on_overwriting_operations,
68
66
  )
69
67
  from ._inference_endpoints import InferenceEndpoint, InferenceEndpointType
70
- from ._jobs_api import JobInfo, ScheduledJobInfo, _create_job_spec
68
+ from ._jobs_api import JobInfo, JobSpec, ScheduledJobInfo, _create_job_spec
71
69
  from ._space_api import SpaceHardware, SpaceRuntime, SpaceStorage, SpaceVariable
72
70
  from ._upload_large_folder import upload_large_folder_internal
73
71
  from .community import (
@@ -132,13 +130,8 @@ from .utils import (
132
130
  validate_hf_hub_args,
133
131
  )
134
132
  from .utils import tqdm as hf_tqdm
135
- from .utils._auth import (
136
- _get_token_from_environment,
137
- _get_token_from_file,
138
- _get_token_from_google_colab,
139
- )
133
+ from .utils._auth import _get_token_from_environment, _get_token_from_file, _get_token_from_google_colab
140
134
  from .utils._deprecation import _deprecate_arguments, _deprecate_method
141
- from .utils._runtime import is_xet_available
142
135
  from .utils._typing import CallableT
143
136
  from .utils.endpoint_helpers import _is_emission_within_threshold
144
137
 
@@ -510,11 +503,15 @@ class WebhookWatchedItem:
510
503
  class WebhookInfo:
511
504
  """Data structure containing information about a webhook.
512
505
 
506
+ One of `url` or `job` is specified, but not both.
507
+
513
508
  Attributes:
514
509
  id (`str`):
515
510
  ID of the webhook.
516
- url (`str`):
511
+ url (`str`, *optional*):
517
512
  URL of the webhook.
513
+ job (`JobSpec`, *optional*):
514
+ Specifications of the Job to trigger.
518
515
  watched (`List[WebhookWatchedItem]`):
519
516
  List of items watched by the webhook, see [`WebhookWatchedItem`].
520
517
  domains (`List[WEBHOOK_DOMAIN_T]`):
@@ -526,7 +523,8 @@ class WebhookInfo:
526
523
  """
527
524
 
528
525
  id: str
529
- url: str
526
+ url: Optional[str]
527
+ job: Optional[JobSpec]
530
528
  watched: List[WebhookWatchedItem]
531
529
  domains: List[constants.WEBHOOK_DOMAIN_T]
532
530
  secret: Optional[str]
@@ -599,15 +597,12 @@ class RepoSibling:
599
597
  """
600
598
  Contains basic information about a repo file inside a repo on the Hub.
601
599
 
602
- <Tip>
603
-
604
- All attributes of this class are optional except `rfilename`. This is because only the file names are returned when
605
- listing repositories on the Hub (with [`list_models`], [`list_datasets`] or [`list_spaces`]). If you need more
606
- information like file size, blob id or lfs details, you must request them specifically from one repo at a time
607
- (using [`model_info`], [`dataset_info`] or [`space_info`]) as it adds more constraints on the backend server to
608
- retrieve these.
609
-
610
- </Tip>
600
+ > [!TIP]
601
+ > All attributes of this class are optional except `rfilename`. This is because only the file names are returned when
602
+ > listing repositories on the Hub (with [`list_models`], [`list_datasets`] or [`list_spaces`]). If you need more
603
+ > information like file size, blob id or lfs details, you must request them specifically from one repo at a time
604
+ > (using [`model_info`], [`dataset_info`] or [`space_info`]) as it adds more constraints on the backend server to
605
+ > retrieve these.
611
606
 
612
607
  Attributes:
613
608
  rfilename (str):
@@ -748,13 +743,10 @@ class ModelInfo:
748
743
  """
749
744
  Contains information about a model on the Hub. This object is returned by [`model_info`] and [`list_models`].
750
745
 
751
- <Tip>
752
-
753
- Most attributes of this class are optional. This is because the data returned by the Hub depends on the query made.
754
- In general, the more specific the query, the more information is returned. On the contrary, when listing models
755
- using [`list_models`] only a subset of the attributes are returned.
756
-
757
- </Tip>
746
+ > [!TIP]
747
+ > Most attributes of this class are optional. This is because the data returned by the Hub depends on the query made.
748
+ > In general, the more specific the query, the more information is returned. On the contrary, when listing models
749
+ > using [`list_models`] only a subset of the attributes are returned.
758
750
 
759
751
  Attributes:
760
752
  id (`str`):
@@ -947,13 +939,10 @@ class DatasetInfo:
947
939
  """
948
940
  Contains information about a dataset on the Hub. This object is returned by [`dataset_info`] and [`list_datasets`].
949
941
 
950
- <Tip>
951
-
952
- Most attributes of this class are optional. This is because the data returned by the Hub depends on the query made.
953
- In general, the more specific the query, the more information is returned. On the contrary, when listing datasets
954
- using [`list_datasets`] only a subset of the attributes are returned.
955
-
956
- </Tip>
942
+ > [!TIP]
943
+ > Most attributes of this class are optional. This is because the data returned by the Hub depends on the query made.
944
+ > In general, the more specific the query, the more information is returned. On the contrary, when listing datasets
945
+ > using [`list_datasets`] only a subset of the attributes are returned.
957
946
 
958
947
  Attributes:
959
948
  id (`str`):
@@ -1066,13 +1055,10 @@ class SpaceInfo:
1066
1055
  """
1067
1056
  Contains information about a Space on the Hub. This object is returned by [`space_info`] and [`list_spaces`].
1068
1057
 
1069
- <Tip>
1070
-
1071
- Most attributes of this class are optional. This is because the data returned by the Hub depends on the query made.
1072
- In general, the more specific the query, the more information is returned. On the contrary, when listing spaces
1073
- using [`list_spaces`] only a subset of the attributes are returned.
1074
-
1075
- </Tip>
1058
+ > [!TIP]
1059
+ > Most attributes of this class are optional. This is because the data returned by the Hub depends on the query made.
1060
+ > In general, the more specific the query, the more information is returned. On the contrary, when listing spaces
1061
+ > using [`list_spaces`] only a subset of the attributes are returned.
1076
1062
 
1077
1063
  Attributes:
1078
1064
  id (`str`):
@@ -1418,16 +1404,48 @@ class Organization:
1418
1404
  Name of the organization on the Hub (unique).
1419
1405
  fullname (`str`):
1420
1406
  Organization's full name.
1407
+ details (`str`, *optional*):
1408
+ Organization's description.
1409
+ is_verified (`bool`, *optional*):
1410
+ Whether the organization is verified.
1411
+ is_following (`bool`, *optional*):
1412
+ Whether the authenticated user follows this organization.
1413
+ num_users (`int`, *optional*):
1414
+ Number of members in the organization.
1415
+ num_models (`int`, *optional*):
1416
+ Number of models owned by the organization.
1417
+ num_spaces (`int`, *optional*):
1418
+ Number of Spaces owned by the organization.
1419
+ num_datasets (`int`, *optional*):
1420
+ Number of datasets owned by the organization.
1421
+ num_followers (`int`, *optional*):
1422
+ Number of followers of the organization.
1421
1423
  """
1422
1424
 
1423
1425
  avatar_url: str
1424
1426
  name: str
1425
1427
  fullname: str
1428
+ details: Optional[str] = None
1429
+ is_verified: Optional[bool] = None
1430
+ is_following: Optional[bool] = None
1431
+ num_users: Optional[int] = None
1432
+ num_models: Optional[int] = None
1433
+ num_spaces: Optional[int] = None
1434
+ num_datasets: Optional[int] = None
1435
+ num_followers: Optional[int] = None
1426
1436
 
1427
1437
  def __init__(self, **kwargs) -> None:
1428
1438
  self.avatar_url = kwargs.pop("avatarUrl", "")
1429
1439
  self.name = kwargs.pop("name", "")
1430
1440
  self.fullname = kwargs.pop("fullname", "")
1441
+ self.details = kwargs.pop("details", None)
1442
+ self.is_verified = kwargs.pop("isVerified", None)
1443
+ self.is_following = kwargs.pop("isFollowing", None)
1444
+ self.num_users = kwargs.pop("numUsers", None)
1445
+ self.num_models = kwargs.pop("numModels", None)
1446
+ self.num_spaces = kwargs.pop("numSpaces", None)
1447
+ self.num_datasets = kwargs.pop("numDatasets", None)
1448
+ self.num_followers = kwargs.pop("numFollowers", None)
1431
1449
 
1432
1450
  # forward compatibility
1433
1451
  self.__dict__.update(**kwargs)
@@ -1684,7 +1702,7 @@ class HfApi:
1684
1702
  Args:
1685
1703
  endpoint (`str`, *optional*):
1686
1704
  Endpoint of the Hub. Defaults to <https://huggingface.co>.
1687
- token (Union[bool, str, None], optional):
1705
+ token (`bool` or `str`, *optional*):
1688
1706
  A valid user access token (string). Defaults to the locally saved
1689
1707
  token, which is the recommended method for authentication (see
1690
1708
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -1766,7 +1784,7 @@ class HfApi:
1766
1784
  Call HF API to know "whoami".
1767
1785
 
1768
1786
  Args:
1769
- token (Union[bool, str, None], optional):
1787
+ token (`bool` or `str`, *optional*):
1770
1788
  A valid user access token (string). Defaults to the locally saved
1771
1789
  token, which is the recommended method for authentication (see
1772
1790
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -1811,18 +1829,15 @@ class HfApi:
1811
1829
  """
1812
1830
  Check if a given `token` is valid and return its permissions.
1813
1831
 
1814
- <Tip warning={true}>
1815
-
1816
- This method is deprecated and will be removed in version 1.0. Permissions are more complex than when
1817
- `get_token_permission` was first introduced. OAuth and fine-grain tokens allows for more detailed permissions.
1818
- If you need to know the permissions associated with a token, please use `whoami` and check the `'auth'` key.
1819
-
1820
- </Tip>
1832
+ > [!WARNING]
1833
+ > This method is deprecated and will be removed in version 1.0. Permissions are more complex than when
1834
+ > `get_token_permission` was first introduced. OAuth and fine-grain tokens allows for more detailed permissions.
1835
+ > If you need to know the permissions associated with a token, please use `whoami` and check the `'auth'` key.
1821
1836
 
1822
1837
  For more details about tokens, please refer to https://huggingface.co/docs/hub/security-tokens#what-are-user-access-tokens.
1823
1838
 
1824
1839
  Args:
1825
- token (Union[bool, str, None], optional):
1840
+ token (`bool` or `str`, *optional*):
1826
1841
  A valid user access token (string). Defaults to the locally saved
1827
1842
  token, which is the recommended method for authentication (see
1828
1843
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -1957,7 +1972,7 @@ class HfApi:
1957
1972
  fetch_config (`bool`, *optional*):
1958
1973
  Whether to fetch the model configs as well. This is not included
1959
1974
  in `full` due to its size.
1960
- token (Union[bool, str, None], optional):
1975
+ token (`bool` or `str`, *optional*):
1961
1976
  A valid user access token (string). Defaults to the locally saved
1962
1977
  token, which is the recommended method for authentication (see
1963
1978
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -2173,7 +2188,7 @@ class HfApi:
2173
2188
  Whether to fetch all dataset data, including the `last_modified`,
2174
2189
  the `card_data` and the files. Can contain useful information such as the
2175
2190
  PapersWithCode ID.
2176
- token (Union[bool, str, None], optional):
2191
+ token (`bool` or `str`, *optional*):
2177
2192
  A valid user access token (string). Defaults to the locally saved
2178
2193
  token, which is the recommended method for authentication (see
2179
2194
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -2350,7 +2365,7 @@ class HfApi:
2350
2365
  full (`bool`, *optional*):
2351
2366
  Whether to fetch all Spaces data, including the `last_modified`, `siblings`
2352
2367
  and `card_data` fields.
2353
- token (Union[bool, str, None], optional):
2368
+ token (`bool` or `str`, *optional*):
2354
2369
  A valid user access token (string). Defaults to the locally saved
2355
2370
  token, which is the recommended method for authentication (see
2356
2371
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -2425,7 +2440,7 @@ class HfApi:
2425
2440
  repo_id (`str`):
2426
2441
  The repository to unlike. Example: `"user/my-cool-model"`.
2427
2442
 
2428
- token (Union[bool, str, None], optional):
2443
+ token (`bool` or `str`, *optional*):
2429
2444
  A valid user access token (string). Defaults to the locally saved
2430
2445
  token, which is the recommended method for authentication (see
2431
2446
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -2475,7 +2490,7 @@ class HfApi:
2475
2490
  Args:
2476
2491
  user (`str`, *optional*):
2477
2492
  Name of the user for which you want to fetch the likes.
2478
- token (Union[bool, str, None], optional):
2493
+ token (`bool` or `str`, *optional*):
2479
2494
  A valid user access token (string). Defaults to the locally saved
2480
2495
  token, which is the recommended method for authentication (see
2481
2496
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -2550,7 +2565,7 @@ class HfApi:
2550
2565
  repo_id (`str`):
2551
2566
  The repository to retrieve . Example: `"user/my-cool-model"`.
2552
2567
 
2553
- token (Union[bool, str, None], optional):
2568
+ token (`bool` or `str`, *optional*):
2554
2569
  A valid user access token (string). Defaults to the locally saved
2555
2570
  token, which is the recommended method for authentication (see
2556
2571
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -2608,7 +2623,7 @@ class HfApi:
2608
2623
  List properties to return in the response. When used, only the properties in the list will be returned.
2609
2624
  This parameter cannot be used if `securityStatus` or `files_metadata` are passed.
2610
2625
  Possible values are `"author"`, `"baseModels"`, `"cardData"`, `"childrenModelCount"`, `"config"`, `"createdAt"`, `"disabled"`, `"downloads"`, `"downloadsAllTime"`, `"gated"`, `"gguf"`, `"inference"`, `"inferenceProviderMapping"`, `"lastModified"`, `"library_name"`, `"likes"`, `"mask_token"`, `"model-index"`, `"pipeline_tag"`, `"private"`, `"safetensors"`, `"sha"`, `"siblings"`, `"spaces"`, `"tags"`, `"transformersInfo"`, `"trendingScore"`, `"widgetData"`, `"usedStorage"`, `"resourceGroup"` and `"xetEnabled"`.
2611
- token (Union[bool, str, None], optional):
2626
+ token (`bool` or `str`, *optional*):
2612
2627
  A valid user access token (string). Defaults to the locally saved
2613
2628
  token, which is the recommended method for authentication (see
2614
2629
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -2617,17 +2632,14 @@ class HfApi:
2617
2632
  Returns:
2618
2633
  [`huggingface_hub.hf_api.ModelInfo`]: The model repository information.
2619
2634
 
2620
- <Tip>
2621
-
2622
- Raises the following errors:
2623
-
2624
- - [`~utils.RepositoryNotFoundError`]
2625
- If the repository to download from cannot be found. This may be because it doesn't exist,
2626
- or because it is set to `private` and you do not have access.
2627
- - [`~utils.RevisionNotFoundError`]
2628
- If the revision to download from cannot be found.
2629
-
2630
- </Tip>
2635
+ > [!TIP]
2636
+ > Raises the following errors:
2637
+ >
2638
+ > - [`~utils.RepositoryNotFoundError`]
2639
+ > If the repository to download from cannot be found. This may be because it doesn't exist,
2640
+ > or because it is set to `private` and you do not have access.
2641
+ > - [`~utils.RevisionNotFoundError`]
2642
+ > If the revision to download from cannot be found.
2631
2643
  """
2632
2644
  if expand and (securityStatus or files_metadata):
2633
2645
  raise ValueError("`expand` cannot be used if `securityStatus` or `files_metadata` are set.")
@@ -2682,7 +2694,7 @@ class HfApi:
2682
2694
  List properties to return in the response. When used, only the properties in the list will be returned.
2683
2695
  This parameter cannot be used if `files_metadata` is passed.
2684
2696
  Possible values are `"author"`, `"cardData"`, `"citation"`, `"createdAt"`, `"disabled"`, `"description"`, `"downloads"`, `"downloadsAllTime"`, `"gated"`, `"lastModified"`, `"likes"`, `"paperswithcode_id"`, `"private"`, `"siblings"`, `"sha"`, `"tags"`, `"trendingScore"`,`"usedStorage"`, `"resourceGroup"` and `"xetEnabled"`.
2685
- token (Union[bool, str, None], optional):
2697
+ token (`bool` or `str`, *optional*):
2686
2698
  A valid user access token (string). Defaults to the locally saved
2687
2699
  token, which is the recommended method for authentication (see
2688
2700
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -2691,17 +2703,14 @@ class HfApi:
2691
2703
  Returns:
2692
2704
  [`hf_api.DatasetInfo`]: The dataset repository information.
2693
2705
 
2694
- <Tip>
2695
-
2696
- Raises the following errors:
2697
-
2698
- - [`~utils.RepositoryNotFoundError`]
2699
- If the repository to download from cannot be found. This may be because it doesn't exist,
2700
- or because it is set to `private` and you do not have access.
2701
- - [`~utils.RevisionNotFoundError`]
2702
- If the revision to download from cannot be found.
2703
-
2704
- </Tip>
2706
+ > [!TIP]
2707
+ > Raises the following errors:
2708
+ >
2709
+ > - [`~utils.RepositoryNotFoundError`]
2710
+ > If the repository to download from cannot be found. This may be because it doesn't exist,
2711
+ > or because it is set to `private` and you do not have access.
2712
+ > - [`~utils.RevisionNotFoundError`]
2713
+ > If the revision to download from cannot be found.
2705
2714
  """
2706
2715
  if expand and files_metadata:
2707
2716
  raise ValueError("`expand` cannot be used if `files_metadata` is set.")
@@ -2755,7 +2764,7 @@ class HfApi:
2755
2764
  List properties to return in the response. When used, only the properties in the list will be returned.
2756
2765
  This parameter cannot be used if `full` is passed.
2757
2766
  Possible values are `"author"`, `"cardData"`, `"createdAt"`, `"datasets"`, `"disabled"`, `"lastModified"`, `"likes"`, `"models"`, `"private"`, `"runtime"`, `"sdk"`, `"siblings"`, `"sha"`, `"subdomain"`, `"tags"`, `"trendingScore"`, `"usedStorage"`, `"resourceGroup"` and `"xetEnabled"`.
2758
- token (Union[bool, str, None], optional):
2767
+ token (`bool` or `str`, *optional*):
2759
2768
  A valid user access token (string). Defaults to the locally saved
2760
2769
  token, which is the recommended method for authentication (see
2761
2770
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -2764,17 +2773,14 @@ class HfApi:
2764
2773
  Returns:
2765
2774
  [`~hf_api.SpaceInfo`]: The space repository information.
2766
2775
 
2767
- <Tip>
2768
-
2769
- Raises the following errors:
2770
-
2771
- - [`~utils.RepositoryNotFoundError`]
2772
- If the repository to download from cannot be found. This may be because it doesn't exist,
2773
- or because it is set to `private` and you do not have access.
2774
- - [`~utils.RevisionNotFoundError`]
2775
- If the revision to download from cannot be found.
2776
-
2777
- </Tip>
2776
+ > [!TIP]
2777
+ > Raises the following errors:
2778
+ >
2779
+ > - [`~utils.RepositoryNotFoundError`]
2780
+ > If the repository to download from cannot be found. This may be because it doesn't exist,
2781
+ > or because it is set to `private` and you do not have access.
2782
+ > - [`~utils.RevisionNotFoundError`]
2783
+ > If the revision to download from cannot be found.
2778
2784
  """
2779
2785
  if expand and files_metadata:
2780
2786
  raise ValueError("`expand` cannot be used if `files_metadata` is set.")
@@ -2830,7 +2836,7 @@ class HfApi:
2830
2836
  files_metadata (`bool`, *optional*):
2831
2837
  Whether or not to retrieve metadata for files in the repository
2832
2838
  (size, LFS metadata, etc). Defaults to `False`.
2833
- token (Union[bool, str, None], optional):
2839
+ token (`bool` or `str`, *optional*):
2834
2840
  A valid user access token (string). Defaults to the locally saved
2835
2841
  token, which is the recommended method for authentication (see
2836
2842
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -2841,17 +2847,14 @@ class HfApi:
2841
2847
  [`huggingface_hub.hf_api.DatasetInfo`], [`huggingface_hub.hf_api.ModelInfo`]
2842
2848
  or [`huggingface_hub.hf_api.SpaceInfo`] object.
2843
2849
 
2844
- <Tip>
2845
-
2846
- Raises the following errors:
2847
-
2848
- - [`~utils.RepositoryNotFoundError`]
2849
- If the repository to download from cannot be found. This may be because it doesn't exist,
2850
- or because it is set to `private` and you do not have access.
2851
- - [`~utils.RevisionNotFoundError`]
2852
- If the revision to download from cannot be found.
2853
-
2854
- </Tip>
2850
+ > [!TIP]
2851
+ > Raises the following errors:
2852
+ >
2853
+ > - [`~utils.RepositoryNotFoundError`]
2854
+ > If the repository to download from cannot be found. This may be because it doesn't exist,
2855
+ > or because it is set to `private` and you do not have access.
2856
+ > - [`~utils.RevisionNotFoundError`]
2857
+ > If the revision to download from cannot be found.
2855
2858
  """
2856
2859
  if repo_type is None or repo_type == "model":
2857
2860
  method = self.model_info
@@ -2888,7 +2891,7 @@ class HfApi:
2888
2891
  repo_type (`str`, *optional*):
2889
2892
  Set to `"dataset"` or `"space"` if getting repository info from a dataset or a space,
2890
2893
  `None` or `"model"` if getting repository info from a model. Default is `None`.
2891
- token (Union[bool, str, None], optional):
2894
+ token (`bool` or `str`, *optional*):
2892
2895
  A valid user access token (string). Defaults to the locally saved
2893
2896
  token, which is the recommended method for authentication (see
2894
2897
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -2935,7 +2938,7 @@ class HfApi:
2935
2938
  repo_type (`str`, *optional*):
2936
2939
  Set to `"dataset"` or `"space"` if getting repository info from a dataset or a space,
2937
2940
  `None` or `"model"` if getting repository info from a model. Default is `None`.
2938
- token (Union[bool, str, None], optional):
2941
+ token (`bool` or `str`, *optional*):
2939
2942
  A valid user access token (string). Defaults to the locally saved
2940
2943
  token, which is the recommended method for authentication (see
2941
2944
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -2986,7 +2989,7 @@ class HfApi:
2986
2989
  `None` or `"model"` if getting repository info from a model. Default is `None`.
2987
2990
  revision (`str`, *optional*):
2988
2991
  The revision of the repository from which to get the information. Defaults to `"main"` branch.
2989
- token (Union[bool, str, None], optional):
2992
+ token (`bool` or `str`, *optional*):
2990
2993
  A valid user access token (string). Defaults to the locally saved
2991
2994
  token, which is the recommended method for authentication (see
2992
2995
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -3039,7 +3042,7 @@ class HfApi:
3039
3042
  repo_type (`str`, *optional*):
3040
3043
  Set to `"dataset"` or `"space"` if uploading to a dataset or space, `None` or `"model"` if uploading to
3041
3044
  a model. Default is `None`.
3042
- token (Union[bool, str, None], optional):
3045
+ token (`bool` or `str`, *optional*):
3043
3046
  A valid user access token (string). Defaults to the locally saved
3044
3047
  token, which is the recommended method for authentication (see
3045
3048
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -3089,7 +3092,7 @@ class HfApi:
3089
3092
  repo_type (`str`, *optional*):
3090
3093
  The type of the repository from which to get the tree (`"model"`, `"dataset"` or `"space"`.
3091
3094
  Defaults to `"model"`.
3092
- token (Union[bool, str, None], optional):
3095
+ token (`bool` or `str`, *optional*):
3093
3096
  A valid user access token (string). Defaults to the locally saved
3094
3097
  token, which is the recommended method for authentication (see
3095
3098
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -3209,7 +3212,7 @@ class HfApi:
3209
3212
  `None` or `"model"` if listing from a model. Default is `None`.
3210
3213
  include_pull_requests (`bool`, *optional*):
3211
3214
  Whether to include refs from pull requests in the list. Defaults to `False`.
3212
- token (Union[bool, str, None], optional):
3215
+ token (`bool` or `str`, *optional*):
3213
3216
  A valid user access token (string). Defaults to the locally saved
3214
3217
  token, which is the recommended method for authentication (see
3215
3218
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -3281,7 +3284,7 @@ class HfApi:
3281
3284
  repo_type (`str`, *optional*):
3282
3285
  Set to `"dataset"` or `"space"` if listing commits from a dataset or a Space, `None` or `"model"` if
3283
3286
  listing from a model. Default is `None`.
3284
- token (Union[bool, str, None], optional):
3287
+ token (`bool` or `str`, *optional*):
3285
3288
  A valid user access token (string). Defaults to the locally saved
3286
3289
  token, which is the recommended method for authentication (see
3287
3290
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -3376,7 +3379,7 @@ class HfApi:
3376
3379
  repo_type (`str`, *optional*):
3377
3380
  The type of the repository from which to get the information (`"model"`, `"dataset"` or `"space"`.
3378
3381
  Defaults to `"model"`.
3379
- token (Union[bool, str, None], optional):
3382
+ token (`bool` or `str`, *optional*):
3380
3383
  A valid user access token (string). Defaults to the locally saved
3381
3384
  token, which is the recommended method for authentication (see
3382
3385
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -3438,18 +3441,12 @@ class HfApi:
3438
3441
  Squashing the repo history is useful when you know you'll make hundreds of commits and you don't want to
3439
3442
  clutter the history. Squashing commits can only be performed from the head of a branch.
3440
3443
 
3441
- <Tip warning={true}>
3442
-
3443
- Once squashed, the commit history cannot be retrieved. This is a non-revertible operation.
3444
-
3445
- </Tip>
3444
+ > [!WARNING]
3445
+ > Once squashed, the commit history cannot be retrieved. This is a non-revertible operation.
3446
3446
 
3447
- <Tip warning={true}>
3448
-
3449
- Once the history of a branch has been squashed, it is not possible to merge it back into another branch since
3450
- their history will have diverged.
3451
-
3452
- </Tip>
3447
+ > [!WARNING]
3448
+ > Once the history of a branch has been squashed, it is not possible to merge it back into another branch since
3449
+ > their history will have diverged.
3453
3450
 
3454
3451
  Args:
3455
3452
  repo_id (`str`):
@@ -3461,7 +3458,7 @@ class HfApi:
3461
3458
  repo_type (`str`, *optional*):
3462
3459
  Set to `"dataset"` or `"space"` if listing commits from a dataset or a Space, `None` or `"model"` if
3463
3460
  listing from a model. Default is `None`.
3464
- token (Union[bool, str, None], optional):
3461
+ token (`bool` or `str`, *optional*):
3465
3462
  A valid user access token (string). Defaults to the locally saved
3466
3463
  token, which is the recommended method for authentication (see
3467
3464
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -3530,7 +3527,7 @@ class HfApi:
3530
3527
  repo_type (`str`, *optional*):
3531
3528
  Type of repository. Set to `"dataset"` or `"space"` if listing from a dataset or space, `None` or
3532
3529
  `"model"` if listing from a model. Default is `None`.
3533
- token (Union[bool, str, None], optional):
3530
+ token (`bool` or `str`, *optional*):
3534
3531
  A valid user access token (string). Defaults to the locally saved
3535
3532
  token, which is the recommended method for authentication (see
3536
3533
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -3576,12 +3573,9 @@ class HfApi:
3576
3573
  """
3577
3574
  Permanently delete LFS files from a repo on the Hub.
3578
3575
 
3579
- <Tip warning={true}>
3580
-
3581
- This is a permanent action that will affect all commits referencing the deleted files and might corrupt your
3582
- repository. This is a non-revertible operation. Use it only if you know what you are doing.
3583
-
3584
- </Tip>
3576
+ > [!WARNING]
3577
+ > This is a permanent action that will affect all commits referencing the deleted files and might corrupt your
3578
+ > repository. This is a non-revertible operation. Use it only if you know what you are doing.
3585
3579
 
3586
3580
  Args:
3587
3581
  repo_id (`str`):
@@ -3594,7 +3588,7 @@ class HfApi:
3594
3588
  repo_type (`str`, *optional*):
3595
3589
  Type of repository. Set to `"dataset"` or `"space"` if listing from a dataset or space, `None` or
3596
3590
  `"model"` if listing from a model. Default is `None`.
3597
- token (Union[bool, str, None], optional):
3591
+ token (`bool` or `str`, *optional*):
3598
3592
  A valid user access token (string). Defaults to the locally saved
3599
3593
  token, which is the recommended method for authentication (see
3600
3594
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -3657,7 +3651,7 @@ class HfApi:
3657
3651
  repo_id (`str`):
3658
3652
  A namespace (user or an organization) and a repo name separated
3659
3653
  by a `/`.
3660
- token (Union[bool, str, None], optional):
3654
+ token (`bool` or `str`, *optional*):
3661
3655
  A valid user access token (string). Defaults to the locally saved
3662
3656
  token, which is the recommended method for authentication (see
3663
3657
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -3799,7 +3793,7 @@ class HfApi:
3799
3793
  repo_id (`str`):
3800
3794
  A namespace (user or an organization) and a repo name separated
3801
3795
  by a `/`.
3802
- token (Union[bool, str, None], optional):
3796
+ token (`bool` or `str`, *optional*):
3803
3797
  A valid user access token (string). Defaults to the locally saved
3804
3798
  token, which is the recommended method for authentication (see
3805
3799
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -3852,7 +3846,7 @@ class HfApi:
3852
3846
  A namespace (user or an organization) and a repo name separated by a `/`.
3853
3847
  private (`bool`, *optional*, defaults to `False`):
3854
3848
  Whether the repository should be private.
3855
- token (Union[bool, str, None], optional):
3849
+ token (`bool` or `str`, *optional*):
3856
3850
  A valid user access token (string). Defaults to the locally saved
3857
3851
  token, which is the recommended method for authentication (see
3858
3852
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -3865,15 +3859,12 @@ class HfApi:
3865
3859
  Returns:
3866
3860
  The HTTP response in json.
3867
3861
 
3868
- <Tip>
3869
-
3870
- Raises the following errors:
3871
-
3872
- - [`~utils.RepositoryNotFoundError`]
3873
- If the repository to download from cannot be found. This may be because it doesn't exist,
3874
- or because it is set to `private` and you do not have access.
3875
-
3876
- </Tip>
3862
+ > [!TIP]
3863
+ > Raises the following errors:
3864
+ >
3865
+ > - [`~utils.RepositoryNotFoundError`]
3866
+ > If the repository to download from cannot be found. This may be because it doesn't exist,
3867
+ > or because it is set to `private` and you do not have access.
3877
3868
  """
3878
3869
  if repo_type not in constants.REPO_TYPES:
3879
3870
  raise ValueError(f"Invalid repo type, must be one of {constants.REPO_TYPES}")
@@ -3995,21 +3986,18 @@ class HfApi:
3995
3986
  Set to `"dataset"` or `"space"` if uploading to a dataset or
3996
3987
  space, `None` or `"model"` if uploading to a model. Default is
3997
3988
  `None`.
3998
- token (Union[bool, str, None], optional):
3989
+ token (`bool` or `str`, *optional*):
3999
3990
  A valid user access token (string). Defaults to the locally saved
4000
3991
  token, which is the recommended method for authentication (see
4001
3992
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
4002
3993
  To disable authentication, pass `False`.
4003
3994
 
4004
- <Tip>
4005
-
4006
- Raises the following errors:
4007
-
4008
- - [`~utils.RepositoryNotFoundError`]
4009
- If the repository to download from cannot be found. This may be because it doesn't exist,
4010
- or because it is set to `private` and you do not have access.
4011
-
4012
- </Tip>
3995
+ > [!TIP]
3996
+ > Raises the following errors:
3997
+ >
3998
+ > - [`~utils.RepositoryNotFoundError`]
3999
+ > If the repository to download from cannot be found. This may be because it doesn't exist,
4000
+ > or because it is set to `private` and you do not have access.
4013
4001
  """
4014
4002
  if len(from_id.split("/")) != 2:
4015
4003
  raise ValueError(f"Invalid repo_id: {from_id}. It should have a namespace (:namespace:/:repo_name:)")
@@ -4088,27 +4076,18 @@ class HfApi:
4088
4076
  """
4089
4077
  Creates a commit in the given repo, deleting & uploading files as needed.
4090
4078
 
4091
- <Tip warning={true}>
4092
-
4093
- The input list of `CommitOperation` will be mutated during the commit process. Do not reuse the same objects
4094
- for multiple commits.
4095
-
4096
- </Tip>
4097
-
4098
- <Tip warning={true}>
4099
-
4100
- `create_commit` assumes that the repo already exists on the Hub. If you get a
4101
- Client error 404, please make sure you are authenticated and that `repo_id` and
4102
- `repo_type` are set correctly. If repo does not exist, create it first using
4103
- [`~hf_api.create_repo`].
4079
+ > [!WARNING]
4080
+ > The input list of `CommitOperation` will be mutated during the commit process. Do not reuse the same objects
4081
+ > for multiple commits.
4104
4082
 
4105
- </Tip>
4083
+ > [!WARNING]
4084
+ > `create_commit` assumes that the repo already exists on the Hub. If you get a
4085
+ > Client error 404, please make sure you are authenticated and that `repo_id` and
4086
+ > `repo_type` are set correctly. If repo does not exist, create it first using
4087
+ > [`~hf_api.create_repo`].
4106
4088
 
4107
- <Tip warning={true}>
4108
-
4109
- `create_commit` is limited to 25k LFS files and a 1GB payload for regular files.
4110
-
4111
- </Tip>
4089
+ > [!WARNING]
4090
+ > `create_commit` is limited to 25k LFS files and a 1GB payload for regular files.
4112
4091
 
4113
4092
  Args:
4114
4093
  repo_id (`str`):
@@ -4131,7 +4110,7 @@ class HfApi:
4131
4110
  commit_description (`str`, *optional*):
4132
4111
  The description of the commit that will be created
4133
4112
 
4134
- token (Union[bool, str, None], optional):
4113
+ token (`bool` or `str`, *optional*):
4135
4114
  A valid user access token (string). Defaults to the locally saved
4136
4115
  token, which is the recommended method for authentication (see
4137
4116
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -4382,21 +4361,15 @@ class HfApi:
4382
4361
  This method is useful if you are generating the files to upload on-the-fly and you don't want to store them
4383
4362
  in memory before uploading them all at once.
4384
4363
 
4385
- <Tip warning={true}>
4386
-
4387
- This is a power-user method. You shouldn't need to call it directly to make a normal commit.
4388
- Use [`create_commit`] directly instead.
4389
-
4390
- </Tip>
4364
+ > [!WARNING]
4365
+ > This is a power-user method. You shouldn't need to call it directly to make a normal commit.
4366
+ > Use [`create_commit`] directly instead.
4391
4367
 
4392
- <Tip warning={true}>
4393
-
4394
- Commit operations will be mutated during the process. In particular, the attached `path_or_fileobj` will be
4395
- removed after the upload to save memory (and replaced by an empty `bytes` object). Do not reuse the same
4396
- objects except to pass them to [`create_commit`]. If you don't want to remove the attached content from the
4397
- commit operation object, pass `free_memory=False`.
4398
-
4399
- </Tip>
4368
+ > [!WARNING]
4369
+ > Commit operations will be mutated during the process. In particular, the attached `path_or_fileobj` will be
4370
+ > removed after the upload to save memory (and replaced by an empty `bytes` object). Do not reuse the same
4371
+ > objects except to pass them to [`create_commit`]. If you don't want to remove the attached content from the
4372
+ > commit operation object, pass `free_memory=False`.
4400
4373
 
4401
4374
  Args:
4402
4375
  repo_id (`str`):
@@ -4406,7 +4379,7 @@ class HfApi:
4406
4379
  The list of files to upload. Warning: the objects in this list will be mutated to include information
4407
4380
  relative to the upload. Do not reuse the same objects for multiple commits.
4408
4381
 
4409
- token (Union[bool, str, None], optional):
4382
+ token (`bool` or `str`, *optional*):
4410
4383
  A valid user access token (string). Defaults to the locally saved
4411
4384
  token, which is the recommended method for authentication (see
4412
4385
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -4502,6 +4475,10 @@ class HfApi:
4502
4475
  f"Skipped upload for {len(new_lfs_additions) - len(new_lfs_additions_to_upload)} LFS file(s) "
4503
4476
  "(ignored by gitignore file)."
4504
4477
  )
4478
+ # If no LFS files remain to upload, keep previous behavior and log explicitly
4479
+ if len(new_lfs_additions_to_upload) == 0:
4480
+ logger.debug("No LFS files to upload.")
4481
+ return
4505
4482
  # Prepare upload parameters
4506
4483
  upload_kwargs = {
4507
4484
  "additions": new_lfs_additions_to_upload,
@@ -4514,32 +4491,7 @@ class HfApi:
4514
4491
  # PR (i.e. `revision`).
4515
4492
  "revision": revision if not create_pr else None,
4516
4493
  }
4517
- # Upload files using Xet protocol if all of the following are true:
4518
- # - xet is enabled for the repo,
4519
- # - the files are provided as str or paths objects,
4520
- # - the library is installed.
4521
- # Otherwise, default back to LFS.
4522
- xet_enabled = self.repo_info(
4523
- repo_id=repo_id,
4524
- repo_type=repo_type,
4525
- revision=unquote(revision) if revision is not None else revision,
4526
- expand="xetEnabled",
4527
- token=token,
4528
- ).xet_enabled
4529
- has_buffered_io_data = any(
4530
- isinstance(addition.path_or_fileobj, io.BufferedIOBase) for addition in new_lfs_additions_to_upload
4531
- )
4532
- if xet_enabled and not has_buffered_io_data and is_xet_available():
4533
- logger.debug("Uploading files using Xet Storage..")
4534
- _upload_xet_files(**upload_kwargs, create_pr=create_pr) # type: ignore [arg-type]
4535
- else:
4536
- if xet_enabled and is_xet_available():
4537
- if has_buffered_io_data:
4538
- logger.warning(
4539
- "Uploading files as a binary IO buffer is not supported by Xet Storage. "
4540
- "Falling back to HTTP upload."
4541
- )
4542
- _upload_lfs_files(**upload_kwargs, num_threads=num_threads) # type: ignore [arg-type]
4494
+ _upload_files(**upload_kwargs, num_threads=num_threads, create_pr=create_pr) # type: ignore [arg-type]
4543
4495
  for addition in new_lfs_additions_to_upload:
4544
4496
  addition._is_uploaded = True
4545
4497
  if free_memory:
@@ -4611,7 +4563,7 @@ class HfApi:
4611
4563
  repo_id (`str`):
4612
4564
  The repository to which the file will be uploaded, for example:
4613
4565
  `"username/custom_transformers"`
4614
- token (Union[bool, str, None], optional):
4566
+ token (`bool` or `str`, *optional*):
4615
4567
  A valid user access token (string). Defaults to the locally saved
4616
4568
  token, which is the recommended method for authentication (see
4617
4569
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -4649,30 +4601,24 @@ class HfApi:
4649
4601
  Instance of [`CommitInfo`] containing information about the newly created commit (commit hash, commit
4650
4602
  url, pr url, commit message,...). If `run_as_future=True` is passed, returns a Future object which will
4651
4603
  contain the result when executed.
4652
- <Tip>
4653
-
4654
- Raises the following errors:
4655
-
4656
- - [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError)
4657
- if the HuggingFace API returned an error
4658
- - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
4659
- if some parameter value is invalid
4660
- - [`~utils.RepositoryNotFoundError`]
4661
- If the repository to download from cannot be found. This may be because it doesn't exist,
4662
- or because it is set to `private` and you do not have access.
4663
- - [`~utils.RevisionNotFoundError`]
4664
- If the revision to download from cannot be found.
4665
-
4666
- </Tip>
4667
-
4668
- <Tip warning={true}>
4669
-
4670
- `upload_file` assumes that the repo already exists on the Hub. If you get a
4671
- Client error 404, please make sure you are authenticated and that `repo_id` and
4672
- `repo_type` are set correctly. If repo does not exist, create it first using
4673
- [`~hf_api.create_repo`].
4674
-
4675
- </Tip>
4604
+ > [!TIP]
4605
+ > Raises the following errors:
4606
+ >
4607
+ > - [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError)
4608
+ > if the HuggingFace API returned an error
4609
+ > - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
4610
+ > if some parameter value is invalid
4611
+ > - [`~utils.RepositoryNotFoundError`]
4612
+ > If the repository to download from cannot be found. This may be because it doesn't exist,
4613
+ > or because it is set to `private` and you do not have access.
4614
+ > - [`~utils.RevisionNotFoundError`]
4615
+ > If the revision to download from cannot be found.
4616
+
4617
+ > [!WARNING]
4618
+ > `upload_file` assumes that the repo already exists on the Hub. If you get a
4619
+ > Client error 404, please make sure you are authenticated and that `repo_id` and
4620
+ > `repo_type` are set correctly. If repo does not exist, create it first using
4621
+ > [`~hf_api.create_repo`].
4676
4622
 
4677
4623
  Example:
4678
4624
 
@@ -4839,7 +4785,7 @@ class HfApi:
4839
4785
  path_in_repo (`str`, *optional*):
4840
4786
  Relative path of the directory in the repo, for example:
4841
4787
  `"checkpoints/1fec34a/results"`. Will default to the root folder of the repository.
4842
- token (Union[bool, str, None], optional):
4788
+ token (`bool` or `str`, *optional*):
4843
4789
  A valid user access token (string). Defaults to the locally saved
4844
4790
  token, which is the recommended method for authentication (see
4845
4791
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -4885,30 +4831,21 @@ class HfApi:
4885
4831
  url, pr url, commit message,...). If `run_as_future=True` is passed, returns a Future object which will
4886
4832
  contain the result when executed.
4887
4833
 
4888
- <Tip>
4889
-
4890
- Raises the following errors:
4891
-
4892
- - [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError)
4893
- if the HuggingFace API returned an error
4894
- - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
4895
- if some parameter value is invalid
4896
-
4897
- </Tip>
4898
-
4899
- <Tip warning={true}>
4900
-
4901
- `upload_folder` assumes that the repo already exists on the Hub. If you get a Client error 404, please make
4902
- sure you are authenticated and that `repo_id` and `repo_type` are set correctly. If repo does not exist, create
4903
- it first using [`~hf_api.create_repo`].
4834
+ > [!TIP]
4835
+ > Raises the following errors:
4836
+ >
4837
+ > - [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError)
4838
+ > if the HuggingFace API returned an error
4839
+ > - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
4840
+ > if some parameter value is invalid
4904
4841
 
4905
- </Tip>
4842
+ > [!WARNING]
4843
+ > `upload_folder` assumes that the repo already exists on the Hub. If you get a Client error 404, please make
4844
+ > sure you are authenticated and that `repo_id` and `repo_type` are set correctly. If repo does not exist, create
4845
+ > it first using [`~hf_api.create_repo`].
4906
4846
 
4907
- <Tip>
4908
-
4909
- When dealing with a large folder (thousands of files or hundreds of GB), we recommend using [`~hf_api.upload_large_folder`] instead.
4910
-
4911
- </Tip>
4847
+ > [!TIP]
4848
+ > When dealing with a large folder (thousands of files or hundreds of GB), we recommend using [`~hf_api.upload_large_folder`] instead.
4912
4849
 
4913
4850
  Example:
4914
4851
 
@@ -5044,7 +4981,7 @@ class HfApi:
5044
4981
  repo_id (`str`):
5045
4982
  The repository from which the file will be deleted, for example:
5046
4983
  `"username/custom_transformers"`
5047
- token (Union[bool, str, None], optional):
4984
+ token (`bool` or `str`, *optional*):
5048
4985
  A valid user access token (string). Defaults to the locally saved
5049
4986
  token, which is the recommended method for authentication (see
5050
4987
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -5073,23 +5010,20 @@ class HfApi:
5073
5010
  especially useful if the repo is updated / committed to concurrently.
5074
5011
 
5075
5012
 
5076
- <Tip>
5077
-
5078
- Raises the following errors:
5079
-
5080
- - [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError)
5081
- if the HuggingFace API returned an error
5082
- - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
5083
- if some parameter value is invalid
5084
- - [`~utils.RepositoryNotFoundError`]
5085
- If the repository to download from cannot be found. This may be because it doesn't exist,
5086
- or because it is set to `private` and you do not have access.
5087
- - [`~utils.RevisionNotFoundError`]
5088
- If the revision to download from cannot be found.
5089
- - [`~utils.EntryNotFoundError`]
5090
- If the file to download cannot be found.
5091
-
5092
- </Tip>
5013
+ > [!TIP]
5014
+ > Raises the following errors:
5015
+ >
5016
+ > - [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError)
5017
+ > if the HuggingFace API returned an error
5018
+ > - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
5019
+ > if some parameter value is invalid
5020
+ > - [`~utils.RepositoryNotFoundError`]
5021
+ > If the repository to download from cannot be found. This may be because it doesn't exist,
5022
+ > or because it is set to `private` and you do not have access.
5023
+ > - [`~utils.RevisionNotFoundError`]
5024
+ > If the revision to download from cannot be found.
5025
+ > - [`~utils.EntryNotFoundError`]
5026
+ > If the file to download cannot be found.
5093
5027
 
5094
5028
  """
5095
5029
  commit_message = (
@@ -5138,7 +5072,7 @@ class HfApi:
5138
5072
  List of files or folders to delete. Each string can either be
5139
5073
  a file path, a folder path or a Unix shell-style wildcard.
5140
5074
  E.g. `["file.txt", "folder/", "data/*.parquet"]`
5141
- token (Union[bool, str, None], optional):
5075
+ token (`bool` or `str`, *optional*):
5142
5076
  A valid user access token (string). Defaults to the locally saved
5143
5077
  token, which is the recommended method for authentication (see
5144
5078
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -5211,7 +5145,7 @@ class HfApi:
5211
5145
  repo_id (`str`):
5212
5146
  The repository from which the folder will be deleted, for example:
5213
5147
  `"username/custom_transformers"`
5214
- token (Union[bool, str, None], optional):
5148
+ token (`bool` or `str`, *optional*):
5215
5149
  A valid user access token (string). Defaults to the locally saved
5216
5150
  token, which is the recommended method for authentication (see
5217
5151
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -5306,25 +5240,19 @@ class HfApi:
5306
5240
  print_report_every (`int`, *optional*):
5307
5241
  Frequency at which the report is printed. Defaults to 60 seconds.
5308
5242
 
5309
- <Tip>
5310
-
5311
- A few things to keep in mind:
5312
- - Repository limits still apply: https://huggingface.co/docs/hub/repositories-recommendations
5313
- - Do not start several processes in parallel.
5314
- - You can interrupt and resume the process at any time.
5315
- - Do not upload the same folder to several repositories. If you need to do so, you must delete the local `.cache/.huggingface/` folder first.
5316
-
5317
- </Tip>
5243
+ > [!TIP]
5244
+ > A few things to keep in mind:
5245
+ > - Repository limits still apply: https://huggingface.co/docs/hub/repositories-recommendations
5246
+ > - Do not start several processes in parallel.
5247
+ > - You can interrupt and resume the process at any time.
5248
+ > - Do not upload the same folder to several repositories. If you need to do so, you must delete the local `.cache/.huggingface/` folder first.
5318
5249
 
5319
- <Tip warning={true}>
5320
-
5321
- While being much more robust to upload large folders, `upload_large_folder` is more limited than [`upload_folder`] feature-wise. In practice:
5322
- - you cannot set a custom `path_in_repo`. If you want to upload to a subfolder, you need to set the proper structure locally.
5323
- - you cannot set a custom `commit_message` and `commit_description` since multiple commits are created.
5324
- - you cannot delete from the repo while uploading. Please make a separate commit first.
5325
- - you cannot create a PR directly. Please create a PR first (from the UI or using [`create_pull_request`]) and then commit to it by passing `revision`.
5326
-
5327
- </Tip>
5250
+ > [!WARNING]
5251
+ > While being much more robust to upload large folders, `upload_large_folder` is more limited than [`upload_folder`] feature-wise. In practice:
5252
+ > - you cannot set a custom `path_in_repo`. If you want to upload to a subfolder, you need to set the proper structure locally.
5253
+ > - you cannot set a custom `commit_message` and `commit_description` since multiple commits are created.
5254
+ > - you cannot delete from the repo while uploading. Please make a separate commit first.
5255
+ > - you cannot create a PR directly. Please create a PR first (from the UI or using [`create_pull_request`]) and then commit to it by passing `revision`.
5328
5256
 
5329
5257
  **Technical details:**
5330
5258
 
@@ -5391,7 +5319,7 @@ class HfApi:
5391
5319
  Args:
5392
5320
  url (`str`):
5393
5321
  File url, for example returned by [`hf_hub_url`].
5394
- token (Union[bool, str, None], optional):
5322
+ token (`bool` or `str`, *optional*):
5395
5323
  A valid user access token (string). Defaults to the locally saved
5396
5324
  token, which is the recommended method for authentication (see
5397
5325
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -5501,7 +5429,7 @@ class HfApi:
5501
5429
  etag_timeout (`float`, *optional*, defaults to `10`):
5502
5430
  When fetching ETag, how many seconds to wait for the server to send
5503
5431
  data before giving up which is passed to `requests.request`.
5504
- token (Union[bool, str, None], optional):
5432
+ token (`bool` or `str`, *optional*):
5505
5433
  A valid user access token (string). Defaults to the locally saved
5506
5434
  token, which is the recommended method for authentication (see
5507
5435
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -5617,7 +5545,7 @@ class HfApi:
5617
5545
  data before giving up which is passed to `requests.request`.
5618
5546
  force_download (`bool`, *optional*, defaults to `False`):
5619
5547
  Whether the file should be downloaded even if it already exists in the local cache.
5620
- token (Union[bool, str, None], optional):
5548
+ token (`bool` or `str`, *optional*):
5621
5549
  A valid user access token (string). Defaults to the locally saved
5622
5550
  token, which is the recommended method for authentication (see
5623
5551
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -5712,7 +5640,7 @@ class HfApi:
5712
5640
  revision (`str`, *optional*):
5713
5641
  The git revision to fetch the file from. Can be a branch name, a tag, or a commit hash. Defaults to the
5714
5642
  head of the `"main"` branch.
5715
- token (Union[bool, str, None], optional):
5643
+ token (`bool` or `str`, *optional*):
5716
5644
  A valid user access token (string). Defaults to the locally saved
5717
5645
  token, which is the recommended method for authentication (see
5718
5646
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -5851,7 +5779,7 @@ class HfApi:
5851
5779
  revision (`str`, *optional*):
5852
5780
  The git revision to fetch the file from. Can be a branch name, a tag, or a commit hash. Defaults to the
5853
5781
  head of the `"main"` branch.
5854
- token (Union[bool, str, None], optional):
5782
+ token (`bool` or `str`, *optional*):
5855
5783
  A valid user access token (string). Defaults to the locally saved
5856
5784
  token, which is the recommended method for authentication (see
5857
5785
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -5955,7 +5883,7 @@ class HfApi:
5955
5883
  the OID/SHA of a commit, as a hexadecimal string. Defaults to the head
5956
5884
  of the `"main"` branch.
5957
5885
 
5958
- token (Union[bool, str, None], optional):
5886
+ token (`bool` or `str`, *optional*):
5959
5887
  A valid user access token (string). Defaults to the locally saved
5960
5888
  token, which is the recommended method for authentication (see
5961
5889
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -6027,7 +5955,7 @@ class HfApi:
6027
5955
  branch (`str`):
6028
5956
  The name of the branch to delete.
6029
5957
 
6030
- token (Union[bool, str, None], optional):
5958
+ token (`bool` or `str`, *optional*):
6031
5959
  A valid user access token (string). Defaults to the locally saved
6032
5960
  token, which is the recommended method for authentication (see
6033
5961
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -6090,7 +6018,7 @@ class HfApi:
6090
6018
  commit, as a hexadecimal string. Shorthands (7 first characters) are
6091
6019
  also supported. Defaults to the head of the `"main"` branch.
6092
6020
 
6093
- token (Union[bool, str, None], optional):
6021
+ token (`bool` or `str`, *optional*):
6094
6022
  A valid user access token (string). Defaults to the locally saved
6095
6023
  token, which is the recommended method for authentication (see
6096
6024
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -6153,7 +6081,7 @@ class HfApi:
6153
6081
  tag (`str`):
6154
6082
  The name of the tag to delete.
6155
6083
 
6156
- token (Union[bool, str, None], optional):
6084
+ token (`bool` or `str`, *optional*):
6157
6085
  A valid user access token (string). Defaults to the locally saved
6158
6086
  token, which is the recommended method for authentication (see
6159
6087
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -6200,7 +6128,7 @@ class HfApi:
6200
6128
  organization (`str`, *optional*):
6201
6129
  If passed, the repository name will be in the organization
6202
6130
  namespace instead of the user namespace.
6203
- token (Union[bool, str, None], optional):
6131
+ token (`bool` or `str`, *optional*):
6204
6132
  A valid user access token (string). Defaults to the locally saved
6205
6133
  token, which is the recommended method for authentication (see
6206
6134
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -6254,7 +6182,7 @@ class HfApi:
6254
6182
  Set to `"dataset"` or `"space"` if fetching from a dataset or
6255
6183
  space, `None` or `"model"` if fetching from a model. Default is
6256
6184
  `None`.
6257
- token (Union[bool, str, None], optional):
6185
+ token (`bool` or `str`, *optional*):
6258
6186
  A valid user access token (string). Defaults to the locally saved
6259
6187
  token, which is the recommended method for authentication (see
6260
6188
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -6349,7 +6277,7 @@ class HfApi:
6349
6277
  Set to `"dataset"` or `"space"` if uploading to a dataset or
6350
6278
  space, `None` or `"model"` if uploading to a model. Default is
6351
6279
  `None`.
6352
- token (Union[bool, str, None], optional):
6280
+ token (`bool` or `str`, *optional*):
6353
6281
  A valid user access token (string). Defaults to the locally saved
6354
6282
  token, which is the recommended method for authentication (see
6355
6283
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -6357,19 +6285,16 @@ class HfApi:
6357
6285
 
6358
6286
  Returns: [`DiscussionWithDetails`]
6359
6287
 
6360
- <Tip>
6361
-
6362
- Raises the following errors:
6363
-
6364
- - [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError)
6365
- if the HuggingFace API returned an error
6366
- - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
6367
- if some parameter value is invalid
6368
- - [`~utils.RepositoryNotFoundError`]
6369
- If the repository to download from cannot be found. This may be because it doesn't exist,
6370
- or because it is set to `private` and you do not have access.
6371
-
6372
- </Tip>
6288
+ > [!TIP]
6289
+ > Raises the following errors:
6290
+ >
6291
+ > - [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError)
6292
+ > if the HuggingFace API returned an error
6293
+ > - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
6294
+ > if some parameter value is invalid
6295
+ > - [`~utils.RepositoryNotFoundError`]
6296
+ > If the repository to download from cannot be found. This may be because it doesn't exist,
6297
+ > or because it is set to `private` and you do not have access.
6373
6298
  """
6374
6299
  if not isinstance(discussion_num, int) or discussion_num <= 0:
6375
6300
  raise ValueError("Invalid discussion_num, must be a positive integer")
@@ -6432,7 +6357,7 @@ class HfApi:
6432
6357
  The title of the discussion. It can be up to 200 characters long,
6433
6358
  and must be at least 3 characters long. Leading and trailing whitespaces
6434
6359
  will be stripped.
6435
- token (Union[bool, str, None], optional):
6360
+ token (`bool` or `str`, *optional*):
6436
6361
  A valid user access token (string). Defaults to the locally saved
6437
6362
  token, which is the recommended method for authentication (see
6438
6363
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -6450,19 +6375,16 @@ class HfApi:
6450
6375
 
6451
6376
  Returns: [`DiscussionWithDetails`]
6452
6377
 
6453
- <Tip>
6454
-
6455
- Raises the following errors:
6456
-
6457
- - [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError)
6458
- if the HuggingFace API returned an error
6459
- - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
6460
- if some parameter value is invalid
6461
- - [`~utils.RepositoryNotFoundError`]
6462
- If the repository to download from cannot be found. This may be because it doesn't exist,
6463
- or because it is set to `private` and you do not have access.
6464
-
6465
- </Tip>"""
6378
+ > [!TIP]
6379
+ > Raises the following errors:
6380
+ >
6381
+ > - [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError)
6382
+ > if the HuggingFace API returned an error
6383
+ > - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
6384
+ > if some parameter value is invalid
6385
+ > - [`~utils.RepositoryNotFoundError`]
6386
+ > If the repository to download from cannot be found. This may be because it doesn't exist,
6387
+ > or because it is set to `private` and you do not have access."""
6466
6388
  if repo_type not in constants.REPO_TYPES:
6467
6389
  raise ValueError(f"Invalid repo type, must be one of {constants.REPO_TYPES}")
6468
6390
  if repo_type is None:
@@ -6523,7 +6445,7 @@ class HfApi:
6523
6445
  The title of the discussion. It can be up to 200 characters long,
6524
6446
  and must be at least 3 characters long. Leading and trailing whitespaces
6525
6447
  will be stripped.
6526
- token (Union[bool, str, None], optional):
6448
+ token (`bool` or `str`, *optional*):
6527
6449
  A valid user access token (string). Defaults to the locally saved
6528
6450
  token, which is the recommended method for authentication (see
6529
6451
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -6538,19 +6460,16 @@ class HfApi:
6538
6460
 
6539
6461
  Returns: [`DiscussionWithDetails`]
6540
6462
 
6541
- <Tip>
6542
-
6543
- Raises the following errors:
6544
-
6545
- - [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError)
6546
- if the HuggingFace API returned an error
6547
- - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
6548
- if some parameter value is invalid
6549
- - [`~utils.RepositoryNotFoundError`]
6550
- If the repository to download from cannot be found. This may be because it doesn't exist,
6551
- or because it is set to `private` and you do not have access.
6552
-
6553
- </Tip>"""
6463
+ > [!TIP]
6464
+ > Raises the following errors:
6465
+ >
6466
+ > - [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError)
6467
+ > if the HuggingFace API returned an error
6468
+ > - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
6469
+ > if some parameter value is invalid
6470
+ > - [`~utils.RepositoryNotFoundError`]
6471
+ > If the repository to download from cannot be found. This may be because it doesn't exist,
6472
+ > or because it is set to `private` and you do not have access."""
6554
6473
  return self.create_discussion(
6555
6474
  repo_id=repo_id,
6556
6475
  title=title,
@@ -6610,7 +6529,7 @@ class HfApi:
6610
6529
  Set to `"dataset"` or `"space"` if uploading to a dataset or
6611
6530
  space, `None` or `"model"` if uploading to a model. Default is
6612
6531
  `None`.
6613
- token (Union[bool, str, None], optional):
6532
+ token (`bool` or `str`, *optional*):
6614
6533
  A valid user access token (string). Defaults to the locally saved
6615
6534
  token, which is the recommended method for authentication (see
6616
6535
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -6641,19 +6560,16 @@ class HfApi:
6641
6560
 
6642
6561
  ```
6643
6562
 
6644
- <Tip>
6645
-
6646
- Raises the following errors:
6647
-
6648
- - [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError)
6649
- if the HuggingFace API returned an error
6650
- - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
6651
- if some parameter value is invalid
6652
- - [`~utils.RepositoryNotFoundError`]
6653
- If the repository to download from cannot be found. This may be because it doesn't exist,
6654
- or because it is set to `private` and you do not have access.
6655
-
6656
- </Tip>
6563
+ > [!TIP]
6564
+ > Raises the following errors:
6565
+ >
6566
+ > - [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError)
6567
+ > if the HuggingFace API returned an error
6568
+ > - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
6569
+ > if some parameter value is invalid
6570
+ > - [`~utils.RepositoryNotFoundError`]
6571
+ > If the repository to download from cannot be found. This may be because it doesn't exist,
6572
+ > or because it is set to `private` and you do not have access.
6657
6573
  """
6658
6574
  resp = self._post_discussion_changes(
6659
6575
  repo_id=repo_id,
@@ -6689,7 +6605,7 @@ class HfApi:
6689
6605
  Set to `"dataset"` or `"space"` if uploading to a dataset or
6690
6606
  space, `None` or `"model"` if uploading to a model. Default is
6691
6607
  `None`.
6692
- token (Union[bool, str, None], optional):
6608
+ token (`bool` or `str`, *optional*):
6693
6609
  A valid user access token (string). Defaults to the locally saved
6694
6610
  token, which is the recommended method for authentication (see
6695
6611
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -6711,19 +6627,16 @@ class HfApi:
6711
6627
 
6712
6628
  ```
6713
6629
 
6714
- <Tip>
6715
-
6716
- Raises the following errors:
6717
-
6718
- - [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError)
6719
- if the HuggingFace API returned an error
6720
- - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
6721
- if some parameter value is invalid
6722
- - [`~utils.RepositoryNotFoundError`]
6723
- If the repository to download from cannot be found. This may be because it doesn't exist,
6724
- or because it is set to `private` and you do not have access.
6725
-
6726
- </Tip>
6630
+ > [!TIP]
6631
+ > Raises the following errors:
6632
+ >
6633
+ > - [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError)
6634
+ > if the HuggingFace API returned an error
6635
+ > - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
6636
+ > if some parameter value is invalid
6637
+ > - [`~utils.RepositoryNotFoundError`]
6638
+ > If the repository to download from cannot be found. This may be because it doesn't exist,
6639
+ > or because it is set to `private` and you do not have access.
6727
6640
  """
6728
6641
  resp = self._post_discussion_changes(
6729
6642
  repo_id=repo_id,
@@ -6762,7 +6675,7 @@ class HfApi:
6762
6675
  Set to `"dataset"` or `"space"` if uploading to a dataset or
6763
6676
  space, `None` or `"model"` if uploading to a model. Default is
6764
6677
  `None`.
6765
- token (Union[bool, str, None], optional):
6678
+ token (`bool` or `str`, *optional*):
6766
6679
  A valid user access token (string). Defaults to the locally saved
6767
6680
  token, which is the recommended method for authentication (see
6768
6681
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -6784,19 +6697,16 @@ class HfApi:
6784
6697
 
6785
6698
  ```
6786
6699
 
6787
- <Tip>
6788
-
6789
- Raises the following errors:
6790
-
6791
- - [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError)
6792
- if the HuggingFace API returned an error
6793
- - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
6794
- if some parameter value is invalid
6795
- - [`~utils.RepositoryNotFoundError`]
6796
- If the repository to download from cannot be found. This may be because it doesn't exist,
6797
- or because it is set to `private` and you do not have access.
6798
-
6799
- </Tip>
6700
+ > [!TIP]
6701
+ > Raises the following errors:
6702
+ >
6703
+ > - [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError)
6704
+ > if the HuggingFace API returned an error
6705
+ > - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
6706
+ > if some parameter value is invalid
6707
+ > - [`~utils.RepositoryNotFoundError`]
6708
+ > If the repository to download from cannot be found. This may be because it doesn't exist,
6709
+ > or because it is set to `private` and you do not have access.
6800
6710
  """
6801
6711
  if new_status not in ["open", "closed"]:
6802
6712
  raise ValueError("Invalid status, valid statuses are: 'open' and 'closed'")
@@ -6837,7 +6747,7 @@ class HfApi:
6837
6747
  Set to `"dataset"` or `"space"` if uploading to a dataset or
6838
6748
  space, `None` or `"model"` if uploading to a model. Default is
6839
6749
  `None`.
6840
- token (Union[bool, str, None], optional):
6750
+ token (`bool` or `str`, *optional*):
6841
6751
  A valid user access token (string). Defaults to the locally saved
6842
6752
  token, which is the recommended method for authentication (see
6843
6753
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -6846,19 +6756,16 @@ class HfApi:
6846
6756
  Returns:
6847
6757
  [`DiscussionStatusChange`]: the status change event
6848
6758
 
6849
- <Tip>
6850
-
6851
- Raises the following errors:
6852
-
6853
- - [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError)
6854
- if the HuggingFace API returned an error
6855
- - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
6856
- if some parameter value is invalid
6857
- - [`~utils.RepositoryNotFoundError`]
6858
- If the repository to download from cannot be found. This may be because it doesn't exist,
6859
- or because it is set to `private` and you do not have access.
6860
-
6861
- </Tip>
6759
+ > [!TIP]
6760
+ > Raises the following errors:
6761
+ >
6762
+ > - [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError)
6763
+ > if the HuggingFace API returned an error
6764
+ > - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
6765
+ > if some parameter value is invalid
6766
+ > - [`~utils.RepositoryNotFoundError`]
6767
+ > If the repository to download from cannot be found. This may be because it doesn't exist,
6768
+ > or because it is set to `private` and you do not have access.
6862
6769
  """
6863
6770
  self._post_discussion_changes(
6864
6771
  repo_id=repo_id,
@@ -6896,7 +6803,7 @@ class HfApi:
6896
6803
  Set to `"dataset"` or `"space"` if uploading to a dataset or
6897
6804
  space, `None` or `"model"` if uploading to a model. Default is
6898
6805
  `None`.
6899
- token (Union[bool, str, None], optional):
6806
+ token (`bool` or `str`, *optional*):
6900
6807
  A valid user access token (string). Defaults to the locally saved
6901
6808
  token, which is the recommended method for authentication (see
6902
6809
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -6905,19 +6812,16 @@ class HfApi:
6905
6812
  Returns:
6906
6813
  [`DiscussionComment`]: the edited comment
6907
6814
 
6908
- <Tip>
6909
-
6910
- Raises the following errors:
6911
-
6912
- - [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError)
6913
- if the HuggingFace API returned an error
6914
- - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
6915
- if some parameter value is invalid
6916
- - [`~utils.RepositoryNotFoundError`]
6917
- If the repository to download from cannot be found. This may be because it doesn't exist,
6918
- or because it is set to `private` and you do not have access.
6919
-
6920
- </Tip>
6815
+ > [!TIP]
6816
+ > Raises the following errors:
6817
+ >
6818
+ > - [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError)
6819
+ > if the HuggingFace API returned an error
6820
+ > - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
6821
+ > if some parameter value is invalid
6822
+ > - [`~utils.RepositoryNotFoundError`]
6823
+ > If the repository to download from cannot be found. This may be because it doesn't exist,
6824
+ > or because it is set to `private` and you do not have access.
6921
6825
  """
6922
6826
  resp = self._post_discussion_changes(
6923
6827
  repo_id=repo_id,
@@ -6941,9 +6845,8 @@ class HfApi:
6941
6845
  ) -> DiscussionComment:
6942
6846
  """Hides a comment on a Discussion / Pull Request.
6943
6847
 
6944
- <Tip warning={true}>
6945
- Hidden comments' content cannot be retrieved anymore. Hiding a comment is irreversible.
6946
- </Tip>
6848
+ > [!WARNING]
6849
+ > Hidden comments' content cannot be retrieved anymore. Hiding a comment is irreversible.
6947
6850
 
6948
6851
  Args:
6949
6852
  repo_id (`str`):
@@ -6957,7 +6860,7 @@ class HfApi:
6957
6860
  Set to `"dataset"` or `"space"` if uploading to a dataset or
6958
6861
  space, `None` or `"model"` if uploading to a model. Default is
6959
6862
  `None`.
6960
- token (Union[bool, str, None], optional):
6863
+ token (`bool` or `str`, *optional*):
6961
6864
  A valid user access token (string). Defaults to the locally saved
6962
6865
  token, which is the recommended method for authentication (see
6963
6866
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -6966,19 +6869,16 @@ class HfApi:
6966
6869
  Returns:
6967
6870
  [`DiscussionComment`]: the hidden comment
6968
6871
 
6969
- <Tip>
6970
-
6971
- Raises the following errors:
6972
-
6973
- - [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError)
6974
- if the HuggingFace API returned an error
6975
- - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
6976
- if some parameter value is invalid
6977
- - [`~utils.RepositoryNotFoundError`]
6978
- If the repository to download from cannot be found. This may be because it doesn't exist,
6979
- or because it is set to `private` and you do not have access.
6980
-
6981
- </Tip>
6872
+ > [!TIP]
6873
+ > Raises the following errors:
6874
+ >
6875
+ > - [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError)
6876
+ > if the HuggingFace API returned an error
6877
+ > - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
6878
+ > if some parameter value is invalid
6879
+ > - [`~utils.RepositoryNotFoundError`]
6880
+ > If the repository to download from cannot be found. This may be because it doesn't exist,
6881
+ > or because it is set to `private` and you do not have access.
6982
6882
  """
6983
6883
  warnings.warn(
6984
6884
  "Hidden comments' content cannot be retrieved anymore. Hiding a comment is irreversible.",
@@ -7017,7 +6917,7 @@ class HfApi:
7017
6917
  Secret value. Example: `"your_github_api_key"`.
7018
6918
  description (`str`, *optional*):
7019
6919
  Secret description. Example: `"Github API key to access the Github API"`.
7020
- token (Union[bool, str, None], optional):
6920
+ token (`bool` or `str`, *optional*):
7021
6921
  A valid user access token (string). Defaults to the locally saved
7022
6922
  token, which is the recommended method for authentication (see
7023
6923
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -7045,7 +6945,7 @@ class HfApi:
7045
6945
  ID of the repo to update. Example: `"bigcode/in-the-stack"`.
7046
6946
  key (`str`):
7047
6947
  Secret key. Example: `"GITHUB_API_KEY"`.
7048
- token (Union[bool, str, None], optional):
6948
+ token (`bool` or `str`, *optional*):
7049
6949
  A valid user access token (string). Defaults to the locally saved
7050
6950
  token, which is the recommended method for authentication (see
7051
6951
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -7068,7 +6968,7 @@ class HfApi:
7068
6968
  Args:
7069
6969
  repo_id (`str`):
7070
6970
  ID of the repo to query. Example: `"bigcode/in-the-stack"`.
7071
- token (Union[bool, str, None], optional):
6971
+ token (`bool` or `str`, *optional*):
7072
6972
  A valid user access token (string). Defaults to the locally saved
7073
6973
  token, which is the recommended method for authentication (see
7074
6974
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -7105,7 +7005,7 @@ class HfApi:
7105
7005
  Variable value. Example: `"the_model_repo_id"`.
7106
7006
  description (`str`):
7107
7007
  Description of the variable. Example: `"Model Repo ID of the implemented model"`.
7108
- token (Union[bool, str, None], optional):
7008
+ token (`bool` or `str`, *optional*):
7109
7009
  A valid user access token (string). Defaults to the locally saved
7110
7010
  token, which is the recommended method for authentication (see
7111
7011
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -7136,7 +7036,7 @@ class HfApi:
7136
7036
  ID of the repo to update. Example: `"bigcode/in-the-stack"`.
7137
7037
  key (`str`):
7138
7038
  Variable key. Example: `"MODEL_REPO_ID"`
7139
- token (Union[bool, str, None], optional):
7039
+ token (`bool` or `str`, *optional*):
7140
7040
  A valid user access token (string). Defaults to the locally saved
7141
7041
  token, which is the recommended method for authentication (see
7142
7042
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -7157,7 +7057,7 @@ class HfApi:
7157
7057
  Args:
7158
7058
  repo_id (`str`):
7159
7059
  ID of the repo to update. Example: `"bigcode/in-the-stack"`.
7160
- token (Union[bool, str, None], optional):
7060
+ token (`bool` or `str`, *optional*):
7161
7061
  A valid user access token (string). Defaults to the locally saved
7162
7062
  token, which is the recommended method for authentication (see
7163
7063
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -7187,7 +7087,7 @@ class HfApi:
7187
7087
  ID of the repo to update. Example: `"bigcode/in-the-stack"`.
7188
7088
  hardware (`str` or [`SpaceHardware`]):
7189
7089
  Hardware on which to run the Space. Example: `"t4-medium"`.
7190
- token (Union[bool, str, None], optional):
7090
+ token (`bool` or `str`, *optional*):
7191
7091
  A valid user access token (string). Defaults to the locally saved
7192
7092
  token, which is the recommended method for authentication (see
7193
7093
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -7200,11 +7100,8 @@ class HfApi:
7200
7100
  Returns:
7201
7101
  [`SpaceRuntime`]: Runtime information about a Space including Space stage and hardware.
7202
7102
 
7203
- <Tip>
7204
-
7205
- It is also possible to request hardware directly when creating the Space repo! See [`create_repo`] for details.
7206
-
7207
- </Tip>
7103
+ > [!TIP]
7104
+ > It is also possible to request hardware directly when creating the Space repo! See [`create_repo`] for details.
7208
7105
  """
7209
7106
  if sleep_time is not None and hardware == SpaceHardware.CPU_BASIC:
7210
7107
  warnings.warn(
@@ -7243,7 +7140,7 @@ class HfApi:
7243
7140
  your Space to pause (default behavior for upgraded hardware). For free hardware, you can't configure
7244
7141
  the sleep time (value is fixed to 48 hours of inactivity).
7245
7142
  See https://huggingface.co/docs/hub/spaces-gpus#sleep-time for more details.
7246
- token (Union[bool, str, None], optional):
7143
+ token (`bool` or `str`, *optional*):
7247
7144
  A valid user access token (string). Defaults to the locally saved
7248
7145
  token, which is the recommended method for authentication (see
7249
7146
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -7251,11 +7148,8 @@ class HfApi:
7251
7148
  Returns:
7252
7149
  [`SpaceRuntime`]: Runtime information about a Space including Space stage and hardware.
7253
7150
 
7254
- <Tip>
7255
-
7256
- It is also possible to set a custom sleep time when requesting hardware with [`request_space_hardware`].
7257
-
7258
- </Tip>
7151
+ > [!TIP]
7152
+ > It is also possible to set a custom sleep time when requesting hardware with [`request_space_hardware`].
7259
7153
  """
7260
7154
  r = get_session().post(
7261
7155
  f"{self.endpoint}/api/spaces/{repo_id}/sleeptime",
@@ -7288,7 +7182,7 @@ class HfApi:
7288
7182
  Args:
7289
7183
  repo_id (`str`):
7290
7184
  ID of the Space to pause. Example: `"Salesforce/BLIP2"`.
7291
- token (Union[bool, str, None], optional):
7185
+ token (`bool` or `str`, *optional*):
7292
7186
  A valid user access token (string). Defaults to the locally saved
7293
7187
  token, which is the recommended method for authentication (see
7294
7188
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -7329,7 +7223,7 @@ class HfApi:
7329
7223
  Args:
7330
7224
  repo_id (`str`):
7331
7225
  ID of the Space to restart. Example: `"Salesforce/BLIP2"`.
7332
- token (Union[bool, str, None], optional):
7226
+ token (`bool` or `str`, *optional*):
7333
7227
  A valid user access token (string). Defaults to the locally saved
7334
7228
  token, which is the recommended method for authentication (see
7335
7229
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -7388,7 +7282,7 @@ class HfApi:
7388
7282
  name as the original Space, but in your account.
7389
7283
  private (`bool`, *optional*):
7390
7284
  Whether the new Space should be private or not. Defaults to the same privacy as the original Space.
7391
- token (Union[bool, str, None], optional):
7285
+ token (`bool` or `str`, *optional*):
7392
7286
  A valid user access token (string). Defaults to the locally saved
7393
7287
  token, which is the recommended method for authentication (see
7394
7288
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -7493,7 +7387,7 @@ class HfApi:
7493
7387
  ID of the Space to update. Example: `"open-llm-leaderboard/open_llm_leaderboard"`.
7494
7388
  storage (`str` or [`SpaceStorage`]):
7495
7389
  Storage tier. Either 'small', 'medium', or 'large'.
7496
- token (Union[bool, str, None], optional):
7390
+ token (`bool` or `str`, *optional*):
7497
7391
  A valid user access token (string). Defaults to the locally saved
7498
7392
  token, which is the recommended method for authentication (see
7499
7393
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -7501,12 +7395,9 @@ class HfApi:
7501
7395
  Returns:
7502
7396
  [`SpaceRuntime`]: Runtime information about a Space including Space stage and hardware.
7503
7397
 
7504
- <Tip>
7505
-
7506
- It is not possible to decrease persistent storage after its granted. To do so, you must delete it
7507
- via [`delete_space_storage`].
7508
-
7509
- </Tip>
7398
+ > [!TIP]
7399
+ > It is not possible to decrease persistent storage after its granted. To do so, you must delete it
7400
+ > via [`delete_space_storage`].
7510
7401
  """
7511
7402
  payload: Dict[str, SpaceStorage] = {"tier": storage}
7512
7403
  r = get_session().post(
@@ -7529,7 +7420,7 @@ class HfApi:
7529
7420
  Args:
7530
7421
  repo_id (`str`):
7531
7422
  ID of the Space to update. Example: `"open-llm-leaderboard/open_llm_leaderboard"`.
7532
- token (Union[bool, str, None], optional):
7423
+ token (`bool` or `str`, *optional*):
7533
7424
  A valid user access token (string). Defaults to the locally saved
7534
7425
  token, which is the recommended method for authentication (see
7535
7426
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -7561,7 +7452,7 @@ class HfApi:
7561
7452
  namespace (`str`, *optional*):
7562
7453
  The namespace to list endpoints for. Defaults to the current user. Set to `"*"` to list all endpoints
7563
7454
  from all namespaces (i.e. personal namespace and all orgs the user belongs to).
7564
- token (Union[bool, str, None], optional):
7455
+ token (`bool` or `str`, *optional*):
7565
7456
  A valid user access token (string). Defaults to the locally saved
7566
7457
  token, which is the recommended method for authentication (see
7567
7458
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -7690,7 +7581,7 @@ class HfApi:
7690
7581
  A list of tags to associate with the Inference Endpoint.
7691
7582
  namespace (`str`, *optional*):
7692
7583
  The namespace where the Inference Endpoint will be created. Defaults to the current user's namespace.
7693
- token (Union[bool, str, None], optional):
7584
+ token (`bool` or `str`, *optional*):
7694
7585
  A valid user access token (string). Defaults to the locally saved
7695
7586
  token, which is the recommended method for authentication (see
7696
7587
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -7860,7 +7751,7 @@ class HfApi:
7860
7751
  The ID of the model in the catalog to deploy as an Inference Endpoint.
7861
7752
  name (`str`, *optional*):
7862
7753
  The unique name for the new Inference Endpoint. If not provided, a random name will be generated.
7863
- token (Union[bool, str, None], optional):
7754
+ token (`bool` or `str`, *optional*):
7864
7755
  A valid user access token (string). Defaults to the locally saved
7865
7756
  token, which is the recommended method for authentication (see
7866
7757
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -7870,12 +7761,9 @@ class HfApi:
7870
7761
  Returns:
7871
7762
  [`InferenceEndpoint`]: information about the new Inference Endpoint.
7872
7763
 
7873
- <Tip warning={true}>
7874
-
7875
- `create_inference_endpoint_from_catalog` is experimental. Its API is subject to change in the future. Please provide feedback
7876
- if you have any suggestions or requests.
7877
-
7878
- </Tip>
7764
+ > [!WARNING]
7765
+ > `create_inference_endpoint_from_catalog` is experimental. Its API is subject to change in the future. Please provide feedback
7766
+ > if you have any suggestions or requests.
7879
7767
  """
7880
7768
  token = token or self.token or get_token()
7881
7769
  payload: Dict = {
@@ -7906,19 +7794,16 @@ class HfApi:
7906
7794
  Use [`create_inference_endpoint_from_catalog`] to deploy a model from the catalog.
7907
7795
 
7908
7796
  Args:
7909
- token (Union[bool, str, None], optional):
7797
+ token (`bool` or `str`, *optional*):
7910
7798
  A valid user access token (string). Defaults to the locally saved
7911
7799
  token, which is the recommended method for authentication (see
7912
7800
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
7913
7801
 
7914
7802
  Returns:
7915
7803
  List[`str`]: A list of model IDs available in the catalog.
7916
- <Tip warning={true}>
7917
-
7918
- `list_inference_catalog` is experimental. Its API is subject to change in the future. Please provide feedback
7919
- if you have any suggestions or requests.
7920
-
7921
- </Tip>
7804
+ > [!WARNING]
7805
+ > `list_inference_catalog` is experimental. Its API is subject to change in the future. Please provide feedback
7806
+ > if you have any suggestions or requests.
7922
7807
  """
7923
7808
  response = get_session().get(
7924
7809
  f"{constants.INFERENCE_CATALOG_ENDPOINT}/repo-list",
@@ -7937,7 +7822,7 @@ class HfApi:
7937
7822
  The name of the Inference Endpoint to retrieve information about.
7938
7823
  namespace (`str`, *optional*):
7939
7824
  The namespace in which the Inference Endpoint is located. Defaults to the current user.
7940
- token (Union[bool, str, None], optional):
7825
+ token (`bool` or `str`, *optional*):
7941
7826
  A valid user access token (string). Defaults to the locally saved
7942
7827
  token, which is the recommended method for authentication (see
7943
7828
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -8054,7 +7939,7 @@ class HfApi:
8054
7939
 
8055
7940
  namespace (`str`, *optional*):
8056
7941
  The namespace where the Inference Endpoint will be updated. Defaults to the current user's namespace.
8057
- token (Union[bool, str, None], optional):
7942
+ token (`bool` or `str`, *optional*):
8058
7943
  A valid user access token (string). Defaults to the locally saved
8059
7944
  token, which is the recommended method for authentication (see
8060
7945
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -8126,7 +8011,7 @@ class HfApi:
8126
8011
  The name of the Inference Endpoint to delete.
8127
8012
  namespace (`str`, *optional*):
8128
8013
  The namespace in which the Inference Endpoint is located. Defaults to the current user.
8129
- token (Union[bool, str, None], optional):
8014
+ token (`bool` or `str`, *optional*):
8130
8015
  A valid user access token (string). Defaults to the locally saved
8131
8016
  token, which is the recommended method for authentication (see
8132
8017
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -8155,7 +8040,7 @@ class HfApi:
8155
8040
  The name of the Inference Endpoint to pause.
8156
8041
  namespace (`str`, *optional*):
8157
8042
  The namespace in which the Inference Endpoint is located. Defaults to the current user.
8158
- token (Union[bool, str, None], optional):
8043
+ token (`bool` or `str`, *optional*):
8159
8044
  A valid user access token (string). Defaults to the locally saved
8160
8045
  token, which is the recommended method for authentication (see
8161
8046
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -8194,7 +8079,7 @@ class HfApi:
8194
8079
  running_ok (`bool`, *optional*):
8195
8080
  If `True`, the method will not raise an error if the Inference Endpoint is already running. Defaults to
8196
8081
  `True`.
8197
- token (Union[bool, str, None], optional):
8082
+ token (`bool` or `str`, *optional*):
8198
8083
  A valid user access token (string). Defaults to the locally saved
8199
8084
  token, which is the recommended method for authentication (see
8200
8085
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -8236,7 +8121,7 @@ class HfApi:
8236
8121
  The name of the Inference Endpoint to scale to zero.
8237
8122
  namespace (`str`, *optional*):
8238
8123
  The namespace in which the Inference Endpoint is located. Defaults to the current user.
8239
- token (Union[bool, str, None], optional):
8124
+ token (`bool` or `str`, *optional*):
8240
8125
  A valid user access token (string). Defaults to the locally saved
8241
8126
  token, which is the recommended method for authentication (see
8242
8127
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -8281,12 +8166,9 @@ class HfApi:
8281
8166
  ) -> Iterable[Collection]:
8282
8167
  """List collections on the Huggingface Hub, given some filters.
8283
8168
 
8284
- <Tip warning={true}>
8285
-
8286
- When listing collections, the item list per collection is truncated to 4 items maximum. To retrieve all items
8287
- from a collection, you must use [`get_collection`].
8288
-
8289
- </Tip>
8169
+ > [!WARNING]
8170
+ > When listing collections, the item list per collection is truncated to 4 items maximum. To retrieve all items
8171
+ > from a collection, you must use [`get_collection`].
8290
8172
 
8291
8173
  Args:
8292
8174
  owner (`List[str]` or `str`, *optional*):
@@ -8297,7 +8179,7 @@ class HfApi:
8297
8179
  Sort collections by last modified, trending or upvotes.
8298
8180
  limit (`int`, *optional*):
8299
8181
  Maximum number of collections to be returned.
8300
- token (Union[bool, str, None], optional):
8182
+ token (`bool` or `str`, *optional*):
8301
8183
  A valid user access token (string). Defaults to the locally saved
8302
8184
  token, which is the recommended method for authentication (see
8303
8185
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -8334,7 +8216,7 @@ class HfApi:
8334
8216
  Args:
8335
8217
  collection_slug (`str`):
8336
8218
  Slug of the collection of the Hub. Example: `"TheBloke/recent-models-64f9a55bb3115b4f513ec026"`.
8337
- token (Union[bool, str, None], optional):
8219
+ token (`bool` or `str`, *optional*):
8338
8220
  A valid user access token (string). Defaults to the locally saved
8339
8221
  token, which is the recommended method for authentication (see
8340
8222
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -8390,7 +8272,7 @@ class HfApi:
8390
8272
  Whether the collection should be private or not. Defaults to `False` (i.e. public collection).
8391
8273
  exists_ok (`bool`, *optional*):
8392
8274
  If `True`, do not raise an error if collection already exists.
8393
- token (Union[bool, str, None], optional):
8275
+ token (`bool` or `str`, *optional*):
8394
8276
  A valid user access token (string). Defaults to the locally saved
8395
8277
  token, which is the recommended method for authentication (see
8396
8278
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -8463,7 +8345,7 @@ class HfApi:
8463
8345
  Whether the collection should be private or not.
8464
8346
  theme (`str`, *optional*):
8465
8347
  Theme of the collection on the Hub.
8466
- token (Union[bool, str, None], optional):
8348
+ token (`bool` or `str`, *optional*):
8467
8349
  A valid user access token (string). Defaults to the locally saved
8468
8350
  token, which is the recommended method for authentication (see
8469
8351
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -8513,7 +8395,7 @@ class HfApi:
8513
8395
  Slug of the collection to delete. Example: `"TheBloke/recent-models-64f9a55bb3115b4f513ec026"`.
8514
8396
  missing_ok (`bool`, *optional*):
8515
8397
  If `True`, do not raise an error if collection doesn't exists.
8516
- token (Union[bool, str, None], optional):
8398
+ token (`bool` or `str`, *optional*):
8517
8399
  A valid user access token (string). Defaults to the locally saved
8518
8400
  token, which is the recommended method for authentication (see
8519
8401
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -8526,11 +8408,8 @@ class HfApi:
8526
8408
  >>> collection = delete_collection("username/useless-collection-64f9a55bb3115b4f513ec026", missing_ok=True)
8527
8409
  ```
8528
8410
 
8529
- <Tip warning={true}>
8530
-
8531
- This is a non-revertible action. A deleted collection cannot be restored.
8532
-
8533
- </Tip>
8411
+ > [!WARNING]
8412
+ > This is a non-revertible action. A deleted collection cannot be restored.
8534
8413
  """
8535
8414
  r = get_session().delete(
8536
8415
  f"{self.endpoint}/api/collections/{collection_slug}", headers=self._build_hf_headers(token=token)
@@ -8568,7 +8447,7 @@ class HfApi:
8568
8447
  A note to attach to the item in the collection. The maximum size for a note is 500 characters.
8569
8448
  exists_ok (`bool`, *optional*):
8570
8449
  If `True`, do not raise an error if item already exists.
8571
- token (Union[bool, str, None], optional):
8450
+ token (`bool` or `str`, *optional*):
8572
8451
  A valid user access token (string). Defaults to the locally saved
8573
8452
  token, which is the recommended method for authentication (see
8574
8453
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -8647,7 +8526,7 @@ class HfApi:
8647
8526
  A note to attach to the item in the collection. The maximum size for a note is 500 characters.
8648
8527
  position (`int`, *optional*):
8649
8528
  New position of the item in the collection.
8650
- token (Union[bool, str, None], optional):
8529
+ token (`bool` or `str`, *optional*):
8651
8530
  A valid user access token (string). Defaults to the locally saved
8652
8531
  token, which is the recommended method for authentication (see
8653
8532
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -8697,7 +8576,7 @@ class HfApi:
8697
8576
  It must be retrieved from a [`CollectionItem`] object. Example: `collection.items[0].item_object_id`.
8698
8577
  missing_ok (`bool`, *optional*):
8699
8578
  If `True`, do not raise an error if item doesn't exists.
8700
- token (Union[bool, str, None], optional):
8579
+ token (`bool` or `str`, *optional*):
8701
8580
  A valid user access token (string). Defaults to the locally saved
8702
8581
  token, which is the recommended method for authentication (see
8703
8582
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -8754,7 +8633,7 @@ class HfApi:
8754
8633
  repo_type (`str`, *optional*):
8755
8634
  The type of the repo to get access requests for. Must be one of `model`, `dataset` or `space`.
8756
8635
  Defaults to `model`.
8757
- token (Union[bool, str, None], optional):
8636
+ token (`bool` or `str`, *optional*):
8758
8637
  A valid user access token (string). Defaults to the locally saved
8759
8638
  token, which is the recommended method for authentication (see
8760
8639
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -8820,7 +8699,7 @@ class HfApi:
8820
8699
  repo_type (`str`, *optional*):
8821
8700
  The type of the repo to get access requests for. Must be one of `model`, `dataset` or `space`.
8822
8701
  Defaults to `model`.
8823
- token (Union[bool, str, None], optional):
8702
+ token (`bool` or `str`, *optional*):
8824
8703
  A valid user access token (string). Defaults to the locally saved
8825
8704
  token, which is the recommended method for authentication (see
8826
8705
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -8882,7 +8761,7 @@ class HfApi:
8882
8761
  repo_type (`str`, *optional*):
8883
8762
  The type of the repo to get access requests for. Must be one of `model`, `dataset` or `space`.
8884
8763
  Defaults to `model`.
8885
- token (Union[bool, str, None], optional):
8764
+ token (`bool` or `str`, *optional*):
8886
8765
  A valid user access token (string). Defaults to the locally saved
8887
8766
  token, which is the recommended method for authentication (see
8888
8767
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -8971,7 +8850,7 @@ class HfApi:
8971
8850
  repo_type (`str`, *optional*):
8972
8851
  The type of the repo to cancel access request for. Must be one of `model`, `dataset` or `space`.
8973
8852
  Defaults to `model`.
8974
- token (Union[bool, str, None], optional):
8853
+ token (`bool` or `str`, *optional*):
8975
8854
  A valid user access token (string). Defaults to the locally saved
8976
8855
  token, which is the recommended method for authentication (see
8977
8856
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -9013,7 +8892,7 @@ class HfApi:
9013
8892
  repo_type (`str`, *optional*):
9014
8893
  The type of the repo to accept access request for. Must be one of `model`, `dataset` or `space`.
9015
8894
  Defaults to `model`.
9016
- token (Union[bool, str, None], optional):
8895
+ token (`bool` or `str`, *optional*):
9017
8896
  A valid user access token (string). Defaults to the locally saved
9018
8897
  token, which is the recommended method for authentication (see
9019
8898
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -9063,7 +8942,7 @@ class HfApi:
9063
8942
  Defaults to `model`.
9064
8943
  rejection_reason (`str`, *optional*):
9065
8944
  Optional rejection reason that will be visible to the user (max 200 characters).
9066
- token (Union[bool, str, None], optional):
8945
+ token (`bool` or `str`, *optional*):
9067
8946
  A valid user access token (string). Defaults to the locally saved
9068
8947
  token, which is the recommended method for authentication (see
9069
8948
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -9136,7 +9015,7 @@ class HfApi:
9136
9015
  repo_type (`str`, *optional*):
9137
9016
  The type of the repo to grant access to. Must be one of `model`, `dataset` or `space`.
9138
9017
  Defaults to `model`.
9139
- token (Union[bool, str, None], optional):
9018
+ token (`bool` or `str`, *optional*):
9140
9019
  A valid user access token (string). Defaults to the locally saved
9141
9020
  token, which is the recommended method for authentication (see
9142
9021
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -9177,7 +9056,7 @@ class HfApi:
9177
9056
  Args:
9178
9057
  webhook_id (`str`):
9179
9058
  The unique identifier of the webhook to get.
9180
- token (Union[bool, str, None], optional):
9059
+ token (`bool` or `str`, *optional*):
9181
9060
  A valid user access token (string). Defaults to the locally saved token, which is the recommended
9182
9061
  method for authentication (see https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
9183
9062
  To disable authentication, pass `False`.
@@ -9193,6 +9072,7 @@ class HfApi:
9193
9072
  >>> print(webhook)
9194
9073
  WebhookInfo(
9195
9074
  id="654bbbc16f2ec14d77f109cc",
9075
+ job=None,
9196
9076
  watched=[WebhookWatchedItem(type="user", name="julien-c"), WebhookWatchedItem(type="org", name="HuggingFaceH4")],
9197
9077
  url="https://webhook.site/a2176e82-5720-43ee-9e06-f91cb4c91548",
9198
9078
  secret="my-secret",
@@ -9212,7 +9092,8 @@ class HfApi:
9212
9092
 
9213
9093
  webhook = WebhookInfo(
9214
9094
  id=webhook_data["id"],
9215
- url=webhook_data["url"],
9095
+ url=webhook_data.get("url"),
9096
+ job=JobSpec(**webhook_data["job"]) if webhook_data.get("job") else None,
9216
9097
  watched=watched_items,
9217
9098
  domains=webhook_data["domains"],
9218
9099
  secret=webhook_data.get("secret"),
@@ -9226,7 +9107,7 @@ class HfApi:
9226
9107
  """List all configured webhooks.
9227
9108
 
9228
9109
  Args:
9229
- token (Union[bool, str, None], optional):
9110
+ token (`bool` or `str`, *optional*):
9230
9111
  A valid user access token (string). Defaults to the locally saved token, which is the recommended
9231
9112
  method for authentication (see https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
9232
9113
  To disable authentication, pass `False`.
@@ -9262,7 +9143,8 @@ class HfApi:
9262
9143
  return [
9263
9144
  WebhookInfo(
9264
9145
  id=webhook["id"],
9265
- url=webhook["url"],
9146
+ url=webhook.get("url"),
9147
+ job=JobSpec(**webhook["job"]) if webhook.get("job") else None,
9266
9148
  watched=[WebhookWatchedItem(type=item["type"], name=item["name"]) for item in webhook["watched"]],
9267
9149
  domains=webhook["domains"],
9268
9150
  secret=webhook.get("secret"),
@@ -9275,7 +9157,8 @@ class HfApi:
9275
9157
  def create_webhook(
9276
9158
  self,
9277
9159
  *,
9278
- url: str,
9160
+ url: Optional[str] = None,
9161
+ job_id: Optional[str] = None,
9279
9162
  watched: List[Union[Dict, WebhookWatchedItem]],
9280
9163
  domains: Optional[List[constants.WEBHOOK_DOMAIN_T]] = None,
9281
9164
  secret: Optional[str] = None,
@@ -9283,9 +9166,15 @@ class HfApi:
9283
9166
  ) -> WebhookInfo:
9284
9167
  """Create a new webhook.
9285
9168
 
9169
+ The webhook can either send a payload to a URL, or trigger a Job to run on Hugging Face infrastructure.
9170
+ This function should be called with one of `url` or `job_id`, but not both.
9171
+
9286
9172
  Args:
9287
9173
  url (`str`):
9288
9174
  URL to send the payload to.
9175
+ job_id (`str`):
9176
+ ID of the source Job to trigger with the webhook payload in the environment variable WEBHOOK_PAYLOAD.
9177
+ Additional environment variables are available for convenience: WEBHOOK_REPO_ID, WEBHOOK_REPO_TYPE and WEBHOOK_SECRET.
9289
9178
  watched (`List[WebhookWatchedItem]`):
9290
9179
  List of [`WebhookWatchedItem`] to be watched by the webhook. It can be users, orgs, models, datasets or spaces.
9291
9180
  Watched items can also be provided as plain dictionaries.
@@ -9293,7 +9182,7 @@ class HfApi:
9293
9182
  List of domains to watch. It can be "repo", "discussion" or both.
9294
9183
  secret (`str`, optional):
9295
9184
  A secret to sign the payload with.
9296
- token (Union[bool, str, None], optional):
9185
+ token (`bool` or `str`, *optional*):
9297
9186
  A valid user access token (string). Defaults to the locally saved token, which is the recommended
9298
9187
  method for authentication (see https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
9299
9188
  To disable authentication, pass `False`.
@@ -9303,6 +9192,8 @@ class HfApi:
9303
9192
  Info about the newly created webhook.
9304
9193
 
9305
9194
  Example:
9195
+
9196
+ Create a webhook that sends a payload to a URL
9306
9197
  ```python
9307
9198
  >>> from huggingface_hub import create_webhook
9308
9199
  >>> payload = create_webhook(
@@ -9315,6 +9206,43 @@ class HfApi:
9315
9206
  WebhookInfo(
9316
9207
  id="654bbbc16f2ec14d77f109cc",
9317
9208
  url="https://webhook.site/a2176e82-5720-43ee-9e06-f91cb4c91548",
9209
+ job=None,
9210
+ watched=[WebhookWatchedItem(type="user", name="julien-c"), WebhookWatchedItem(type="org", name="HuggingFaceH4")],
9211
+ domains=["repo", "discussion"],
9212
+ secret="my-secret",
9213
+ disabled=False,
9214
+ )
9215
+ ```
9216
+
9217
+ Run a Job and then create a webhook that triggers this Job
9218
+ ```python
9219
+ >>> from huggingface_hub import create_webhook, run_job
9220
+ >>> job = run_job(
9221
+ ... image="ubuntu",
9222
+ ... command=["bash", "-c", r"echo An event occured in $WEBHOOK_REPO_ID: $WEBHOOK_PAYLOAD"],
9223
+ ... )
9224
+ >>> payload = create_webhook(
9225
+ ... watched=[{"type": "user", "name": "julien-c"}, {"type": "org", "name": "HuggingFaceH4"}],
9226
+ ... job_id=job.id,
9227
+ ... domains=["repo", "discussion"],
9228
+ ... secret="my-secret",
9229
+ ... )
9230
+ >>> print(payload)
9231
+ WebhookInfo(
9232
+ id="654bbbc16f2ec14d77f109cc",
9233
+ url=None,
9234
+ job=JobSpec(
9235
+ docker_image='ubuntu',
9236
+ space_id=None,
9237
+ command=['bash', '-c', 'echo An event occured in $WEBHOOK_REPO_ID: $WEBHOOK_PAYLOAD'],
9238
+ arguments=[],
9239
+ environment={},
9240
+ secrets=[],
9241
+ flavor='cpu-basic',
9242
+ timeout=None,
9243
+ tags=None,
9244
+ arch=None
9245
+ ),
9318
9246
  watched=[WebhookWatchedItem(type="user", name="julien-c"), WebhookWatchedItem(type="org", name="HuggingFaceH4")],
9319
9247
  domains=["repo", "discussion"],
9320
9248
  secret="my-secret",
@@ -9324,9 +9252,19 @@ class HfApi:
9324
9252
  """
9325
9253
  watched_dicts = [asdict(item) if isinstance(item, WebhookWatchedItem) else item for item in watched]
9326
9254
 
9255
+ post_webhooks_json = {"watched": watched_dicts, "domains": domains, "secret": secret}
9256
+ if url is not None and job_id is not None:
9257
+ raise ValueError("Set `url` or `job_id` but not both.")
9258
+ elif url is not None:
9259
+ post_webhooks_json["url"] = url
9260
+ elif job_id is not None:
9261
+ post_webhooks_json["jobSourceId"] = job_id
9262
+ else:
9263
+ raise ValueError("Missing argument for webhook: `url` or `job_id`.")
9264
+
9327
9265
  response = get_session().post(
9328
9266
  f"{constants.ENDPOINT}/api/settings/webhooks",
9329
- json={"watched": watched_dicts, "url": url, "domains": domains, "secret": secret},
9267
+ json=post_webhooks_json,
9330
9268
  headers=self._build_hf_headers(token=token),
9331
9269
  )
9332
9270
  hf_raise_for_status(response)
@@ -9335,7 +9273,8 @@ class HfApi:
9335
9273
 
9336
9274
  webhook = WebhookInfo(
9337
9275
  id=webhook_data["id"],
9338
- url=webhook_data["url"],
9276
+ url=webhook_data.get("url"),
9277
+ job=JobSpec(**webhook_data["job"]) if webhook_data.get("job") else None,
9339
9278
  watched=watched_items,
9340
9279
  domains=webhook_data["domains"],
9341
9280
  secret=webhook_data.get("secret"),
@@ -9369,7 +9308,7 @@ class HfApi:
9369
9308
  The domains to watch. This can include "repo", "discussion", or both.
9370
9309
  secret (`str`, optional):
9371
9310
  A secret to sign the payload with, providing an additional layer of security.
9372
- token (Union[bool, str, None], optional):
9311
+ token (`bool` or `str`, *optional*):
9373
9312
  A valid user access token (string). Defaults to the locally saved token, which is the recommended
9374
9313
  method for authentication (see https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
9375
9314
  To disable authentication, pass `False`.
@@ -9391,6 +9330,7 @@ class HfApi:
9391
9330
  >>> print(updated_payload)
9392
9331
  WebhookInfo(
9393
9332
  id="654bbbc16f2ec14d77f109cc",
9333
+ job=None,
9394
9334
  url="https://new.webhook.site/a2176e82-5720-43ee-9e06-f91cb4c91548",
9395
9335
  watched=[WebhookWatchedItem(type="user", name="julien-c"), WebhookWatchedItem(type="org", name="HuggingFaceH4")],
9396
9336
  domains=["repo"],
@@ -9414,7 +9354,8 @@ class HfApi:
9414
9354
 
9415
9355
  webhook = WebhookInfo(
9416
9356
  id=webhook_data["id"],
9417
- url=webhook_data["url"],
9357
+ url=webhook_data.get("url"),
9358
+ job=JobSpec(**webhook_data["job"]) if webhook_data.get("job") else None,
9418
9359
  watched=watched_items,
9419
9360
  domains=webhook_data["domains"],
9420
9361
  secret=webhook_data.get("secret"),
@@ -9430,7 +9371,7 @@ class HfApi:
9430
9371
  Args:
9431
9372
  webhook_id (`str`):
9432
9373
  The unique identifier of the webhook to enable.
9433
- token (Union[bool, str, None], optional):
9374
+ token (`bool` or `str`, *optional*):
9434
9375
  A valid user access token (string). Defaults to the locally saved token, which is the recommended
9435
9376
  method for authentication (see https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
9436
9377
  To disable authentication, pass `False`.
@@ -9446,6 +9387,7 @@ class HfApi:
9446
9387
  >>> enabled_webhook
9447
9388
  WebhookInfo(
9448
9389
  id="654bbbc16f2ec14d77f109cc",
9390
+ job=None,
9449
9391
  url="https://webhook.site/a2176e82-5720-43ee-9e06-f91cb4c91548",
9450
9392
  watched=[WebhookWatchedItem(type="user", name="julien-c"), WebhookWatchedItem(type="org", name="HuggingFaceH4")],
9451
9393
  domains=["repo", "discussion"],
@@ -9465,7 +9407,8 @@ class HfApi:
9465
9407
 
9466
9408
  webhook = WebhookInfo(
9467
9409
  id=webhook_data["id"],
9468
- url=webhook_data["url"],
9410
+ url=webhook_data.get("url"),
9411
+ job=JobSpec(**webhook_data["job"]) if webhook_data.get("job") else None,
9469
9412
  watched=watched_items,
9470
9413
  domains=webhook_data["domains"],
9471
9414
  secret=webhook_data.get("secret"),
@@ -9481,7 +9424,7 @@ class HfApi:
9481
9424
  Args:
9482
9425
  webhook_id (`str`):
9483
9426
  The unique identifier of the webhook to disable.
9484
- token (Union[bool, str, None], optional):
9427
+ token (`bool` or `str`, *optional*):
9485
9428
  A valid user access token (string). Defaults to the locally saved token, which is the recommended
9486
9429
  method for authentication (see https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
9487
9430
  To disable authentication, pass `False`.
@@ -9498,6 +9441,7 @@ class HfApi:
9498
9441
  WebhookInfo(
9499
9442
  id="654bbbc16f2ec14d77f109cc",
9500
9443
  url="https://webhook.site/a2176e82-5720-43ee-9e06-f91cb4c91548",
9444
+ jon=None,
9501
9445
  watched=[WebhookWatchedItem(type="user", name="julien-c"), WebhookWatchedItem(type="org", name="HuggingFaceH4")],
9502
9446
  domains=["repo", "discussion"],
9503
9447
  secret="my-secret",
@@ -9516,7 +9460,8 @@ class HfApi:
9516
9460
 
9517
9461
  webhook = WebhookInfo(
9518
9462
  id=webhook_data["id"],
9519
- url=webhook_data["url"],
9463
+ url=webhook_data.get("url"),
9464
+ job=JobSpec(**webhook_data["job"]) if webhook_data.get("job") else None,
9520
9465
  watched=watched_items,
9521
9466
  domains=webhook_data["domains"],
9522
9467
  secret=webhook_data.get("secret"),
@@ -9532,7 +9477,7 @@ class HfApi:
9532
9477
  Args:
9533
9478
  webhook_id (`str`):
9534
9479
  The unique identifier of the webhook to delete.
9535
- token (Union[bool, str, None], optional):
9480
+ token (`bool` or `str`, *optional*):
9536
9481
  A valid user access token (string). Defaults to the locally saved token, which is the recommended
9537
9482
  method for authentication (see https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
9538
9483
  To disable authentication, pass `False`.
@@ -9692,7 +9637,7 @@ class HfApi:
9692
9637
  repo_type (`str`, *optional*):
9693
9638
  The type of the repo to grant access to. Must be one of `model`, `dataset` or `space`.
9694
9639
  Defaults to `model`.
9695
- token (Union[bool, str, None], optional):
9640
+ token (`bool` or `str`, *optional*):
9696
9641
  A valid user access token (string). Defaults to the locally saved
9697
9642
  token, which is the recommended method for authentication (see
9698
9643
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -9731,7 +9676,7 @@ class HfApi:
9731
9676
  Args:
9732
9677
  username (`str`):
9733
9678
  Username of the user to get an overview of.
9734
- token (Union[bool, str, None], optional):
9679
+ token (`bool` or `str`, *optional*):
9735
9680
  A valid user access token (string). Defaults to the locally saved
9736
9681
  token, which is the recommended method for authentication (see
9737
9682
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -9750,6 +9695,33 @@ class HfApi:
9750
9695
  hf_raise_for_status(r)
9751
9696
  return User(**r.json())
9752
9697
 
9698
+ @validate_hf_hub_args
9699
+ def get_organization_overview(self, organization: str, token: Union[bool, str, None] = None) -> Organization:
9700
+ """
9701
+ Get an overview of an organization on the Hub.
9702
+
9703
+ Args:
9704
+ organization (`str`):
9705
+ Name of the organization to get an overview of.
9706
+ token (`bool` or `str`, *optional*):
9707
+ A valid user access token (string). Defaults to the locally saved token, which is the recommended method
9708
+ for authentication (see https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
9709
+ To disable authentication, pass `False`.
9710
+
9711
+ Returns:
9712
+ `Organization`: An [`Organization`] object with the organization's overview.
9713
+
9714
+ Raises:
9715
+ [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError):
9716
+ HTTP 404 If the organization does not exist on the Hub.
9717
+ """
9718
+ r = get_session().get(
9719
+ f"{constants.ENDPOINT}/api/organizations/{organization}/overview",
9720
+ headers=self._build_hf_headers(token=token),
9721
+ )
9722
+ hf_raise_for_status(r)
9723
+ return Organization(**r.json())
9724
+
9753
9725
  def list_organization_members(self, organization: str, token: Union[bool, str, None] = None) -> Iterable[User]:
9754
9726
  """
9755
9727
  List of members of an organization on the Hub.
@@ -9757,7 +9729,7 @@ class HfApi:
9757
9729
  Args:
9758
9730
  organization (`str`):
9759
9731
  Name of the organization to get the members of.
9760
- token (Union[bool, str, None], optional):
9732
+ token (`bool` or `str`, *optional*):
9761
9733
  A valid user access token (string). Defaults to the locally saved
9762
9734
  token, which is the recommended method for authentication (see
9763
9735
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -9785,7 +9757,7 @@ class HfApi:
9785
9757
  Args:
9786
9758
  username (`str`):
9787
9759
  Username of the user to get the followers of.
9788
- token (Union[bool, str, None], optional):
9760
+ token (`bool` or `str`, *optional*):
9789
9761
  A valid user access token (string). Defaults to the locally saved
9790
9762
  token, which is the recommended method for authentication (see
9791
9763
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -9813,7 +9785,7 @@ class HfApi:
9813
9785
  Args:
9814
9786
  username (`str`):
9815
9787
  Username of the user to get the users followed by.
9816
- token (Union[bool, str, None], optional):
9788
+ token (`bool` or `str`, *optional*):
9817
9789
  A valid user access token (string). Defaults to the locally saved
9818
9790
  token, which is the recommended method for authentication (see
9819
9791
  https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
@@ -11043,6 +11015,7 @@ update_webhook = api.update_webhook
11043
11015
 
11044
11016
  # User API
11045
11017
  get_user_overview = api.get_user_overview
11018
+ get_organization_overview = api.get_organization_overview
11046
11019
  list_organization_members = api.list_organization_members
11047
11020
  list_user_followers = api.list_user_followers
11048
11021
  list_user_following = api.list_user_following