huggingface-hub 0.35.1__py3-none-any.whl → 1.0.0rc1__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 (127) hide show
  1. huggingface_hub/__init__.py +28 -45
  2. huggingface_hub/_commit_api.py +28 -28
  3. huggingface_hub/_commit_scheduler.py +11 -8
  4. huggingface_hub/_inference_endpoints.py +8 -8
  5. huggingface_hub/_jobs_api.py +20 -20
  6. huggingface_hub/_login.py +13 -39
  7. huggingface_hub/_oauth.py +8 -8
  8. huggingface_hub/_snapshot_download.py +14 -28
  9. huggingface_hub/_space_api.py +4 -4
  10. huggingface_hub/_tensorboard_logger.py +5 -5
  11. huggingface_hub/_upload_large_folder.py +15 -15
  12. huggingface_hub/_webhooks_payload.py +3 -3
  13. huggingface_hub/_webhooks_server.py +2 -2
  14. huggingface_hub/cli/__init__.py +0 -14
  15. huggingface_hub/cli/_cli_utils.py +80 -3
  16. huggingface_hub/cli/auth.py +104 -150
  17. huggingface_hub/cli/cache.py +102 -126
  18. huggingface_hub/cli/download.py +93 -110
  19. huggingface_hub/cli/hf.py +37 -41
  20. huggingface_hub/cli/jobs.py +689 -1017
  21. huggingface_hub/cli/lfs.py +120 -143
  22. huggingface_hub/cli/repo.py +158 -216
  23. huggingface_hub/cli/repo_files.py +50 -84
  24. huggingface_hub/cli/system.py +6 -25
  25. huggingface_hub/cli/upload.py +198 -212
  26. huggingface_hub/cli/upload_large_folder.py +90 -105
  27. huggingface_hub/commands/_cli_utils.py +2 -2
  28. huggingface_hub/commands/delete_cache.py +11 -11
  29. huggingface_hub/commands/download.py +4 -13
  30. huggingface_hub/commands/lfs.py +4 -4
  31. huggingface_hub/commands/repo_files.py +2 -2
  32. huggingface_hub/commands/tag.py +1 -3
  33. huggingface_hub/commands/upload.py +4 -4
  34. huggingface_hub/commands/upload_large_folder.py +3 -3
  35. huggingface_hub/commands/user.py +4 -5
  36. huggingface_hub/community.py +5 -5
  37. huggingface_hub/constants.py +3 -41
  38. huggingface_hub/dataclasses.py +16 -22
  39. huggingface_hub/errors.py +43 -30
  40. huggingface_hub/fastai_utils.py +8 -9
  41. huggingface_hub/file_download.py +154 -253
  42. huggingface_hub/hf_api.py +329 -558
  43. huggingface_hub/hf_file_system.py +104 -62
  44. huggingface_hub/hub_mixin.py +32 -54
  45. huggingface_hub/inference/_client.py +178 -163
  46. huggingface_hub/inference/_common.py +38 -54
  47. huggingface_hub/inference/_generated/_async_client.py +219 -259
  48. huggingface_hub/inference/_generated/types/automatic_speech_recognition.py +3 -3
  49. huggingface_hub/inference/_generated/types/base.py +10 -7
  50. huggingface_hub/inference/_generated/types/chat_completion.py +16 -16
  51. huggingface_hub/inference/_generated/types/depth_estimation.py +2 -2
  52. huggingface_hub/inference/_generated/types/document_question_answering.py +2 -2
  53. huggingface_hub/inference/_generated/types/feature_extraction.py +2 -2
  54. huggingface_hub/inference/_generated/types/fill_mask.py +2 -2
  55. huggingface_hub/inference/_generated/types/sentence_similarity.py +3 -3
  56. huggingface_hub/inference/_generated/types/summarization.py +2 -2
  57. huggingface_hub/inference/_generated/types/table_question_answering.py +4 -4
  58. huggingface_hub/inference/_generated/types/text2text_generation.py +2 -2
  59. huggingface_hub/inference/_generated/types/text_generation.py +10 -10
  60. huggingface_hub/inference/_generated/types/text_to_video.py +2 -2
  61. huggingface_hub/inference/_generated/types/token_classification.py +2 -2
  62. huggingface_hub/inference/_generated/types/translation.py +2 -2
  63. huggingface_hub/inference/_generated/types/zero_shot_classification.py +2 -2
  64. huggingface_hub/inference/_generated/types/zero_shot_image_classification.py +2 -2
  65. huggingface_hub/inference/_generated/types/zero_shot_object_detection.py +1 -3
  66. huggingface_hub/inference/_mcp/agent.py +3 -3
  67. huggingface_hub/inference/_mcp/constants.py +1 -2
  68. huggingface_hub/inference/_mcp/mcp_client.py +33 -22
  69. huggingface_hub/inference/_mcp/types.py +10 -10
  70. huggingface_hub/inference/_mcp/utils.py +4 -4
  71. huggingface_hub/inference/_providers/__init__.py +2 -13
  72. huggingface_hub/inference/_providers/_common.py +24 -25
  73. huggingface_hub/inference/_providers/black_forest_labs.py +6 -6
  74. huggingface_hub/inference/_providers/cohere.py +3 -3
  75. huggingface_hub/inference/_providers/fal_ai.py +25 -25
  76. huggingface_hub/inference/_providers/featherless_ai.py +4 -4
  77. huggingface_hub/inference/_providers/fireworks_ai.py +3 -3
  78. huggingface_hub/inference/_providers/hf_inference.py +13 -13
  79. huggingface_hub/inference/_providers/hyperbolic.py +4 -4
  80. huggingface_hub/inference/_providers/nebius.py +10 -10
  81. huggingface_hub/inference/_providers/novita.py +5 -5
  82. huggingface_hub/inference/_providers/nscale.py +4 -4
  83. huggingface_hub/inference/_providers/replicate.py +15 -15
  84. huggingface_hub/inference/_providers/sambanova.py +6 -6
  85. huggingface_hub/inference/_providers/together.py +7 -7
  86. huggingface_hub/lfs.py +24 -33
  87. huggingface_hub/repocard.py +16 -17
  88. huggingface_hub/repocard_data.py +56 -56
  89. huggingface_hub/serialization/__init__.py +0 -1
  90. huggingface_hub/serialization/_base.py +9 -9
  91. huggingface_hub/serialization/_dduf.py +7 -7
  92. huggingface_hub/serialization/_torch.py +28 -28
  93. huggingface_hub/utils/__init__.py +10 -4
  94. huggingface_hub/utils/_auth.py +5 -5
  95. huggingface_hub/utils/_cache_manager.py +31 -31
  96. huggingface_hub/utils/_deprecation.py +1 -1
  97. huggingface_hub/utils/_dotenv.py +3 -3
  98. huggingface_hub/utils/_fixes.py +0 -10
  99. huggingface_hub/utils/_git_credential.py +3 -3
  100. huggingface_hub/utils/_headers.py +7 -29
  101. huggingface_hub/utils/_http.py +369 -209
  102. huggingface_hub/utils/_pagination.py +4 -4
  103. huggingface_hub/utils/_paths.py +5 -5
  104. huggingface_hub/utils/_runtime.py +15 -13
  105. huggingface_hub/utils/_safetensors.py +21 -21
  106. huggingface_hub/utils/_subprocess.py +9 -9
  107. huggingface_hub/utils/_telemetry.py +3 -3
  108. huggingface_hub/utils/_typing.py +3 -3
  109. huggingface_hub/utils/_validators.py +53 -72
  110. huggingface_hub/utils/_xet.py +16 -16
  111. huggingface_hub/utils/_xet_progress_reporting.py +1 -1
  112. huggingface_hub/utils/insecure_hashlib.py +3 -9
  113. huggingface_hub/utils/tqdm.py +3 -3
  114. {huggingface_hub-0.35.1.dist-info → huggingface_hub-1.0.0rc1.dist-info}/METADATA +17 -26
  115. huggingface_hub-1.0.0rc1.dist-info/RECORD +161 -0
  116. huggingface_hub/inference/_providers/publicai.py +0 -6
  117. huggingface_hub/inference/_providers/scaleway.py +0 -28
  118. huggingface_hub/inference_api.py +0 -217
  119. huggingface_hub/keras_mixin.py +0 -500
  120. huggingface_hub/repository.py +0 -1477
  121. huggingface_hub/serialization/_tensorflow.py +0 -95
  122. huggingface_hub/utils/_hf_folder.py +0 -68
  123. huggingface_hub-0.35.1.dist-info/RECORD +0 -168
  124. {huggingface_hub-0.35.1.dist-info → huggingface_hub-1.0.0rc1.dist-info}/LICENSE +0 -0
  125. {huggingface_hub-0.35.1.dist-info → huggingface_hub-1.0.0rc1.dist-info}/WHEEL +0 -0
  126. {huggingface_hub-0.35.1.dist-info → huggingface_hub-1.0.0rc1.dist-info}/entry_points.txt +0 -0
  127. {huggingface_hub-0.35.1.dist-info → huggingface_hub-1.0.0rc1.dist-info}/top_level.txt +0 -0
@@ -11,10 +11,17 @@
11
11
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
- """Contains a utility for good-looking prints."""
14
+ """Contains CLI utilities (styling, helpers)."""
15
15
 
16
16
  import os
17
- from typing import List, Union
17
+ from enum import Enum
18
+ from typing import Annotated, Optional, Union
19
+
20
+ import click
21
+ import typer
22
+
23
+ from huggingface_hub import __version__
24
+ from huggingface_hub.hf_api import HfApi
18
25
 
19
26
 
20
27
  class ANSI:
@@ -52,7 +59,7 @@ class ANSI:
52
59
  return f"{code}{s}{cls._reset}"
53
60
 
54
61
 
55
- def tabulate(rows: List[List[Union[str, int]]], headers: List[str]) -> str:
62
+ def tabulate(rows: list[list[Union[str, int]]], headers: list[str]) -> str:
56
63
  """
57
64
  Inspired by:
58
65
 
@@ -67,3 +74,73 @@ def tabulate(rows: List[List[Union[str, int]]], headers: List[str]) -> str:
67
74
  for row in rows:
68
75
  lines.append(row_format.format(*row))
69
76
  return "\n".join(lines)
77
+
78
+
79
+ #### TYPER UTILS
80
+
81
+
82
+ class AlphabeticalMixedGroup(typer.core.TyperGroup):
83
+ """
84
+ Typer Group that lists commands and sub-apps mixed and alphabetically.
85
+ """
86
+
87
+ def list_commands(self, ctx: click.Context) -> list[str]: # type: ignore[name-defined]
88
+ # click.Group stores both commands and sub-groups in `self.commands`
89
+ return sorted(self.commands.keys())
90
+
91
+
92
+ def typer_factory(help: str) -> typer.Typer:
93
+ return typer.Typer(
94
+ help=help,
95
+ add_completion=True,
96
+ rich_markup_mode=None,
97
+ no_args_is_help=True,
98
+ cls=AlphabeticalMixedGroup,
99
+ )
100
+
101
+
102
+ class RepoType(str, Enum):
103
+ model = "model"
104
+ dataset = "dataset"
105
+ space = "space"
106
+
107
+
108
+ RepoIdArg = Annotated[
109
+ str,
110
+ typer.Argument(
111
+ help="The ID of the repo (e.g. `username/repo-name`).",
112
+ ),
113
+ ]
114
+
115
+
116
+ RepoTypeOpt = Annotated[
117
+ RepoType,
118
+ typer.Option(
119
+ help="The type of repository (model, dataset, or space).",
120
+ ),
121
+ ]
122
+
123
+ TokenOpt = Annotated[
124
+ Optional[str],
125
+ typer.Option(
126
+ help="A User Access Token generated from https://huggingface.co/settings/tokens.",
127
+ ),
128
+ ]
129
+
130
+ PrivateOpt = Annotated[
131
+ bool,
132
+ typer.Option(
133
+ help="Whether to create a private repo if repo doesn't exist on the Hub. Ignored if the repo already exists.",
134
+ ),
135
+ ]
136
+
137
+ RevisionOpt = Annotated[
138
+ Optional[str],
139
+ typer.Option(
140
+ help="Git revision id which can be a branch name, a tag, or a commit hash.",
141
+ ),
142
+ ]
143
+
144
+
145
+ def get_hf_api(token: Optional[str] = None) -> HfApi:
146
+ return HfApi(token=token, library_name="hf", library_version=__version__)
@@ -30,18 +30,17 @@ Usage:
30
30
  hf auth whoami
31
31
  """
32
32
 
33
- from argparse import _SubParsersAction
34
- from typing import List, Optional
33
+ from typing import Annotated, Optional
35
34
 
36
- from requests.exceptions import HTTPError
35
+ import typer
37
36
 
38
- from huggingface_hub.commands import BaseHuggingfaceCLICommand
39
37
  from huggingface_hub.constants import ENDPOINT
40
- from huggingface_hub.hf_api import HfApi
38
+ from huggingface_hub.errors import HfHubHTTPError
39
+ from huggingface_hub.hf_api import whoami
41
40
 
42
41
  from .._login import auth_list, auth_switch, login, logout
43
42
  from ..utils import get_stored_tokens, get_token, logging
44
- from ._cli_utils import ANSI
43
+ from ._cli_utils import ANSI, TokenOpt, typer_factory
45
44
 
46
45
 
47
46
  logger = logging.get_logger(__name__)
@@ -55,125 +54,42 @@ except ImportError:
55
54
  _inquirer_py_available = False
56
55
 
57
56
 
58
- class AuthCommands(BaseHuggingfaceCLICommand):
59
- @staticmethod
60
- def register_subcommand(parser: _SubParsersAction):
61
- # Create the main 'auth' command
62
- auth_parser = parser.add_parser("auth", help="Manage authentication (login, logout, etc.).")
63
- auth_subparsers = auth_parser.add_subparsers(help="Authentication subcommands")
64
-
65
- # Show help if no subcommand is provided
66
- auth_parser.set_defaults(func=lambda args: auth_parser.print_help())
67
-
68
- # Add 'login' as a subcommand of 'auth'
69
- login_parser = auth_subparsers.add_parser(
70
- "login", help="Log in using a token from huggingface.co/settings/tokens"
71
- )
72
- login_parser.add_argument(
73
- "--token",
74
- type=str,
75
- help="Token generated from https://huggingface.co/settings/tokens",
76
- )
77
- login_parser.add_argument(
78
- "--add-to-git-credential",
79
- action="store_true",
80
- help="Optional: Save token to git credential helper.",
81
- )
82
- login_parser.set_defaults(func=lambda args: AuthLogin(args))
83
-
84
- # Add 'logout' as a subcommand of 'auth'
85
- logout_parser = auth_subparsers.add_parser("logout", help="Log out")
86
- logout_parser.add_argument(
87
- "--token-name",
88
- type=str,
89
- help="Optional: Name of the access token to log out from.",
90
- )
91
- logout_parser.set_defaults(func=lambda args: AuthLogout(args))
92
-
93
- # Add 'whoami' as a subcommand of 'auth'
94
- whoami_parser = auth_subparsers.add_parser(
95
- "whoami", help="Find out which huggingface.co account you are logged in as."
96
- )
97
- whoami_parser.set_defaults(func=lambda args: AuthWhoami(args))
98
-
99
- # Existing subcommands
100
- auth_switch_parser = auth_subparsers.add_parser("switch", help="Switch between access tokens")
101
- auth_switch_parser.add_argument(
102
- "--token-name",
103
- type=str,
104
- help="Optional: Name of the access token to switch to.",
105
- )
106
- auth_switch_parser.add_argument(
107
- "--add-to-git-credential",
108
- action="store_true",
109
- help="Optional: Save token to git credential helper.",
110
- )
111
- auth_switch_parser.set_defaults(func=lambda args: AuthSwitch(args))
112
-
113
- auth_list_parser = auth_subparsers.add_parser("list", help="List all stored access tokens")
114
- auth_list_parser.set_defaults(func=lambda args: AuthList(args))
115
-
116
-
117
- class BaseAuthCommand:
118
- def __init__(self, args):
119
- self.args = args
120
- self._api = HfApi()
121
-
122
-
123
- class AuthLogin(BaseAuthCommand):
124
- def run(self):
125
- logging.set_verbosity_info()
126
- login(
127
- token=self.args.token,
128
- add_to_git_credential=self.args.add_to_git_credential,
129
- )
130
-
131
-
132
- class AuthLogout(BaseAuthCommand):
133
- def run(self):
134
- logging.set_verbosity_info()
135
- logout(token_name=self.args.token_name)
136
-
137
-
138
- class AuthSwitch(BaseAuthCommand):
139
- def run(self):
140
- logging.set_verbosity_info()
141
- token_name = self.args.token_name
142
- if token_name is None:
143
- token_name = self._select_token_name()
144
-
145
- if token_name is None:
146
- print("No token name provided. Aborting.")
147
- exit()
148
- auth_switch(token_name, add_to_git_credential=self.args.add_to_git_credential)
149
-
150
- def _select_token_name(self) -> Optional[str]:
151
- token_names = list(get_stored_tokens().keys())
152
-
153
- if not token_names:
154
- logger.error("No stored tokens found. Please login first.")
155
- return None
57
+ auth_cli = typer_factory(help="Manage authentication (login, logout, etc.).")
58
+
59
+
60
+ @auth_cli.command("login", help="Login using a token from huggingface.co/settings/tokens")
61
+ def auth_login(
62
+ token: TokenOpt = None,
63
+ add_to_git_credential: Annotated[
64
+ bool,
65
+ typer.Option(
66
+ help="Save to git credential helper. Useful only if you plan to run git commands directly.",
67
+ ),
68
+ ] = False,
69
+ ) -> None:
70
+ login(token=token, add_to_git_credential=add_to_git_credential)
71
+
72
+
73
+ @auth_cli.command("logout", help="Logout from a specific token")
74
+ def auth_logout(
75
+ token_name: Annotated[
76
+ Optional[str],
77
+ typer.Option(
78
+ help="Name of token to logout",
79
+ ),
80
+ ] = None,
81
+ ) -> None:
82
+ logout(token_name=token_name)
83
+
156
84
 
157
- if _inquirer_py_available:
158
- return self._select_token_name_tui(token_names)
159
- # if inquirer is not available, use a simpler terminal UI
160
- print("Available stored tokens:")
161
- for i, token_name in enumerate(token_names, 1):
162
- print(f"{i}. {token_name}")
163
- while True:
164
- try:
165
- choice = input("Enter the number of the token to switch to (or 'q' to quit): ")
166
- if choice.lower() == "q":
167
- return None
168
- index = int(choice) - 1
169
- if 0 <= index < len(token_names):
170
- return token_names[index]
171
- else:
172
- print("Invalid selection. Please try again.")
173
- except ValueError:
174
- print("Invalid input. Please enter a number or 'q' to quit.")
175
-
176
- def _select_token_name_tui(self, token_names: List[str]) -> Optional[str]:
85
+ def _select_token_name() -> Optional[str]:
86
+ token_names = list(get_stored_tokens().keys())
87
+
88
+ if not token_names:
89
+ logger.error("No stored tokens found. Please login first.")
90
+ return None
91
+
92
+ if _inquirer_py_available:
177
93
  choices = [Choice(token_name, name=token_name) for token_name in token_names]
178
94
  try:
179
95
  return inquirer.select(
@@ -184,30 +100,68 @@ class AuthSwitch(BaseAuthCommand):
184
100
  except KeyboardInterrupt:
185
101
  logger.info("Token selection cancelled.")
186
102
  return None
187
-
188
-
189
- class AuthList(BaseAuthCommand):
190
- def run(self):
191
- logging.set_verbosity_info()
192
- auth_list()
193
-
194
-
195
- class AuthWhoami(BaseAuthCommand):
196
- def run(self):
197
- token = get_token()
198
- if token is None:
199
- print("Not logged in")
200
- exit()
103
+ # if inquirer is not available, use a simpler terminal UI
104
+ print("Available stored tokens:")
105
+ for i, token_name in enumerate(token_names, 1):
106
+ print(f"{i}. {token_name}")
107
+ while True:
201
108
  try:
202
- info = self._api.whoami(token)
203
- print(ANSI.bold("user: "), info["name"])
204
- orgs = [org["name"] for org in info["orgs"]]
205
- if orgs:
206
- print(ANSI.bold("orgs: "), ",".join(orgs))
207
-
208
- if ENDPOINT != "https://huggingface.co":
209
- print(f"Authenticated through private endpoint: {ENDPOINT}")
210
- except HTTPError as e:
211
- print(e)
212
- print(ANSI.red(e.response.text))
213
- exit(1)
109
+ choice = input("Enter the number of the token to switch to (or 'q' to quit): ")
110
+ if choice.lower() == "q":
111
+ return None
112
+ index = int(choice) - 1
113
+ if 0 <= index < len(token_names):
114
+ return token_names[index]
115
+ else:
116
+ print("Invalid selection. Please try again.")
117
+ except ValueError:
118
+ print("Invalid input. Please enter a number or 'q' to quit.")
119
+
120
+
121
+ @auth_cli.command("switch", help="Switch between access tokens")
122
+ def auth_switch_cmd(
123
+ token_name: Annotated[
124
+ Optional[str],
125
+ typer.Option(
126
+ help="Name of the token to switch to",
127
+ ),
128
+ ] = None,
129
+ add_to_git_credential: Annotated[
130
+ bool,
131
+ typer.Option(
132
+ help="Save to git credential helper. Useful only if you plan to run git commands directly.",
133
+ ),
134
+ ] = False,
135
+ ) -> None:
136
+ if token_name is None:
137
+ token_name = _select_token_name()
138
+ if token_name is None:
139
+ print("No token name provided. Aborting.")
140
+ raise typer.Exit()
141
+ auth_switch(token_name, add_to_git_credential=add_to_git_credential)
142
+
143
+
144
+ @auth_cli.command("list", help="List all stored access tokens")
145
+ def auth_list_cmd() -> None:
146
+ auth_list()
147
+
148
+
149
+ @auth_cli.command("whoami", help="Find out which huggingface.co account you are logged in as.")
150
+ def auth_whoami() -> None:
151
+ token = get_token()
152
+ if token is None:
153
+ print("Not logged in")
154
+ raise typer.Exit()
155
+ try:
156
+ info = whoami(token)
157
+ print(ANSI.bold("user: "), info["name"])
158
+ orgs = [org["name"] for org in info["orgs"]]
159
+ if orgs:
160
+ print(ANSI.bold("orgs: "), ",".join(orgs))
161
+
162
+ if ENDPOINT != "https://huggingface.co":
163
+ print(f"Authenticated through private endpoint: {ENDPOINT}")
164
+ except HfHubHTTPError as e:
165
+ print(e)
166
+ print(ANSI.red(e.response.text))
167
+ raise typer.Exit(code=1)