huggingface-hub 0.36.0rc0__py3-none-any.whl → 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


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

Files changed (132) hide show
  1. huggingface_hub/__init__.py +33 -45
  2. huggingface_hub/_commit_api.py +39 -43
  3. huggingface_hub/_commit_scheduler.py +11 -8
  4. huggingface_hub/_inference_endpoints.py +8 -8
  5. huggingface_hub/_jobs_api.py +20 -20
  6. huggingface_hub/_login.py +17 -43
  7. huggingface_hub/_oauth.py +8 -8
  8. huggingface_hub/_snapshot_download.py +135 -50
  9. huggingface_hub/_space_api.py +4 -4
  10. huggingface_hub/_tensorboard_logger.py +5 -5
  11. huggingface_hub/_upload_large_folder.py +18 -32
  12. huggingface_hub/_webhooks_payload.py +3 -3
  13. huggingface_hub/_webhooks_server.py +2 -2
  14. huggingface_hub/cli/__init__.py +0 -14
  15. huggingface_hub/cli/_cli_utils.py +143 -39
  16. huggingface_hub/cli/auth.py +105 -171
  17. huggingface_hub/cli/cache.py +594 -361
  18. huggingface_hub/cli/download.py +120 -112
  19. huggingface_hub/cli/hf.py +38 -41
  20. huggingface_hub/cli/jobs.py +689 -1017
  21. huggingface_hub/cli/lfs.py +120 -143
  22. huggingface_hub/cli/repo.py +282 -216
  23. huggingface_hub/cli/repo_files.py +50 -84
  24. huggingface_hub/cli/system.py +6 -25
  25. huggingface_hub/cli/upload.py +198 -220
  26. huggingface_hub/cli/upload_large_folder.py +91 -106
  27. huggingface_hub/community.py +5 -5
  28. huggingface_hub/constants.py +17 -52
  29. huggingface_hub/dataclasses.py +135 -21
  30. huggingface_hub/errors.py +47 -30
  31. huggingface_hub/fastai_utils.py +8 -9
  32. huggingface_hub/file_download.py +351 -303
  33. huggingface_hub/hf_api.py +398 -570
  34. huggingface_hub/hf_file_system.py +101 -66
  35. huggingface_hub/hub_mixin.py +32 -54
  36. huggingface_hub/inference/_client.py +177 -162
  37. huggingface_hub/inference/_common.py +38 -54
  38. huggingface_hub/inference/_generated/_async_client.py +218 -258
  39. huggingface_hub/inference/_generated/types/automatic_speech_recognition.py +3 -3
  40. huggingface_hub/inference/_generated/types/base.py +10 -7
  41. huggingface_hub/inference/_generated/types/chat_completion.py +16 -16
  42. huggingface_hub/inference/_generated/types/depth_estimation.py +2 -2
  43. huggingface_hub/inference/_generated/types/document_question_answering.py +2 -2
  44. huggingface_hub/inference/_generated/types/feature_extraction.py +2 -2
  45. huggingface_hub/inference/_generated/types/fill_mask.py +2 -2
  46. huggingface_hub/inference/_generated/types/sentence_similarity.py +3 -3
  47. huggingface_hub/inference/_generated/types/summarization.py +2 -2
  48. huggingface_hub/inference/_generated/types/table_question_answering.py +4 -4
  49. huggingface_hub/inference/_generated/types/text2text_generation.py +2 -2
  50. huggingface_hub/inference/_generated/types/text_generation.py +10 -10
  51. huggingface_hub/inference/_generated/types/text_to_video.py +2 -2
  52. huggingface_hub/inference/_generated/types/token_classification.py +2 -2
  53. huggingface_hub/inference/_generated/types/translation.py +2 -2
  54. huggingface_hub/inference/_generated/types/zero_shot_classification.py +2 -2
  55. huggingface_hub/inference/_generated/types/zero_shot_image_classification.py +2 -2
  56. huggingface_hub/inference/_generated/types/zero_shot_object_detection.py +1 -3
  57. huggingface_hub/inference/_mcp/agent.py +3 -3
  58. huggingface_hub/inference/_mcp/constants.py +1 -2
  59. huggingface_hub/inference/_mcp/mcp_client.py +33 -22
  60. huggingface_hub/inference/_mcp/types.py +10 -10
  61. huggingface_hub/inference/_mcp/utils.py +4 -4
  62. huggingface_hub/inference/_providers/__init__.py +12 -4
  63. huggingface_hub/inference/_providers/_common.py +62 -24
  64. huggingface_hub/inference/_providers/black_forest_labs.py +6 -6
  65. huggingface_hub/inference/_providers/cohere.py +3 -3
  66. huggingface_hub/inference/_providers/fal_ai.py +25 -25
  67. huggingface_hub/inference/_providers/featherless_ai.py +4 -4
  68. huggingface_hub/inference/_providers/fireworks_ai.py +3 -3
  69. huggingface_hub/inference/_providers/hf_inference.py +13 -13
  70. huggingface_hub/inference/_providers/hyperbolic.py +4 -4
  71. huggingface_hub/inference/_providers/nebius.py +10 -10
  72. huggingface_hub/inference/_providers/novita.py +5 -5
  73. huggingface_hub/inference/_providers/nscale.py +4 -4
  74. huggingface_hub/inference/_providers/replicate.py +15 -15
  75. huggingface_hub/inference/_providers/sambanova.py +6 -6
  76. huggingface_hub/inference/_providers/together.py +7 -7
  77. huggingface_hub/lfs.py +21 -94
  78. huggingface_hub/repocard.py +15 -16
  79. huggingface_hub/repocard_data.py +57 -57
  80. huggingface_hub/serialization/__init__.py +0 -1
  81. huggingface_hub/serialization/_base.py +9 -9
  82. huggingface_hub/serialization/_dduf.py +7 -7
  83. huggingface_hub/serialization/_torch.py +28 -28
  84. huggingface_hub/utils/__init__.py +11 -6
  85. huggingface_hub/utils/_auth.py +5 -5
  86. huggingface_hub/utils/_cache_manager.py +49 -74
  87. huggingface_hub/utils/_deprecation.py +1 -1
  88. huggingface_hub/utils/_dotenv.py +3 -3
  89. huggingface_hub/utils/_fixes.py +0 -10
  90. huggingface_hub/utils/_git_credential.py +3 -3
  91. huggingface_hub/utils/_headers.py +7 -29
  92. huggingface_hub/utils/_http.py +371 -208
  93. huggingface_hub/utils/_pagination.py +4 -4
  94. huggingface_hub/utils/_parsing.py +98 -0
  95. huggingface_hub/utils/_paths.py +5 -5
  96. huggingface_hub/utils/_runtime.py +59 -23
  97. huggingface_hub/utils/_safetensors.py +21 -21
  98. huggingface_hub/utils/_subprocess.py +9 -9
  99. huggingface_hub/utils/_telemetry.py +3 -3
  100. huggingface_hub/{commands/_cli_utils.py → utils/_terminal.py} +4 -9
  101. huggingface_hub/utils/_typing.py +3 -3
  102. huggingface_hub/utils/_validators.py +53 -72
  103. huggingface_hub/utils/_xet.py +16 -16
  104. huggingface_hub/utils/_xet_progress_reporting.py +1 -1
  105. huggingface_hub/utils/insecure_hashlib.py +3 -9
  106. huggingface_hub/utils/tqdm.py +3 -3
  107. {huggingface_hub-0.36.0rc0.dist-info → huggingface_hub-1.0.0.dist-info}/METADATA +16 -35
  108. huggingface_hub-1.0.0.dist-info/RECORD +152 -0
  109. {huggingface_hub-0.36.0rc0.dist-info → huggingface_hub-1.0.0.dist-info}/entry_points.txt +0 -1
  110. huggingface_hub/commands/__init__.py +0 -27
  111. huggingface_hub/commands/delete_cache.py +0 -476
  112. huggingface_hub/commands/download.py +0 -204
  113. huggingface_hub/commands/env.py +0 -39
  114. huggingface_hub/commands/huggingface_cli.py +0 -65
  115. huggingface_hub/commands/lfs.py +0 -200
  116. huggingface_hub/commands/repo.py +0 -151
  117. huggingface_hub/commands/repo_files.py +0 -132
  118. huggingface_hub/commands/scan_cache.py +0 -183
  119. huggingface_hub/commands/tag.py +0 -161
  120. huggingface_hub/commands/upload.py +0 -318
  121. huggingface_hub/commands/upload_large_folder.py +0 -131
  122. huggingface_hub/commands/user.py +0 -208
  123. huggingface_hub/commands/version.py +0 -40
  124. huggingface_hub/inference_api.py +0 -217
  125. huggingface_hub/keras_mixin.py +0 -497
  126. huggingface_hub/repository.py +0 -1471
  127. huggingface_hub/serialization/_tensorflow.py +0 -92
  128. huggingface_hub/utils/_hf_folder.py +0 -68
  129. huggingface_hub-0.36.0rc0.dist-info/RECORD +0 -170
  130. {huggingface_hub-0.36.0rc0.dist-info → huggingface_hub-1.0.0.dist-info}/LICENSE +0 -0
  131. {huggingface_hub-0.36.0rc0.dist-info → huggingface_hub-1.0.0.dist-info}/WHEEL +0 -0
  132. {huggingface_hub-0.36.0rc0.dist-info → huggingface_hub-1.0.0.dist-info}/top_level.txt +0 -0
@@ -30,184 +30,118 @@ 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
- from ..utils import get_stored_tokens, get_token, logging
44
- from ._cli_utils import ANSI
42
+ from ..utils import ANSI, get_stored_tokens, get_token, logging
43
+ from ._cli_utils import TokenOpt, typer_factory
45
44
 
46
45
 
47
46
  logger = logging.get_logger(__name__)
48
47
 
49
- try:
50
- from InquirerPy import inquirer
51
- from InquirerPy.base.control import Choice
52
-
53
- _inquirer_py_available = True
54
- except ImportError:
55
- _inquirer_py_available = False
56
-
57
-
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
156
-
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]:
177
- choices = [Choice(token_name, name=token_name) for token_name in token_names]
178
- try:
179
- return inquirer.select(
180
- message="Select a token to switch to:",
181
- choices=choices,
182
- default=None,
183
- ).execute()
184
- except KeyboardInterrupt:
185
- logger.info("Token selection cancelled.")
186
- 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()
48
+
49
+ auth_cli = typer_factory(help="Manage authentication (login, logout, etc.).")
50
+
51
+
52
+ @auth_cli.command("login", help="Login using a token from huggingface.co/settings/tokens")
53
+ def auth_login(
54
+ token: TokenOpt = None,
55
+ add_to_git_credential: Annotated[
56
+ bool,
57
+ typer.Option(
58
+ help="Save to git credential helper. Useful only if you plan to run git commands directly.",
59
+ ),
60
+ ] = False,
61
+ ) -> None:
62
+ login(token=token, add_to_git_credential=add_to_git_credential)
63
+
64
+
65
+ @auth_cli.command("logout", help="Logout from a specific token")
66
+ def auth_logout(
67
+ token_name: Annotated[
68
+ Optional[str],
69
+ typer.Option(
70
+ help="Name of token to logout",
71
+ ),
72
+ ] = None,
73
+ ) -> None:
74
+ logout(token_name=token_name)
75
+
76
+
77
+ def _select_token_name() -> Optional[str]:
78
+ token_names = list(get_stored_tokens().keys())
79
+
80
+ if not token_names:
81
+ logger.error("No stored tokens found. Please login first.")
82
+ return None
83
+
84
+ print("Available stored tokens:")
85
+ for i, token_name in enumerate(token_names, 1):
86
+ print(f"{i}. {token_name}")
87
+ while True:
201
88
  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)
89
+ choice = input("Enter the number of the token to switch to (or 'q' to quit): ")
90
+ if choice.lower() == "q":
91
+ return None
92
+ index = int(choice) - 1
93
+ if 0 <= index < len(token_names):
94
+ return token_names[index]
95
+ else:
96
+ print("Invalid selection. Please try again.")
97
+ except ValueError:
98
+ print("Invalid input. Please enter a number or 'q' to quit.")
99
+
100
+
101
+ @auth_cli.command("switch", help="Switch between access tokens")
102
+ def auth_switch_cmd(
103
+ token_name: Annotated[
104
+ Optional[str],
105
+ typer.Option(
106
+ help="Name of the token to switch to",
107
+ ),
108
+ ] = None,
109
+ add_to_git_credential: Annotated[
110
+ bool,
111
+ typer.Option(
112
+ help="Save to git credential helper. Useful only if you plan to run git commands directly.",
113
+ ),
114
+ ] = False,
115
+ ) -> None:
116
+ if token_name is None:
117
+ token_name = _select_token_name()
118
+ if token_name is None:
119
+ print("No token name provided. Aborting.")
120
+ raise typer.Exit()
121
+ auth_switch(token_name, add_to_git_credential=add_to_git_credential)
122
+
123
+
124
+ @auth_cli.command("list", help="List all stored access tokens")
125
+ def auth_list_cmd() -> None:
126
+ auth_list()
127
+
128
+
129
+ @auth_cli.command("whoami", help="Find out which huggingface.co account you are logged in as.")
130
+ def auth_whoami() -> None:
131
+ token = get_token()
132
+ if token is None:
133
+ print("Not logged in")
134
+ raise typer.Exit()
135
+ try:
136
+ info = whoami(token)
137
+ print(ANSI.bold("user: "), info["name"])
138
+ orgs = [org["name"] for org in info["orgs"]]
139
+ if orgs:
140
+ print(ANSI.bold("orgs: "), ",".join(orgs))
141
+
142
+ if ENDPOINT != "https://huggingface.co":
143
+ print(f"Authenticated through private endpoint: {ENDPOINT}")
144
+ except HfHubHTTPError as e:
145
+ print(e)
146
+ print(ANSI.red(e.response.text))
147
+ raise typer.Exit(code=1)