diff --git a/src/huggingface_hub/hf_api.py b/src/huggingface_hub/hf_api.py index 17b55ce3a5..bca395e6a5 100644 --- a/src/huggingface_hub/hf_api.py +++ b/src/huggingface_hub/hf_api.py @@ -9702,6 +9702,41 @@ def paper_info(self, id: str) -> PaperInfo: hf_raise_for_status(r) return PaperInfo(**r.json()) + def list_daily_papers( + self, + *, + date: str, + token: Union[bool, str, None] = None, + ) -> Iterable[PaperInfo]: + """ + List the daily papers published on a given date on the Hugging Face Hub. + + Args: + date (`str`): + Date in ISO format (YYYY-MM-DD) for which to fetch daily papers. + token (Union[bool, str, None], *optional*): + A valid user access token (string). Defaults to the locally saved + token. To disable authentication, pass `False`. + + Returns: + `Iterable[PaperInfo]`: an iterable of [`huggingface_hub.hf_api.PaperInfo`] objects. + + Example: + + ```python + >>> from huggingface_hub import HfApi + + >>> api = HfApi() + >>> list(api.list_daily_papers(date="2025-10-29")) + ``` + """ + path = f"{self.endpoint}/api/daily_papers" + params = {"date": date} + r = get_session().get(path, params=params, headers=self._build_hf_headers(token=token)) + hf_raise_for_status(r) + for paper in r.json(): + yield PaperInfo(**paper) + def auth_check( self, repo_id: str, *, repo_type: Optional[str] = None, token: Union[bool, str, None] = None ) -> None: @@ -10723,6 +10758,7 @@ def _parse_revision_from_pr_url(pr_url: str) -> str: list_papers = api.list_papers paper_info = api.paper_info +list_daily_papers = api.list_daily_papers repo_exists = api.repo_exists revision_exists = api.revision_exists diff --git a/tests/test_hf_api.py b/tests/test_hf_api.py index e700dde3b0..014928101c 100644 --- a/tests/test_hf_api.py +++ b/tests/test_hf_api.py @@ -64,6 +64,7 @@ SpaceInfo, SpaceRuntime, User, + PaperInfo, WebhookInfo, WebhookWatchedItem, repo_type_and_id_from_hf_id, @@ -4228,6 +4229,16 @@ def test_get_paper_by_id_not_found(self) -> None: self.api.paper_info("1234.56789") assert context.exception.response.status_code == 404 + def test_list_daily_papers_by_date(self) -> None: + papers = list(self.api.list_daily_papers(date="2025-10-29")) + assert len(papers) > 0 + assert hasattr(papers[0], "id") + assert hasattr(papers[0], "title") + + def test_list_daily_papers_by_date_invalid_date(self) -> None: + with self.assertRaises(ValueError): + list(self.api.list_daily_papers(date="2025-13-40")) + class WebhookApiTest(HfApiCommonTest): def setUp(self) -> None: