Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
35 changes: 34 additions & 1 deletion src/huggingface_hub/hf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9890,6 +9890,12 @@ def list_daily_papers(
*,
date: Optional[str] = None,
token: Union[bool, str, None] = None,
week: Optional[str] = None,
month: Optional[str] = None,
submitter: Optional[str] = None,
sort: Optional[Literal["publishedAt", "trending"]] = None,
p: Optional[int] = None,
limit: Optional[int] = None,
) -> Iterable[PaperInfo]:
"""
List the daily papers published on a given date on the Hugging Face Hub.
Expand All @@ -9901,6 +9907,19 @@ def list_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`.
week (`str`, *optional*):
Week in ISO format (YYYY-Www) for which to fetch daily papers. Example, `2025-W09`.
month (`str`, *optional*):
Month in ISO format (YYYY-MM) for which to fetch daily papers. Example, `2025-02`.
submitter (`str`, *optional*):
Username of the submitter to filter daily papers.
sort (`Literal["publishedAt", "trending"]`, *optional*):
Sort order for the daily papers. Can be either by `publishedAt` or by `trending`.
Defaults to `"publishedAt"`
p (`int`, *optional*):
Page number for pagination. Defaults to 0.
limit (`int`, *optional*):
Limit of papers to fetch. Defaults to 50.

Returns:
`Iterable[PaperInfo]`: an iterable of [`huggingface_hub.hf_api.PaperInfo`] objects.
Expand All @@ -9915,7 +9934,21 @@ def list_daily_papers(
```
"""
path = f"{self.endpoint}/api/daily_papers"
params = {"date": date} if date is not None else {}

params = {
k: v
for k, v in {
"p": p,
"limit": limit,
"sort": sort,
"date": date,
"week": week,
"month": month,
"submitter": submitter,
}.items()
if v is not None
}

r = get_session().get(path, params=params, headers=self._build_hf_headers(token=token))
hf_raise_for_status(r)
for paper in r.json():
Expand Down
45 changes: 45 additions & 0 deletions tests/test_hf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4299,6 +4299,51 @@ def test_list_daily_papers_default_date(self) -> None:
assert hasattr(papers[0], "id")
assert hasattr(papers[0], "title")

def test_list_daily_papers_week(self) -> None:
week = 44
papers = list(self.api.list_daily_papers(week=f"2025-W{week}"))
assert len(papers) > 0
first_paper = papers[0]
last_paper = papers[-1]

# friday of previous week
week_start = datetime.datetime.fromisocalendar(2025, week - 1, 5).replace(tzinfo=datetime.timezone.utc)
week_end = datetime.datetime.fromisocalendar(2025, week, 7).replace(tzinfo=datetime.timezone.utc)
assert week_start <= first_paper.submitted_at <= week_end
assert week_start <= last_paper.submitted_at <= week_end

def test_list_daily_papers_month(self) -> None:
month = 10
papers = list(self.api.list_daily_papers(month=f"2025-{month}"))
assert len(papers) > 0
first_paper = papers[0]
last_paper = papers[-1]
# last day of previous month
month_start = datetime.datetime(2025, month, 1, tzinfo=datetime.timezone.utc) - datetime.timedelta(days=1)
month_end = datetime.datetime(2025, month + 1, 1, tzinfo=datetime.timezone.utc) - datetime.timedelta(days=1)
assert month_start <= first_paper.submitted_at <= month_end
assert month_start <= last_paper.submitted_at <= month_end

def test_daily_papers_submitter(self) -> None:
papers = list(self.api.list_daily_papers(submitter="akhaliq"))
assert len(papers) > 0
assert papers[0].submitted_by.fullname == "AK"

def test_daily_papers_sort(self) -> None:
papers = list(self.api.list_daily_papers(date="2025-10-29", sort="trending"))
assert len(papers) > 0
first_paper = papers[0]
last_paper = papers[-1]
assert first_paper.upvotes >= last_paper.upvotes

def test_daily_papers_p(self) -> None:
papers = list(self.api.list_daily_papers(date="2025-10-29", p=100))
assert len(papers) == 0

def test_daily_papers_limit(self) -> None:
papers = list(self.api.list_daily_papers(date="2025-10-29", limit=10))
assert len(papers) == 10


class WebhookApiTest(HfApiCommonTest):
def setUp(self) -> None:
Expand Down
Loading