Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/huggingface_hub/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@
"list_lfs_files",
"list_liked_repos",
"list_models",
"list_organization_followers",
"list_organization_members",
"list_papers",
"list_pending_access_requests",
Expand Down Expand Up @@ -893,6 +894,7 @@
"list_lfs_files",
"list_liked_repos",
"list_models",
"list_organization_followers",
"list_organization_members",
"list_papers",
"list_pending_access_requests",
Expand Down Expand Up @@ -1249,6 +1251,7 @@ def __dir__():
list_lfs_files, # noqa: F401
list_liked_repos, # noqa: F401
list_models, # noqa: F401
list_organization_followers, # noqa: F401
list_organization_members, # noqa: F401
list_papers, # noqa: F401
list_pending_access_requests, # noqa: F401
Expand Down
32 changes: 32 additions & 0 deletions src/huggingface_hub/hf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9528,6 +9528,37 @@ def get_organization_overview(self, organization: str, token: Union[bool, str, N
hf_raise_for_status(r)
return Organization(**r.json())

@validate_hf_hub_args
def list_organization_followers(
self, organization: str, token: Union[bool, str, None] = None
) -> Iterable[User]:
"""
List followers of an organization on the Hub.

Args:
organization (`str`):
Name of the organization to get the followers of.
token (`bool` or `str`, *optional*):
A valid user access token (string). Defaults to the locally saved
token, which is the recommended method for authentication (see
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
To disable authentication, pass `False`.

Returns:
`Iterable[User]`: A list of [`User`] objects with the followers of the organization.

Raises:
[`HfHubHTTPError`]:
HTTP 404 If the organization does not exist on the Hub.

"""
for follower in paginate(
path=f"{constants.ENDPOINT}/api/organizations/{organization}/followers",
params={},
headers=self._build_hf_headers(token=token),
):
yield User(**follower)

def list_organization_members(self, organization: str, token: Union[bool, str, None] = None) -> Iterable[User]:
"""
List of members of an organization on the Hub.
Expand Down Expand Up @@ -10819,6 +10850,7 @@ def _parse_revision_from_pr_url(pr_url: str) -> str:
# User API
get_user_overview = api.get_user_overview
get_organization_overview = api.get_organization_overview
list_organization_followers = api.list_organization_followers
list_organization_members = api.list_organization_members
list_user_followers = api.list_user_followers
list_user_following = api.list_user_following
Expand Down
8 changes: 8 additions & 0 deletions tests/test_hf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4247,6 +4247,14 @@ def test_organization_members(self) -> None:
members = self.api.list_organization_members("huggingface")
assert len(list(members)) > 1

def test_organization_followers(self) -> None:
followers = self.api.list_organization_followers("huggingface")
first_follower = next(followers)
assert isinstance(first_follower, User)
assert first_follower.username
assert first_follower.fullname
assert first_follower.avatar_url

def test_user_followers(self) -> None:
followers = self.api.list_user_followers("clem")
assert len(list(followers)) > 500
Expand Down
Loading