Search plans and quota-aware retrieval¶
The Elsevier Scopus Search API bounds a retrieval in three ways. A weekly quota limits how many requests you may make, a short-term rate limit caps how fast you may make them, and offset paging stops at the first 5000 records of a query. This guide shows how scopusflow works within those bounds to make a large retrieval cheap to plan, accurate about its size and resumable when it stops. Every example assumes import scopusflow as sf. The steps that count or fetch records contact the API and need a Scopus key configured for pybliometrics, so they are shown but not run here. Building queries and plans is offline and runs anywhere.
Size before you spend¶
Counting is cheap. scopus_count issues a single request that asks the API how many records a query matches without downloading any of them. Use it to size a search before committing quota to a harvest. It takes the same years and field arguments as a plan, so you can size what you intend to fetch. It counts the years as one inclusive range from the earliest to the latest, as an unpartitioned plan sends them. For a year-partitioned plan over years with gaps between them, such as [2015, 2020], it therefore also counts the years between.
import pybliometrics
import scopusflow as sf
pybliometrics.init() # once per session, before the first search
q = sf.scopus_query("language learning", "effect size", field="TITLE-ABS-KEY")
# One cheap request; returns an int. Needs a Scopus key.
n = sf.scopus_count(q, years=range(2010, 2021))
n
Because the result is a plain integer, you can branch on it before spending more quota, for instance to check whether the search fits within the 5000 records that offset paging can retrieve.
if sf.scopus_count(q) > 5000:
print("More than offset paging can retrieve in one piece. Page by cursor or partition.")
Why partition by year¶
A SearchPlan with partition="year" turns one search into one cell per year. Each cell carries the same wrapped query and a single year, so it contacts the API as a search of its own. A finished year is checkpointed, so an interrupted harvest resumes from the first unfinished one. Each year's row count is checked against the total the API reports for it, so a shortfall is traced to the year in which it occurred. A long harvest also reports its progress year by year.
The year of publication is the natural facet to split on, because it is recorded on every record and divides a literature without leaving gaps or overlaps. The plan is a plain object that describes the search before it is run, so it can be printed and version-controlled alongside the analysis.
plan = sf.SearchPlan(q, years=range(2010, 2021), partition="year")
# One cell per year, each fetched, checkpointed and checked on its own.
out([(c.cell, c.year) for c in plan.cells()])
[(1, 2010), (2, 2011), (3, 2012), (4, 2013), (5, 2014), (6, 2015), (7, 2016), (8, 2017), (9, 2018), (10, 2019), (11, 2020)]
Each cell sends the wrapped_query, with the field tag already applied, and appends its own year, as AND PUBYEAR IS 2010 for the first cell. A query with a top-level OR, AND NOT or proximity operator is put in brackets before the year is added, so the limit applies to all of it. Inspecting the query is offline, so you can read what each cell will ask for before any request is made.
out(plan.wrapped_query)
TITLE-ABS-KEY(language learning) AND TITLE-ABS-KEY(effect size)
The partition matters most under offset paging. By default, fetch_plan pages each cell by cursor, and a cursor retrieves a cell of any size. Given cursor=False, it pages by offset instead, the route pybliometrics documents for keys without a Scopus subscription. Offset paging cannot retrieve a search that matches more than 5000 records. pybliometrics raises a ScopusQueryError for such a cell after one request, and fetch_plan raises it again with the cell named. Under offset paging, the partition is therefore what makes a large search retrievable, and each year has to stay under the ceiling on its own.
Before an offset-paged harvest, run scopus_count over the same years. If the total exceeds 5000, you know before any fetch begins that the year partition is needed. scopus_trend counts the years one by one, which also shows whether any single year exceeds the ceiling.
total = sf.scopus_count(q, years=range(2010, 2021))
plan = sf.SearchPlan(
q,
years=range(2010, 2021),
partition="year" if total > 5000 else "none",
)
records = sf.fetch_plan(plan, cursor=False)
The R twin's scopus_fetch_plan() pages by offset unless given cursor = TRUE. Each twin keeps the default it has always had, since a checkpoint records the paging mode it was fetched under and serves only a harvest in the same mode. A changed default would refetch every cell of every existing cache, each with a warning that names both modes.
A resumable, checkpointed harvest¶
fetch_plan runs the cells in turn and returns one normalised frame. Given a cache_dir, it writes each cell to disk as it completes, so a run interrupted halfway, or stopped by the quota, resumes from where it left off and never spends quota twice on the same cell. Resuming is the default, so a second call against the same directory reads the finished cells back from disk and only fetches what is missing.
records = sf.fetch_plan(plan, cache_dir="language-harvest", resume=True)
records.shape
A cache directory belongs to one plan. Checkpoints are keyed by cell number, and each is written with a manifest beside it, cell-001.json for the first cell. The manifest records the query as sent, the view, the page size and the paging mode. On resume, a checkpoint is served only when all four match the cell and its records carry no other query or view, so a checkpoint written by a different plan is warned about and refetched. The check also covers a cell that found nothing, whose empty checkpoint holds no records to show which search wrote it. Give each plan its own directory all the same, since that refetch spends the quota the cache was meant to save.
A checkpoint whose row count differs from the one its manifest records is also refetched with a warning. A checkpoint fetched with fields="extended" serves a core harvest with the extra columns dropped, while a core checkpoint is refetched with a warning for an extended harvest.
The manifest also records the cell's reported total, the time it was retrieved and the scopusflow version. A harvest resumed from its checkpoints is therefore dated, and its completeness stated, in the search record. It is dated from its first cell's retrieval to its last cell's, so a harvest finished days after it began gives the date of its last search, as PRISMA-S asks.
Checkpoints written by earlier versions of scopusflow have no manifest. A non-empty one is still served when the query and view its records carry match the cell and the harvest is paged by cursor, as every earlier version paged. It comes without a total, time or version, so the search record reports those as unrecorded. An empty one is fetched again, at one request per cell, and the harvest warns once.
The checkpoint format is parquet by default and falls back to CSV when no parquet engine is installed. You can ask for CSV explicitly when you want checkpoints you can open in any tool.
records = sf.fetch_plan(plan, cache_dir="language-harvest", format="csv")
For a long harvest, you can pass fetch_plan a zero-argument should_stop callable. It is checked before each cell, and when it returns True, the harvest stops early and returns what it has gathered so far. Because every completed cell is on disk, stopping this way costs nothing for the work already done, and the next call resumes from the first unfinished cell.
import time
deadline = time.monotonic() + 600 # stop politely after ten minutes
records = sf.fetch_plan(
plan,
cache_dir="language-harvest",
should_stop=lambda: time.monotonic() > deadline,
)
A harvest stopped this way records attrs["stopped_early"], with the number of cells planned and the number run, and carries no overall total, since the cells it never reached were never counted. Its search record gives the cells and years that were searched, marks the rest 'not run' and calls the harvest incomplete.
The frame fetch_plan returns has the stable RECORD_COLUMNS schema, the same shape a single fetch would return, with entry_number renumbered across the combined cells.
Writing the search up¶
A harvest is rarely the end of the work. A systematic review has to report the search itself, in enough detail that a reader can repeat it, and the reporting standard for that is PRISMA-S (Rethlefsen et al., 2021). scopus_search_report assembles the search record from what the plan and the harvest already carry.
A plan on its own can be reported before it is run, which is useful when a protocol has to be registered in advance. The plan below describes a Scopus search for the phrase the bundled corpus was drawn on. The corpus itself came from OpenAlex's exact-phrase search for 'graphene supercapacitor' in titles and abstracts, limited to journal articles, on 22 July 2026. A Scopus run of this plan would return a different set of records. The query puts the two words in quotation marks so that Scopus searches them as a phrase. Without the quotation marks, Scopus would join the two words with AND, and in OpenAlex the unquoted words match about a hundred times as many records.
graphene = sf.SearchPlan('"graphene supercapacitor"', years=range(2015, 2025),
field="TITLE-ABS-KEY", partition="year")
out(sf.scopus_search_report(graphene))
Search strategy record (PRISMA-S)
Database: Scopus, on the Elsevier Scopus Search API
Search expression: TITLE-ABS-KEY("graphene supercapacitor")
Field tag: TITLE-ABS-KEY
Years: 2015 to 2024
Partition: one cell per year, 10 cells
View: STANDARD
Page size: 200 records per request
Paging: unrecorded
Date searched: unrecorded, this plan has not been run
Software: unrecorded
Records retrieved: none, this plan has not been run
Records reported as matching: unrecorded, this plan has not been run
Completeness: unrecorded, this plan has not been run
Duplicates removed: unrecorded, this plan has not been run
Records carrying a DOI: unrecorded, this plan has not been run
Cells
1 (2015): retrieved records unrecorded
2 (2016): retrieved records unrecorded
3 (2017): retrieved records unrecorded
4 (2018): retrieved records unrecorded
5 (2019): retrieved records unrecorded
6 (2020): retrieved records unrecorded
7 (2021): retrieved records unrecorded
8 (2022): retrieved records unrecorded
9 (2023): retrieved records unrecorded
10 (2024): retrieved records unrecorded
PRISMA 2020 identification
Records identified from Scopus: unrecorded, this plan has not been run
Duplicate records removed before screening: unrecorded, this plan has not been run
PRISMA-S items this record supplies
1 Database name. Scopus, searched on the Elsevier Scopus Search API.
2 Multi-database searching. Scopus is searched on its own, not as one of several databases searched together on one platform.
8 Full search strategies. The search expression, field tag and year limit of every cell, as the plan sends them.
9 Limits and restrictions. Publication years 2015 to 2024. scopusflow applies no document type, language or subject area limit of its own.
PRISMA-S items only you can supply
3 Study registries. Any trial or study registry searched.
4 Online resources and browsing. Any web site, table of contents or other source searched or browsed by hand.
5 Citation searching. Any backward or forward citation searching.
6 Contacts. Any authors or organisations contacted for studies.
7 Other methods. Any further method used to identify records.
10 Search filters. Any published or validated search filter used, and where it came from. scopusflow applies none of its own.
11 Prior work. Any earlier review or strategy this search was adapted from.
12 Updates. Whether the search was re-run or updated, and when.
13 Dates of searches. The date of each search, which this plan has not been run to produce.
14 Peer review. Whether the strategy was peer reviewed, and by whom.
15 Total records. The number of records identified, which this plan has not been run to produce.
16 Deduplication. How duplicate records were removed, which this plan has not been run to produce.
The reporting standard is PRISMA-S (Rethlefsen et al., 2021, Systematic Reviews, 10, 39, https://doi.org/10.1186/s13643-020-01542-z), with the identification counts of the PRISMA 2020 flow diagram.
Much of the record says 'unrecorded'. Nothing has been retrieved yet, so there is nothing to state, and the record says so in words because a blank would be read as a zero. Throughout, the record states only what the objects hold. It never substitutes the current time for a retrieval that did not record one, never gives a completeness figure for a harvest whose reported total is unknown, and never counts duplicates unless a merge recorded removing them.
After a harvest, the record fills in. fetch_plan attaches the plan, the retrieval time, the version, the paging mode and the per-cell accounting, and you never set any of them yourself. Here, the bundled corpus stands in for a harvest, since Scopus records may not be redistributed. Those attributes are therefore written out below to show what each one contributes. Their values are illustrative, so the record they produce describes no search that was run. The retrieval time is set by hand, and the version is the one installed. Each cell's reported total is the number of bundled records in its year, a count from the OpenAlex search that the Scopus API never gave.
from datetime import datetime, timezone
# Illustrative values. No Scopus search was run.
records = sf.example_records()
records.attrs["plan"] = graphene
records.attrs["retrieved_at"] = datetime(2026, 7, 22, 9, 15, tzinfo=timezone.utc)
records.attrs["scopusflow_version"] = sf.__version__
records.attrs["paging"] = "cursor"
per_year = records.groupby("year").size()
records.attrs["cell_totals"] = pd.DataFrame({
"cell": range(1, len(per_year) + 1),
"date": [str(y) for y in per_year.index],
"n_records": per_year.values,
"reported_total": per_year.values,
})
report = sf.scopus_search_report(records)
out(report)
Search strategy record (PRISMA-S)
Database: Scopus, on the Elsevier Scopus Search API
Search expression: TITLE-ABS-KEY("graphene supercapacitor")
Field tag: TITLE-ABS-KEY
Years: 2015 to 2024
Partition: one cell per year, 10 cells
View: STANDARD
Page size: 200 records per request
Paging: cursor
Date searched: 2026-07-22 09:15:00 UTC
Software: scopusflow 0.4.0
Records retrieved: 138
Records reported as matching: 138
Completeness: every record the API reported as matching was retrieved
Duplicates removed: unrecorded, no de-duplication step was recorded for this set
Records carrying a DOI: 127 of 138
Cells
1 (2015): 15 retrieved, 15 reported, complete
2 (2016): 9 retrieved, 9 reported, complete
3 (2017): 10 retrieved, 10 reported, complete
4 (2018): 15 retrieved, 15 reported, complete
5 (2019): 19 retrieved, 19 reported, complete
6 (2020): 13 retrieved, 13 reported, complete
7 (2021): 13 retrieved, 13 reported, complete
8 (2022): 15 retrieved, 15 reported, complete
9 (2023): 15 retrieved, 15 reported, complete
10 (2024): 14 retrieved, 14 reported, complete
PRISMA 2020 identification
Records identified from Scopus: 138
Duplicate records removed before screening: unrecorded, no de-duplication step was recorded for this set
PRISMA-S items this record supplies
1 Database name. Scopus, searched on the Elsevier Scopus Search API.
2 Multi-database searching. Scopus was searched on its own, not as one of several databases searched together on one platform.
8 Full search strategies. The search expression, field tag and year limit of every cell, as the plan sends them.
9 Limits and restrictions. Publication years 2015 to 2024. scopusflow applies no document type, language or subject area limit of its own.
13 Dates of searches. 2026-07-22 09:15:00 UTC.
15 Total records. 138 records retrieved from Scopus, of 138 the API reported as matching.
PRISMA-S items only you can supply
3 Study registries. Any trial or study registry searched.
4 Online resources and browsing. Any web site, table of contents or other source searched or browsed by hand.
5 Citation searching. Any backward or forward citation searching.
6 Contacts. Any authors or organisations contacted for studies.
7 Other methods. Any further method used to identify records.
10 Search filters. Any published or validated search filter used, and where it came from. scopusflow applies none of its own.
11 Prior work. Any earlier review or strategy this search was adapted from.
12 Updates. Whether the search was re-run or updated, and when.
14 Peer review. Whether the strategy was peer reviewed, and by whom.
16 Deduplication. How duplicate records were removed, which this set does not record.
The reporting standard is PRISMA-S (Rethlefsen et al., 2021, Systematic Reviews, 10, 39, https://doi.org/10.1186/s13643-020-01542-z), with the identification counts of the PRISMA 2020 flow diagram.
The completeness lines show each cell against the number of records the API reported for it, so a cell that came back short stays visible where a total would have hidden it. The overall figure is given only because every cell reported one. Drop any of those attributes and the corresponding line says so instead.
The methods paragraph is the same record as prose, ready to paste into a manuscript and edit.
out(report.format(style="paragraph"))
The literature was searched in Scopus, on the Elsevier Scopus Search API, on 22 July 2026. The search expression was TITLE-ABS-KEY("graphene supercapacitor"), limited to publication years 2015 to 2024. It was partitioned into 10 cells, one per year, each retrieved through the STANDARD view in pages of 200 records under cursor paging. The search retrieved 138 records, matching the 138 the API reported, so every reported record was retrieved. Of the records retrieved, 127 carry a DOI. No de-duplication step was recorded for this set. The search was run with scopusflow 0.4.0. The PRISMA-S items this record cannot supply, among them peer review of the strategy, grey literature and any other database searched, remain yours to report.
Supplying a file writes the whole record as Markdown, including a runnable snippet that rebuilds the plan. The file can serve as supplementary material.
sf.scopus_search_report(records, file="search-record.md")
Six of the sixteen PRISMA-S items are answered here from the objects, and a seventh, de-duplication, would be too had these records been merged with scopus_combine. The rest, among them peer review of the strategy and grey literature, are listed as yours to supply, because the objects do not record them. Any other database the review searched is yours to name as well.
Watching progress¶
Per-cell progress is emitted on the scopusflow logger, which is silent by default. For a harvest that spans many years, it is worth attaching a handler, which prints a line as each cell is fetched or loaded from cache.
import logging
logging.getLogger("scopusflow").addHandler(logging.StreamHandler())
logging.getLogger("scopusflow").setLevel(logging.INFO)
records = sf.fetch_plan(plan, cache_dir="language-harvest")
Re-running and tracking change¶
Pointing a later run at a fresh directory fetches the plan again and leaves the earlier checkpoints untouched. Comparing the two DOI sets with diff_dois then shows which DOIs were added or removed in between.
later = sf.fetch_plan(plan, cache_dir="language-harvest-2")
sf.diff_dois(old=records, new=later)
Two caches are involved here, and only one of them is scopusflow's. The checkpoints in cache_dir let an interrupted harvest resume. pybliometrics keeps a response cache of its own, in the directories its configuration names, and stores each search there in a file keyed by its query string and view alone. With its default settings, pybliometrics would serve the later run from that file without contacting the API, and the comparison would set the harvest against a copy of itself, dated now and reported as complete. scopusflow therefore sends refresh=True with every search unless you pass refresh yourself, so the later run spends as much quota as the first.
Passing refresh=False opts in to pybliometrics' cache, and a number of days opts in for cache files younger than that. A cell served from the cache is dated by its cache file, reports no total and comes with a warning. The counting functions scopus_count, scopus_trend, compare_topics and scopus_intersections follow the same rule. A count they take from the cache is the number of rows an earlier harvest of the same query left there, and it is warned about in the same way. The cache key ignores keyword arguments such as subj or date, so put any filter in the query before you opt in. The pybliometrics reference for ScopusSearch describes the cache and its refresh argument.