@@ -9433,13 +9433,18 @@ def _validate_yaml(self, content: str, *, repo_type: Optional[str] = None, token
9433
9433
message = "\n " .join ([f"- { error .get ('message' )} " for error in errors ])
9434
9434
raise ValueError (f"Invalid metadata in README.md.\n { message } " ) from e
9435
9435
9436
- def get_user_overview (self , username : str ) -> User :
9436
+ def get_user_overview (self , username : str , token : Union [ bool , str , None ] = None ) -> User :
9437
9437
"""
9438
9438
Get an overview of a user on the Hub.
9439
9439
9440
9440
Args:
9441
9441
username (`str`):
9442
9442
Username of the user to get an overview of.
9443
+ token (Union[bool, str, None], optional):
9444
+ A valid user access token (string). Defaults to the locally saved
9445
+ token, which is the recommended method for authentication (see
9446
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
9447
+ To disable authentication, pass `False`.
9443
9448
9444
9449
Returns:
9445
9450
`User`: A [`User`] object with the user's overview.
@@ -9448,18 +9453,24 @@ def get_user_overview(self, username: str) -> User:
9448
9453
[`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError):
9449
9454
HTTP 404 If the user does not exist on the Hub.
9450
9455
"""
9451
- r = get_session ().get (f"{ constants .ENDPOINT } /api/users/{ username } /overview" )
9452
-
9456
+ r = get_session ().get (
9457
+ f"{ constants .ENDPOINT } /api/users/{ username } /overview" , headers = self ._build_hf_headers (token = token )
9458
+ )
9453
9459
hf_raise_for_status (r )
9454
9460
return User (** r .json ())
9455
9461
9456
- def list_organization_members (self , organization : str ) -> Iterable [User ]:
9462
+ def list_organization_members (self , organization : str , token : Union [ bool , str , None ] = None ) -> Iterable [User ]:
9457
9463
"""
9458
9464
List of members of an organization on the Hub.
9459
9465
9460
9466
Args:
9461
9467
organization (`str`):
9462
9468
Name of the organization to get the members of.
9469
+ token (Union[bool, str, None], optional):
9470
+ A valid user access token (string). Defaults to the locally saved
9471
+ token, which is the recommended method for authentication (see
9472
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
9473
+ To disable authentication, pass `False`.
9463
9474
9464
9475
Returns:
9465
9476
`Iterable[User]`: A list of [`User`] objects with the members of the organization.
@@ -9469,21 +9480,25 @@ def list_organization_members(self, organization: str) -> Iterable[User]:
9469
9480
HTTP 404 If the organization does not exist on the Hub.
9470
9481
9471
9482
"""
9472
-
9473
- r = get_session ().get (f"{ constants .ENDPOINT } /api/organizations/{ organization } /members" )
9474
-
9475
- hf_raise_for_status (r )
9476
-
9477
- for member in r .json ():
9483
+ for member in paginate (
9484
+ path = f"{ constants .ENDPOINT } /api/organizations/{ organization } /members" ,
9485
+ params = {},
9486
+ headers = self ._build_hf_headers (token = token ),
9487
+ ):
9478
9488
yield User (** member )
9479
9489
9480
- def list_user_followers (self , username : str ) -> Iterable [User ]:
9490
+ def list_user_followers (self , username : str , token : Union [ bool , str , None ] = None ) -> Iterable [User ]:
9481
9491
"""
9482
9492
Get the list of followers of a user on the Hub.
9483
9493
9484
9494
Args:
9485
9495
username (`str`):
9486
9496
Username of the user to get the followers of.
9497
+ token (Union[bool, str, None], optional):
9498
+ A valid user access token (string). Defaults to the locally saved
9499
+ token, which is the recommended method for authentication (see
9500
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
9501
+ To disable authentication, pass `False`.
9487
9502
9488
9503
Returns:
9489
9504
`Iterable[User]`: A list of [`User`] objects with the followers of the user.
@@ -9493,21 +9508,25 @@ def list_user_followers(self, username: str) -> Iterable[User]:
9493
9508
HTTP 404 If the user does not exist on the Hub.
9494
9509
9495
9510
"""
9496
-
9497
- r = get_session ().get (f"{ constants .ENDPOINT } /api/users/{ username } /followers" )
9498
-
9499
- hf_raise_for_status (r )
9500
-
9501
- for follower in r .json ():
9511
+ for follower in paginate (
9512
+ path = f"{ constants .ENDPOINT } /api/users/{ username } /followers" ,
9513
+ params = {},
9514
+ headers = self ._build_hf_headers (token = token ),
9515
+ ):
9502
9516
yield User (** follower )
9503
9517
9504
- def list_user_following (self , username : str ) -> Iterable [User ]:
9518
+ def list_user_following (self , username : str , token : Union [ bool , str , None ] = None ) -> Iterable [User ]:
9505
9519
"""
9506
9520
Get the list of users followed by a user on the Hub.
9507
9521
9508
9522
Args:
9509
9523
username (`str`):
9510
9524
Username of the user to get the users followed by.
9525
+ token (Union[bool, str, None], optional):
9526
+ A valid user access token (string). Defaults to the locally saved
9527
+ token, which is the recommended method for authentication (see
9528
+ https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
9529
+ To disable authentication, pass `False`.
9511
9530
9512
9531
Returns:
9513
9532
`Iterable[User]`: A list of [`User`] objects with the users followed by the user.
@@ -9517,12 +9536,11 @@ def list_user_following(self, username: str) -> Iterable[User]:
9517
9536
HTTP 404 If the user does not exist on the Hub.
9518
9537
9519
9538
"""
9520
-
9521
- r = get_session ().get (f"{ constants .ENDPOINT } /api/users/{ username } /following" )
9522
-
9523
- hf_raise_for_status (r )
9524
-
9525
- for followed_user in r .json ():
9539
+ for followed_user in paginate (
9540
+ path = f"{ constants .ENDPOINT } /api/users/{ username } /following" ,
9541
+ params = {},
9542
+ headers = self ._build_hf_headers (token = token ),
9543
+ ):
9526
9544
yield User (** followed_user )
9527
9545
9528
9546
0 commit comments