springer_open
Overview
The springer_open module retrieves JATS XML full-text articles from the Springer Nature API and saves them into each article's temp module directory. It is one of the publisher-specific full-text modules and ideally runs after crossrefcrawler and validate_metadata, since it requires the DOI from metadata-article.json.
The Springer API imposes a daily query limit (approximately 500 for free-tier access), so this module differs from the other publisher modules in two important ways:
- Batched queries: Articles are collected into batches of
NDOIs (default 20) and fetched with a single API call using a combined(doi:"X" OR doi:"Y" OR ...)query string. The response is a combined JATS XML document containing multiple<article>elements, which the module splits back into per-DOI files. - Quota-aware fail-fast: When the API returns HTTP 429 (rate limit exceeded), the flow immediately stops queuing new articles for the rest of the run. Any articles already in flight are marked as stop-processing with a clear error message, and remaining journals are skipped.
The Input field in history.csv records the masked joint query URL for the entire batch, so the same URL appears in every article's history entry for a given batch.
Module ordering: springer_open should run after crossrefcrawler + validate_metadata (which produce metadata-article.json) and before check_license_information (which reads both the metadata and the full-text XML this module downloads).
The module contains two primary Python files:
flow.pytasks.py
flow.py
This file defines the main flow for Springer full-text harvesting using the Prefect library, and uses prefect's get_run_logger to log various stages along with the module context and previous module information. Unlike single-article modules, the flow accumulates a list of articles into a batch before dispatching a single API call, and terminates early if the Springer API quota is exhausted at any point in the run.
springer_open()
-
Required Parameters:
-
name_of_config_file(str): Name of the configuration file. Default is"springer.json" test_copy(bool): Flag to indicate if it is a test run. Default isFalse-
number_of_desired_parallel_downloads(int): Batch size — the number of DOIs bundled into each Springer API call. Default is20 -
Context for Use:
-
This function is the main entry point for the Springer full-text harvesting flow. It iterates over every article of every journal in the module context, accumulating eligible articles into a batch list. When the batch reaches
number_of_desired_parallel_downloadsentries, it is dispatched todownload_fulltexts_for_processing_listfor a single API call. Any remainder is dispatched as a final smaller batch at the end of each journal. Aquota_reachedflag propagates across journals — once the Springer API signals rate-limit exhaustion, no further batches are queued and remaining journals are skipped. -
Example Usage:
-
python springer_open('springer_lisa.json', test_copy=False, number_of_desired_parallel_downloads=20) -
Example Output:
-
INFO: Module name: springer_open INFO: Set base path to: /mnt/nas/wdm-test INFO: Module context: [{'ISSN': '2948-2143', 'position': 2, 'previous_module': 'validate_metadata', ...}] INFO: Check article directory for springer_open: /mnt/nas-tmp/.../s42467-023-00015-y DEBUG: Append to springer_open download list: /mnt/nas-tmp/.../validate_metadata_2025-01-17 ... (batch fills) DEBUG: Calling Springer Open API for 20 DOIs. DEBUG: Found 20 article nodes in XML response. ... (batch processed, temp dirs renamed)ERROR: SPRINGER API QUOTA EXHAUSTED ! Wait: 86400s WARNING: Quota reached. Stopping all further processing. ERROR: Springer API Quota exhausted for the dayWhen quota is exhausted:
tasks.py
This file contains the task definitions used in the Springer full-text harvesting flow. It handles article-eligibility checks, batch construction, the Springer API call itself, splitting the batched XML response back into per-article files, and writing the appropriate history.csv and error CSV entries.
add_article_directory_to_planned_download_list()
-
Required Parameters:
-
item(os.DirEntry): A directory entry fromos.scandirrepresenting an article folder module_name(str): Name of the current moduleprevious_module(str): Name of the previous module-
list_of_directories_to_be_downloaded(list): The batch list to append to (mutated in place) -
Context for Use:
-
Decides whether the given article should be included in the current batch. Returns
"continue"if the article should be skipped (previous module not found, marked not-to-be-processed, or already processed by springer_open),Trueif it was successfully appended, or"break"for exceptional situations. -
Example Usage:
-
python result = add_article_directory_to_planned_download_list( item, 'springer_open', 'validate_metadata', list_of_directories_to_be_downloaded ) if result == "continue": continue -
Example Output:
-
Return value:
True,"continue", or"break". - Side effect: appends to
list_of_directories_to_be_downloaded, deletes stale temp dirs from earlier failed runs.
prepare_list_of_data_points_for_springer_download()
-
Required Parameters:
-
list_of_directories_to_be_downloaded(list): List of latest-previous-module directories in the current batch module_name(str): Name of the current module-
processing_data(list): The processing data list to fill (mutated in place) -
Context for Use:
-
For each previous-module directory in the batch, creates the
temp-springer_open_...folder (viacopy_content_from_previous_module), extracts the article's DOI frommetadata-article.json, and builds a data point dict to be consumed bydownload_fulltexts_for_processing_list. If a DOI cannot be extracted, that article is immediately routed into a stop folder with an appropriate error message, and is not added toprocessing_data. -
Example Usage:
-
python processing_data = [] prepare_list_of_data_points_for_springer_download( list_of_directories_to_be_downloaded, 'springer_open', processing_data ) -
Example Output:
-
processing_datais populated with entries of the form:{ 'temp_current_module_dir': PosixPath('/mnt/.../temp-springer_open_2025-01-17'), 'latest_previous_module': PosixPath('/mnt/.../validate_metadata_2025-01-17'), 'doi': '10.1186/s42467-023-00015-y', 'download_start_time': None, 'download_end_time': None, 'download_status': None, 'api_request_url_masked': None, }
download_fulltexts_for_processing_list()
-
Required Parameters:
-
processing_data(list): Data points prepared byprepare_list_of_data_points_for_springer_download -
module_name(str): Name of the current module -
Context for Use:
-
This is the main Prefect
@taskand the workhorse of the module. It collects all DOIs fromprocessing_data, issues a single Springer JATS API call for the whole batch, splits the response by DOI, and for each article writesxml/<article_folder_name>.xml, appends ahistory.csventry, and renames the temp folder. Articles for which no XML was returned are marked as stop-processing with an error message. ReturnsFalsewhen the API quota was hit (signalling the flow to stop all further batches); returnsTrueotherwise. -
Example Usage:
-
python success = download_fulltexts_for_processing_list(processing_data, 'springer_open') if success is False: # quota exhausted, stop the flow break -
Example Output:
-
Return value:
Trueon normal completion,Falsewhen quota was hit. - Side effects: writes
xml/<article>.xmlfiles, appendshistory.csventries, renames temp folders tospringer_open_...(orstop-processing_springer_open_...for failures).
write_history_entry()
-
Required Parameters:
-
module_name(str): Name of the current module temp_current_module_dir(pathlib.Path): Path to the current temp module directorymasked_url(str): The batch API request URL with the API key replaced byXYZ-
latest_previous_module(pathlib.Path): Path to the latest previous module directory -
Context for Use:
-
Writes a
history.csventry for the current article, capturing the batched Springer API call as theInputvalue. Because the API call was batched, the same masked URL appears in every article's history entry for that batch. TheOutputisxml/<article_folder_name>.xml, and theVersionis populated from the latest commit hash of the harvesting repository. -
Example Usage:
-
python write_history_entry('springer_open', temp_dir, masked_url, prev_module) -
Example Output:
-
A row appended to
history.csvwith fields like:Date: 2025-01-17 Agent: springer_open Version: 7e3fea72d902d4fbc883039ef2ed2efa14a85102 Task: Create Input: https://api.springernature.com/openaccess/jats?api_key=XYZ&q=%28doi%3A%2210.1186%2Fs42467-023-00015-y%22+OR+...%29&p=20&s=1 Outputs: xml/s42467-023-00015-y.xml Description: Download XML from the API of the publisher Springer Nature
document_springer_error()
-
Required Parameters:
-
module_name(str): Name of the current module latest_previous_module(pathlib.Path): Path to the latest previous module directory-
error_message(str or list): Human-readable error message(s) -
Context for Use:
-
Writes the error message to a
springer_open_error.txtfile in the article directory, and also appends an entry to the central error CSV log. -
Example Usage:
-
python document_springer_error( module_name='springer_open', latest_previous_module=prev_module_path, error_message='No XML content returned from Springer API for DOI 10.1186/...' )
The lower-level helper functions in tasks.py are listed below.
get_springer_config()
-
Context for Use:
-
Reads
springer_api_base_urlandspringer_api_keyfrom the harvesting config JSON on the NAS and returns them as a(base_url, api_key)tuple.
extract_doi_from_metadata()
-
Required Parameters:
-
metadata_path(pathlib.Path): Path tometadata-article.json -
Context for Use:
-
Reads the DOI from
metadata-article.json. Tries the canonical CrossRef key first (CROSSREF_DOI_ARTICLE), then falls back toDOIanddoi. ReturnsNonewhen no DOI can be found, in which case the caller creates a stop folder for that article.
build_springer_query()
-
Required Parameters:
-
dois(list): DOIs to include in the batch -
Context for Use:
-
Builds the Springer Open API query string for a batch of DOIs. Example for 2 DOIs:
(doi:"10.xxx" OR doi:"10.yyy").
fetch_springer_jats_for_batch()
-
Required Parameters:
-
dois(list): DOIs to fetch in one API call -
Context for Use:
-
Calls the Springer Open JATS endpoint with the batched DOI query. Returns a
(response_xml, masked_url, quota_hit)tuple.quota_hitisTruewhen the API responds with HTTP 429; in that case the flow should stop further batches. The URL is masked for safe logging and history recording.
split_jats_response_by_doi()
-
Required Parameters:
-
response_xml(str): The full XML response from the batch API call -
dois(list): The DOIs that were requested (used for fallback matching) -
Context for Use:
-
Splits the batched JATS response into per-DOI XML strings. First tries to find each article's
<article-id pub-id-type="doi">element; falls back to substring-matching the requested DOIs against the article XML for articles that lack a proper DOI element. Returns a dict mapping DOI → XML string.
write_xml_to_article()
-
Required Parameters:
-
temp_current_module_dir(pathlib.Path): Path to the current temp module directory xml_content(str): The XML content to write-
filename(str): The file name for the XML file -
Context for Use:
-
Creates an
xml/subdirectory in the temp module directory if it does not already exist, and writes the given XML content to<temp_current_module_dir>/xml/<filename>.