fulltext-article-downloader 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. fulltext_article_downloader-0.2.0/LICENSE +9 -0
  2. fulltext_article_downloader-0.2.0/PKG-INFO +294 -0
  3. fulltext_article_downloader-0.2.0/README.md +260 -0
  4. fulltext_article_downloader-0.2.0/fulltext_article_downloader/__init__.py +29 -0
  5. fulltext_article_downloader-0.2.0/fulltext_article_downloader/cli.py +66 -0
  6. fulltext_article_downloader-0.2.0/fulltext_article_downloader/configure.py +52 -0
  7. fulltext_article_downloader-0.2.0/fulltext_article_downloader/downloader.py +385 -0
  8. fulltext_article_downloader-0.2.0/fulltext_article_downloader/identifiers.py +44 -0
  9. fulltext_article_downloader-0.2.0/fulltext_article_downloader/mcp_server.py +69 -0
  10. fulltext_article_downloader-0.2.0/fulltext_article_downloader/supplements.py +208 -0
  11. fulltext_article_downloader-0.2.0/fulltext_article_downloader/tools.py +1055 -0
  12. fulltext_article_downloader-0.2.0/fulltext_article_downloader/verify.py +78 -0
  13. fulltext_article_downloader-0.2.0/fulltext_article_downloader.egg-info/PKG-INFO +294 -0
  14. fulltext_article_downloader-0.2.0/fulltext_article_downloader.egg-info/SOURCES.txt +23 -0
  15. fulltext_article_downloader-0.2.0/fulltext_article_downloader.egg-info/dependency_links.txt +1 -0
  16. fulltext_article_downloader-0.2.0/fulltext_article_downloader.egg-info/entry_points.txt +4 -0
  17. fulltext_article_downloader-0.2.0/fulltext_article_downloader.egg-info/requires.txt +29 -0
  18. fulltext_article_downloader-0.2.0/fulltext_article_downloader.egg-info/top_level.txt +1 -0
  19. fulltext_article_downloader-0.2.0/pyproject.toml +44 -0
  20. fulltext_article_downloader-0.2.0/setup.cfg +4 -0
  21. fulltext_article_downloader-0.2.0/setup.py +4 -0
  22. fulltext_article_downloader-0.2.0/tests/test_cli_mcp.py +63 -0
  23. fulltext_article_downloader-0.2.0/tests/test_downloaders.py +708 -0
  24. fulltext_article_downloader-0.2.0/tests/test_engine_v2.py +510 -0
  25. fulltext_article_downloader-0.2.0/tests/test_supplements.py +73 -0
@@ -0,0 +1,9 @@
1
+ Copyright 2025 Anubhav Jain
2
+
3
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
+
5
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
7
+ 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
8
+
9
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,294 @@
1
+ Metadata-Version: 2.4
2
+ Name: fulltext-article-downloader
3
+ Version: 0.2.0
4
+ Summary: Download the full text of research articles by DOI, arXiv, PMC or OpenReview id: publisher TDM APIs, open-access indexes and repositories, with verification of what was fetched
5
+ Author: Anubhav Jain, Xu Huang
6
+ License: BSD-3-Clause
7
+ Project-URL: Homepage, https://github.com/computron/fulltext-article-downloader
8
+ Requires-Python: >=3.10
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: requests>=2.20.0
12
+ Requires-Dist: tqdm>=4.50.0
13
+ Requires-Dist: beautifulsoup4>=4.6.0
14
+ Requires-Dist: pypdf>=4.0
15
+ Provides-Extra: mcp
16
+ Requires-Dist: fastmcp>=2.0; extra == "mcp"
17
+ Provides-Extra: tls
18
+ Requires-Dist: curl-cffi>=0.7; extra == "tls"
19
+ Provides-Extra: springer
20
+ Requires-Dist: sprynger>=0.3.0; extra == "springer"
21
+ Provides-Extra: preprints
22
+ Requires-Dist: paperscraper>=0.1.0; extra == "preprints"
23
+ Provides-Extra: aps
24
+ Requires-Dist: browser-cookie3>=0.15.0; extra == "aps"
25
+ Provides-Extra: all
26
+ Requires-Dist: fastmcp>=2.0; extra == "all"
27
+ Requires-Dist: curl-cffi>=0.7; extra == "all"
28
+ Requires-Dist: sprynger>=0.3.0; extra == "all"
29
+ Requires-Dist: paperscraper>=0.1.0; extra == "all"
30
+ Requires-Dist: browser-cookie3>=0.15.0; extra == "all"
31
+ Provides-Extra: dev
32
+ Requires-Dist: pytest>=8.0; extra == "dev"
33
+ Dynamic: license-file
34
+
35
+ # fulltext-article-downloader
36
+ <!-- mcp-name: io.github.computron/fulltext-article-downloader -->
37
+
38
+ **fulltext-article-downloader** is a Python package for **programmatically downloading the full text of research articles** from a DOI, arXiv id, PubMed Central id or OpenReview id. It chains together publisher APIs, open-access indexes and repositories in a fallback sequence, checks that what came back is really the requested article, and can be used from Python, from the command line, or by an AI agent through an MCP server or a Claude Code skill.
39
+
40
+ **Video tutorial**: https://youtu.be/fTtc4QWMYzE
41
+
42
+ ---
43
+
44
+ ## Features
45
+
46
+ * **Multiple retrieval methods** – Elsevier, Wiley and Springer Nature APIs, CrossRef TDM links, Unpaywall, Europe PMC, OSTI (accepted manuscripts of DOE-funded articles), Semantic Scholar's open-access index, arXiv, ChemRxiv, bioRxiv/medRxiv, Zenodo, MDPI's CDN, and direct scraping for publishers that lack easy APIs (PLOS, eLife, Cambridge, APS).
47
+ * **Automatic fallback logic** – The package selects the best method based on the DOI's publisher; if one fails, the next is tried automatically.
48
+ * **Verification** – Every PDF is checked against the article's title, and supporting-information files and abstract-only records are rejected, so a returned file is the paper you asked for.
49
+ * **Honest results** – Each download reports which route produced the file and carries a note when it is a preprint or accepted manuscript rather than the publisher's version of record.
50
+ * **Configurable tool order** – Per-publisher method sequences are configurable; defaults cover most major publishers and preprint servers.
51
+ * **Batch downloads** – Concurrent downloads with publisher rate limits enforced, a `tqdm` progress bar, and file logs that record which tool succeeded or why an identifier failed.
52
+ * **Easy API-key management** – Store credentials via environment variables or the interactive `fulltext-config` script.
53
+ * **Four entry points, one engine** – Python API, `fulltext-download` CLI, `fulltext-mcp` server for any MCP client, and a Claude Code plugin with a ready-made skill.
54
+
55
+ ---
56
+
57
+ ## 1. Installation
58
+
59
+ ```bash
60
+ pip install fulltext-article-downloader
61
+ ```
62
+
63
+ Until the first PyPI release, install from GitHub instead: `pip install git+https://github.com/computron/fulltext-article-downloader.git`.
64
+
65
+ Optional extras enable additional routes and the MCP server:
66
+
67
+ | Extra | Adds |
68
+ | --- | --- |
69
+ | `mcp` | the `fulltext-mcp` server (fastmcp) |
70
+ | `tls` | a Chrome TLS fingerprint fallback for hosts that reject plain HTTPS clients (curl-cffi) |
71
+ | `springer` | the Springer Nature open-access XML route (sprynger) |
72
+ | `preprints` | bioRxiv/medRxiv downloads through paperscraper |
73
+ | `aps` | the APS route that reuses your browser's login cookies (browser-cookie3) |
74
+ | `all` | everything above |
75
+
76
+ ```bash
77
+ pip install "fulltext-article-downloader[mcp,tls]"
78
+ ```
79
+
80
+ For development, clone the repository and run `pip install -e ".[dev,all]"`. Make sure to **configure** your installation afterwards (see next section).
81
+
82
+ ## 2. Configuration (API keys & email)
83
+
84
+ All credentials are optional; each one unlocks a route. Without keys, and off campus, expect open-access papers, preprints and DOE-funded manuscripts to work and most paywalled articles to fail.
85
+
86
+ | Service | Environment variable | Where to get the key |
87
+ | --- | --- | --- |
88
+ | Unpaywall and Crossref contact email (your own address) | `UNPAYWALL_EMAIL` | (enter your email address) |
89
+ | Elsevier API | `ELSEVIER_API_KEY` | https://dev.elsevier.com |
90
+ | Wiley TDM API | `WILEY_API_KEY` | https://onlinelibrary.wiley.com/library-info/resources/text-and-datamining |
91
+ | Springer Open Access API | `SPRINGER_API_KEY` | https://dev.springernature.com |
92
+ | Semantic Scholar (optional; raises the rate limit and enables the title search that finds arXiv copies of papers whose DOI record has no PDF) | `SEMANTIC_SCHOLAR_API_KEY` | https://www.semanticscholar.org/product/api (free, approved by email in a few days) |
93
+
94
+ `UNPAYWALL_EMAIL` is sent only to Unpaywall and Crossref, which ask API users for a contact address; Crossref serves requests that carry one from its faster "polite" pool. Keys and the email stay on your machine.
95
+
96
+ Set these environment variables **or** run the interactive helper:
97
+
98
+ ```bash
99
+ fulltext-config
100
+ ```
101
+
102
+ The script stores keys in `~/.fulltext_keys`, which are loaded automatically on import. If a required key is missing, the corresponding tool is skipped and the downloader falls back to other methods. Publisher keys return paywalled content only when the key or the network is entitled; the package detects truncated or abstract-only responses and moves on.
103
+
104
+ ---
105
+
106
+ ## 3. Usage
107
+
108
+ ### Identifiers
109
+
110
+ Any of these forms is accepted everywhere an identifier is expected:
111
+
112
+ * DOI: `10.1021/jacs.3c13302`, `https://doi.org/10.1021/jacs.3c13302`, `doi:10.1021/jacs.3c13302`
113
+ * arXiv: `2310.19377`, `arXiv:2310.19377`, `https://arxiv.org/abs/2310.19377`, `cond-mat/9712061`, `10.48550/arXiv.2310.19377`
114
+ * PubMed Central: `PMC6561843`
115
+ * OpenReview: `fNyXCCZ0g6`
116
+
117
+ ### Command-line interface (CLI)
118
+
119
+ ```text
120
+ fulltext-download <ID> [<ID> ...] [-o DIR] [--tools a,b,c] [--workers N] [--no-check] [--log-file FILE]
121
+ ```
122
+
123
+ ```bash
124
+ fulltext-download 10.1371/journal.pone.0171501 -o papers
125
+ fulltext-download 10.1021/jacs.3c13302 arXiv:1710.10324 PMC6561843 -o papers --workers 4
126
+ ```
127
+
128
+ The command prints one JSON object per identifier and exits 0 only when every download succeeded:
129
+
130
+ ```json
131
+ [
132
+ {
133
+ "identifier": "10.1021/jacs.3c13302",
134
+ "success": true,
135
+ "path": "papers/10.1021_jacs.3c13302.pdf",
136
+ "source": "osti",
137
+ "note": "OSTI accepted manuscript, not the publisher's version of record",
138
+ "error": null,
139
+ "attempts": [],
140
+ "supplements": []
141
+ }
142
+ ]
143
+ ```
144
+
145
+ The original form `fulltext-download <DOI> <OUTPUT_DIR> [<FILENAME>]` still works.
146
+
147
+ ### Python API
148
+
149
+ `fetch` returns the same structure the CLI prints; `fetch_many` downloads a list concurrently:
150
+
151
+ ```python
152
+ from fulltext_article_downloader import fetch, fetch_many
153
+
154
+ r = fetch("10.1371/journal.pone.0171501", "papers")
155
+ if r["success"]:
156
+ print(r["path"], r["source"], r["note"])
157
+ else:
158
+ print(r["error"]) # every route tried, with its reason
159
+
160
+ rs = fetch_many(["10.1002/advs.201900808", "10.48550/arXiv.2207.03928"], "papers", workers=4)
161
+ ```
162
+
163
+ The earlier functions are unchanged: `download_article(doi, output_dir, ...)` returns the path or raises, and `bulk_download_articles(dois, output_dir, log_file=..., sleep=..., workers=...)` returns a dict of paths or `"ERROR: ..."` strings with a progress bar.
164
+
165
+ Options shared by all of them: `output_filename` (single download), `tools` (a list of route names that overrides the publisher default), `log_file` (append a download log), and for `fetch` also `check=False` to skip verification and `skip_existing=False` to re-download a file that is already present.
166
+
167
+ ### Supplementary files
168
+
169
+ `fetch(..., supplements=True)`, `fetch_many(..., supplements=True)`, `fulltext-download --supplements` and the MCP tools' `supplements=true` also fetch the article's supplementary files (supporting information, data tables, videos). They are separate files from separate places, so they are saved next to the article as `<name>_si1.pdf`, `<name>_si2.xlsx`, ... and listed in the result's `supplements`. Sources: the ChemRxiv and Elsevier APIs, Europe PMC's supplement bundle for PMC articles, and otherwise the article's landing page (Springer Nature, Wiley, bioRxiv, ACS, RSC, PLOS and others link them there; most publishers serve supplements without a subscription). Off by default because it costs one more request per article; a missing supplement never fails the download.
170
+
171
+ ### MCP server (for agents)
172
+
173
+ `fulltext-mcp` exposes two tools, `get_paper(identifier, output_dir="", tools=None, supplements=False)` and `get_papers(identifiers, output_dir="", max_workers=4, supplements=False)`, returning the structure shown above. It needs the `mcp` extra and reads the same keys as the CLI. `FULLTEXT_OUTPUT_DIR` sets where files go when a call gives no output directory (default `./papers`).
174
+
175
+ Claude Code:
176
+
177
+ ```bash
178
+ claude mcp add fulltext-article-downloader -- uvx --from "fulltext-article-downloader[mcp]" fulltext-mcp
179
+ ```
180
+
181
+ Any other MCP client, in its server configuration:
182
+
183
+ ```json
184
+ {
185
+ "mcpServers": {
186
+ "fulltext-article-downloader": {
187
+ "command": "uvx",
188
+ "args": ["--from", "fulltext-article-downloader[mcp]", "fulltext-mcp"],
189
+ "env": { "UNPAYWALL_EMAIL": "you@example.org", "FULLTEXT_OUTPUT_DIR": "/abs/path/papers" }
190
+ }
191
+ }
192
+ }
193
+ ```
194
+
195
+ `uvx` fetches the package from PyPI into an isolated environment on first use, so nothing needs to be installed beforehand. The server is also listed in the official MCP registry as `io.github.computron/fulltext-article-downloader`.
196
+
197
+ ### Claude Code plugin and skill
198
+
199
+ This repository is also a Claude Code plugin. It installs a skill that teaches Claude when and how to use `fulltext-download`, plus the MCP server above:
200
+
201
+ ```text
202
+ /plugin marketplace add computron/fulltext-article-downloader
203
+ /plugin install fulltext-article-downloader@fulltext-article-downloader
204
+ ```
205
+
206
+ The skill alone (no MCP) is enough inside Claude Code: it runs the CLI and reads the JSON. The MCP server is for clients that cannot run shell commands, and for other agent frameworks.
207
+
208
+ ---
209
+
210
+ ## 4. Failures and tools
211
+
212
+ ### Failure examples
213
+
214
+ Many articles are not open-access, and publishers explicitly restrict or discourage text and data mining. This example is expected to FAIL:
215
+
216
+ ```bash
217
+ fulltext-download 10.1109/GROUP4.2007.4347715 -o papers
218
+ ```
219
+
220
+ The `error` field lists every route tried and why it failed. A failure almost always means the article is paywalled with no open-access copy, or that a host blocked automated access.
221
+
222
+ If you see an error like ``Failed to load APS cookies``, please make sure you are running Python using an application that has full disk access.
223
+
224
+ ### Verification
225
+
226
+ A file that starts with `%PDF-` is not proof of anything: open-access indexes occasionally map a DOI to an unrelated document, and a supporting-information file can carry the article's title. After every route the package extracts the first two pages and checks that the Crossref title is there, rejects files that open with a Supporting Information heading, and rejects Elsevier XML records that contain no body text. A rejected file is deleted and the next route is tried. `--no-check` / `check=False` turns this off.
227
+
228
+ ### Methods and fallback logic
229
+
230
+ The tool is composed of multiple sub-tools intended to support various publishers. The tool order depends on the publisher.
231
+
232
+ | Publisher / source | Default tool order |
233
+ | ------------------ | ------------------ |
234
+ | Elsevier | `unpaywall` → `elsevier` (PDF when entitled, else XML) → `europepmc` → `osti` → `semantic` |
235
+ | Springer / Nature | `springerpdf` (nature.com, SpringerLink) → `unpaywall` → `europepmc` → `springeropen` (XML) → `osti` → `semantic` |
236
+ | Wiley | `wiley` → `unpaywall` → `europepmc` → `osti` → `semantic` |
237
+ | APS | `aps` → `unpaywall` → `crossref_tdm` → `europepmc` → `osti` → `semantic` |
238
+ | ACS, RSC, AIP | `unpaywall` → `europepmc` → `crossref_tdm` → `osti` → `semantic` |
239
+ | PLOS | `plos` → `unpaywall` |
240
+ | eLife | `elife` → `unpaywall` |
241
+ | Cambridge | `cambridge` → `unpaywall` → `europepmc` → `osti` → `semantic` |
242
+ | arXiv | `arxiv` → `unpaywall` |
243
+ | ChemRxiv | `chemrxiv` → `paperscraper` → `unpaywall` |
244
+ | bioRxiv, medRxiv | `biorxiv` → `unpaywall` → `paperscraper` |
245
+ | MDPI | `mdpi` → `unpaywall` → `europepmc` → `semantic` |
246
+ | Zenodo | `zenodo` |
247
+ | Others | `unpaywall` → `europepmc` → `crossref_tdm` → `osti` → `semantic` → `elsevier` |
248
+
249
+ arXiv, PMC and OpenReview ids go straight to `arxiv`, `pmc` and `openreview`. `pmc` fetches Europe PMC's PDF render and, when that endpoint refuses (it throttles hosts that ask for many articles in a row), the full-text JATS XML from Europe PMC's REST service or from NCBI's efetch, which also serves author manuscripts (`NCBI_API_KEY` is optional and raises NCBI's rate limit).
250
+
251
+ What the less obvious tools do:
252
+
253
+ * `elsevier` asks for the PDF first and keeps it only when the API key is entitled to the full PDF; Elsevier otherwise answers with HTTP 200 and a PDF containing only the article's first page, so the tool discards that and takes the full-text XML instead, writing a markdown rendering next to it. Abstract-only XML is rejected. The returned path always carries the extension of the format actually written.
254
+ * `crossref_tdm` tries every full-text link registered with Crossref, including the `unspecified` content-type links that APS, ACS and RSC use; they return the PDF on an entitled network.
255
+ * `europepmc` downloads PMC-hosted open-access articles and the repository copies (usually author manuscripts) listed in Europe PMC's record for the DOI. When the record says the article's full text is in PMC (author manuscripts deposited under funder mandates), it takes the PMC copy: the PDF render, or the JATS XML when that endpoint refuses.
256
+ * `osti` queries the OSTI API for the DOI and downloads the accepted manuscript that DOE-funded articles receive on osti.gov about a year after publication. It needs no credentials; records still under embargo have no full text and the tool moves on.
257
+ * `semantic` downloads the open-access PDF Semantic Scholar has indexed for the DOI, mostly arXiv and institutional-repository copies of subscription articles.
258
+ * `unpaywall` and `semantic` also accept repository landing pages: when an index lists the page rather than the file (HAL, DSpace, Columbia Academic Commons), the tool reads the `citation_pdf_url` tag the page carries for Google Scholar and downloads that.
259
+ * `chemrxiv` goes through the Cambridge Open Engage API, which works from hosts that chemrxiv.org itself blocks.
260
+ * `biorxiv` asks the bioRxiv API which server (bioRxiv or medRxiv) holds the DOI and which version is current, then fetches that PDF. Requests are paced (the site answers 429 with a 100 s Retry-After after a burst) and the transient 503s it returns are retried; when the API itself is throttling, the unversioned URL, which redirects to the current version, is tried on both servers.
261
+ * `mdpi` builds the article's path on MDPI's CDN (`mdpi-res.com`) from the Crossref record; www.mdpi.com itself refuses requests from cloud-provider address ranges.
262
+ * `zenodo` downloads the PDF attached to a Zenodo record (10.5281 DOIs); a concept DOI resolves to the latest version.
263
+ * `wiley` is also used for society journals hosted on Wiley Online Library (AGU and others): Crossref lists their full-text links on wiley.com, and the TDM API serves them. Likewise `elsevier` is added for journals whose Crossref links point at Elsevier, and it closes the default list because Elsevier's API also serves society journals it distributes (ASH's Blood) under their own publisher name; a non-Elsevier DOI costs one quick 404.
264
+ * `semantic` also downloads the arXiv version named in a record's `externalIds` when the record lists no PDF, and with `SEMANTIC_SCHOLAR_API_KEY` searches by title for a second record of the same paper (the search endpoint answers 429 without a key). Requests are spaced one second apart, Semantic Scholar's limit.
265
+
266
+ Downloads send a browser User-Agent, retry with a plain one for repositories that serve PDFs only to non-browser clients, and, with the `tls` extra, once more with a Chrome TLS fingerprint. Wiley requests are paced to 30 per 10 minutes (the published limit is 60, but the API answers HTTP 500 from about 35 on), Crossref requests to its polite-pool limit, and transient 429/5xx responses are retried once.
267
+
268
+ Routes that return preprints or accepted manuscripts (`arxiv`, `chemrxiv`, `biorxiv`, `osti`, `semantic`, repository copies from `unpaywall` and `europepmc`) set `note` in the result. See ``PUBLISHER_TOOL_MAP`` in ``downloader.py``.
269
+
270
+ > **Tip** – Scraping-based methods (`springerpdf`, `elife`, `cambridge`, etc.) can break if sites change layout or due to access limits; favour official APIs and Unpaywall for large-scale downloads.
271
+
272
+ ### Customising the tool sequence
273
+
274
+ ```python
275
+ from fulltext_article_downloader import fetch
276
+ fetch("10.1017/S0885715624000484", "papers", tools=["unpaywall", "cambridge"]) # override default order
277
+ ```
278
+
279
+ ### Override at runtime:
280
+
281
+ ```python
282
+ from fulltext_article_downloader import PUBLISHER_TOOL_MAP
283
+ PUBLISHER_TOOL_MAP["Elsevier BV"] = ["elsevier", "unpaywall"]
284
+ ```
285
+
286
+ ---
287
+
288
+ ## 5. License and Disclaimer.
289
+
290
+ BSD 3-Clause. See the `LICENSE` file.
291
+
292
+ Use this tool **only** for content you are legally entitled to access. Respect publisher terms and copyright laws. It does not use Sci-Hub or similar sites and does not try to get around access controls. The authors are **not** responsible for misuse.
293
+
294
+ Speed-coded by computron on vibes (ChatGPT 4.0) and caffeine; extended by Xu Huang with Claude.
@@ -0,0 +1,260 @@
1
+ # fulltext-article-downloader
2
+ <!-- mcp-name: io.github.computron/fulltext-article-downloader -->
3
+
4
+ **fulltext-article-downloader** is a Python package for **programmatically downloading the full text of research articles** from a DOI, arXiv id, PubMed Central id or OpenReview id. It chains together publisher APIs, open-access indexes and repositories in a fallback sequence, checks that what came back is really the requested article, and can be used from Python, from the command line, or by an AI agent through an MCP server or a Claude Code skill.
5
+
6
+ **Video tutorial**: https://youtu.be/fTtc4QWMYzE
7
+
8
+ ---
9
+
10
+ ## Features
11
+
12
+ * **Multiple retrieval methods** – Elsevier, Wiley and Springer Nature APIs, CrossRef TDM links, Unpaywall, Europe PMC, OSTI (accepted manuscripts of DOE-funded articles), Semantic Scholar's open-access index, arXiv, ChemRxiv, bioRxiv/medRxiv, Zenodo, MDPI's CDN, and direct scraping for publishers that lack easy APIs (PLOS, eLife, Cambridge, APS).
13
+ * **Automatic fallback logic** – The package selects the best method based on the DOI's publisher; if one fails, the next is tried automatically.
14
+ * **Verification** – Every PDF is checked against the article's title, and supporting-information files and abstract-only records are rejected, so a returned file is the paper you asked for.
15
+ * **Honest results** – Each download reports which route produced the file and carries a note when it is a preprint or accepted manuscript rather than the publisher's version of record.
16
+ * **Configurable tool order** – Per-publisher method sequences are configurable; defaults cover most major publishers and preprint servers.
17
+ * **Batch downloads** – Concurrent downloads with publisher rate limits enforced, a `tqdm` progress bar, and file logs that record which tool succeeded or why an identifier failed.
18
+ * **Easy API-key management** – Store credentials via environment variables or the interactive `fulltext-config` script.
19
+ * **Four entry points, one engine** – Python API, `fulltext-download` CLI, `fulltext-mcp` server for any MCP client, and a Claude Code plugin with a ready-made skill.
20
+
21
+ ---
22
+
23
+ ## 1. Installation
24
+
25
+ ```bash
26
+ pip install fulltext-article-downloader
27
+ ```
28
+
29
+ Until the first PyPI release, install from GitHub instead: `pip install git+https://github.com/computron/fulltext-article-downloader.git`.
30
+
31
+ Optional extras enable additional routes and the MCP server:
32
+
33
+ | Extra | Adds |
34
+ | --- | --- |
35
+ | `mcp` | the `fulltext-mcp` server (fastmcp) |
36
+ | `tls` | a Chrome TLS fingerprint fallback for hosts that reject plain HTTPS clients (curl-cffi) |
37
+ | `springer` | the Springer Nature open-access XML route (sprynger) |
38
+ | `preprints` | bioRxiv/medRxiv downloads through paperscraper |
39
+ | `aps` | the APS route that reuses your browser's login cookies (browser-cookie3) |
40
+ | `all` | everything above |
41
+
42
+ ```bash
43
+ pip install "fulltext-article-downloader[mcp,tls]"
44
+ ```
45
+
46
+ For development, clone the repository and run `pip install -e ".[dev,all]"`. Make sure to **configure** your installation afterwards (see next section).
47
+
48
+ ## 2. Configuration (API keys & email)
49
+
50
+ All credentials are optional; each one unlocks a route. Without keys, and off campus, expect open-access papers, preprints and DOE-funded manuscripts to work and most paywalled articles to fail.
51
+
52
+ | Service | Environment variable | Where to get the key |
53
+ | --- | --- | --- |
54
+ | Unpaywall and Crossref contact email (your own address) | `UNPAYWALL_EMAIL` | (enter your email address) |
55
+ | Elsevier API | `ELSEVIER_API_KEY` | https://dev.elsevier.com |
56
+ | Wiley TDM API | `WILEY_API_KEY` | https://onlinelibrary.wiley.com/library-info/resources/text-and-datamining |
57
+ | Springer Open Access API | `SPRINGER_API_KEY` | https://dev.springernature.com |
58
+ | Semantic Scholar (optional; raises the rate limit and enables the title search that finds arXiv copies of papers whose DOI record has no PDF) | `SEMANTIC_SCHOLAR_API_KEY` | https://www.semanticscholar.org/product/api (free, approved by email in a few days) |
59
+
60
+ `UNPAYWALL_EMAIL` is sent only to Unpaywall and Crossref, which ask API users for a contact address; Crossref serves requests that carry one from its faster "polite" pool. Keys and the email stay on your machine.
61
+
62
+ Set these environment variables **or** run the interactive helper:
63
+
64
+ ```bash
65
+ fulltext-config
66
+ ```
67
+
68
+ The script stores keys in `~/.fulltext_keys`, which are loaded automatically on import. If a required key is missing, the corresponding tool is skipped and the downloader falls back to other methods. Publisher keys return paywalled content only when the key or the network is entitled; the package detects truncated or abstract-only responses and moves on.
69
+
70
+ ---
71
+
72
+ ## 3. Usage
73
+
74
+ ### Identifiers
75
+
76
+ Any of these forms is accepted everywhere an identifier is expected:
77
+
78
+ * DOI: `10.1021/jacs.3c13302`, `https://doi.org/10.1021/jacs.3c13302`, `doi:10.1021/jacs.3c13302`
79
+ * arXiv: `2310.19377`, `arXiv:2310.19377`, `https://arxiv.org/abs/2310.19377`, `cond-mat/9712061`, `10.48550/arXiv.2310.19377`
80
+ * PubMed Central: `PMC6561843`
81
+ * OpenReview: `fNyXCCZ0g6`
82
+
83
+ ### Command-line interface (CLI)
84
+
85
+ ```text
86
+ fulltext-download <ID> [<ID> ...] [-o DIR] [--tools a,b,c] [--workers N] [--no-check] [--log-file FILE]
87
+ ```
88
+
89
+ ```bash
90
+ fulltext-download 10.1371/journal.pone.0171501 -o papers
91
+ fulltext-download 10.1021/jacs.3c13302 arXiv:1710.10324 PMC6561843 -o papers --workers 4
92
+ ```
93
+
94
+ The command prints one JSON object per identifier and exits 0 only when every download succeeded:
95
+
96
+ ```json
97
+ [
98
+ {
99
+ "identifier": "10.1021/jacs.3c13302",
100
+ "success": true,
101
+ "path": "papers/10.1021_jacs.3c13302.pdf",
102
+ "source": "osti",
103
+ "note": "OSTI accepted manuscript, not the publisher's version of record",
104
+ "error": null,
105
+ "attempts": [],
106
+ "supplements": []
107
+ }
108
+ ]
109
+ ```
110
+
111
+ The original form `fulltext-download <DOI> <OUTPUT_DIR> [<FILENAME>]` still works.
112
+
113
+ ### Python API
114
+
115
+ `fetch` returns the same structure the CLI prints; `fetch_many` downloads a list concurrently:
116
+
117
+ ```python
118
+ from fulltext_article_downloader import fetch, fetch_many
119
+
120
+ r = fetch("10.1371/journal.pone.0171501", "papers")
121
+ if r["success"]:
122
+ print(r["path"], r["source"], r["note"])
123
+ else:
124
+ print(r["error"]) # every route tried, with its reason
125
+
126
+ rs = fetch_many(["10.1002/advs.201900808", "10.48550/arXiv.2207.03928"], "papers", workers=4)
127
+ ```
128
+
129
+ The earlier functions are unchanged: `download_article(doi, output_dir, ...)` returns the path or raises, and `bulk_download_articles(dois, output_dir, log_file=..., sleep=..., workers=...)` returns a dict of paths or `"ERROR: ..."` strings with a progress bar.
130
+
131
+ Options shared by all of them: `output_filename` (single download), `tools` (a list of route names that overrides the publisher default), `log_file` (append a download log), and for `fetch` also `check=False` to skip verification and `skip_existing=False` to re-download a file that is already present.
132
+
133
+ ### Supplementary files
134
+
135
+ `fetch(..., supplements=True)`, `fetch_many(..., supplements=True)`, `fulltext-download --supplements` and the MCP tools' `supplements=true` also fetch the article's supplementary files (supporting information, data tables, videos). They are separate files from separate places, so they are saved next to the article as `<name>_si1.pdf`, `<name>_si2.xlsx`, ... and listed in the result's `supplements`. Sources: the ChemRxiv and Elsevier APIs, Europe PMC's supplement bundle for PMC articles, and otherwise the article's landing page (Springer Nature, Wiley, bioRxiv, ACS, RSC, PLOS and others link them there; most publishers serve supplements without a subscription). Off by default because it costs one more request per article; a missing supplement never fails the download.
136
+
137
+ ### MCP server (for agents)
138
+
139
+ `fulltext-mcp` exposes two tools, `get_paper(identifier, output_dir="", tools=None, supplements=False)` and `get_papers(identifiers, output_dir="", max_workers=4, supplements=False)`, returning the structure shown above. It needs the `mcp` extra and reads the same keys as the CLI. `FULLTEXT_OUTPUT_DIR` sets where files go when a call gives no output directory (default `./papers`).
140
+
141
+ Claude Code:
142
+
143
+ ```bash
144
+ claude mcp add fulltext-article-downloader -- uvx --from "fulltext-article-downloader[mcp]" fulltext-mcp
145
+ ```
146
+
147
+ Any other MCP client, in its server configuration:
148
+
149
+ ```json
150
+ {
151
+ "mcpServers": {
152
+ "fulltext-article-downloader": {
153
+ "command": "uvx",
154
+ "args": ["--from", "fulltext-article-downloader[mcp]", "fulltext-mcp"],
155
+ "env": { "UNPAYWALL_EMAIL": "you@example.org", "FULLTEXT_OUTPUT_DIR": "/abs/path/papers" }
156
+ }
157
+ }
158
+ }
159
+ ```
160
+
161
+ `uvx` fetches the package from PyPI into an isolated environment on first use, so nothing needs to be installed beforehand. The server is also listed in the official MCP registry as `io.github.computron/fulltext-article-downloader`.
162
+
163
+ ### Claude Code plugin and skill
164
+
165
+ This repository is also a Claude Code plugin. It installs a skill that teaches Claude when and how to use `fulltext-download`, plus the MCP server above:
166
+
167
+ ```text
168
+ /plugin marketplace add computron/fulltext-article-downloader
169
+ /plugin install fulltext-article-downloader@fulltext-article-downloader
170
+ ```
171
+
172
+ The skill alone (no MCP) is enough inside Claude Code: it runs the CLI and reads the JSON. The MCP server is for clients that cannot run shell commands, and for other agent frameworks.
173
+
174
+ ---
175
+
176
+ ## 4. Failures and tools
177
+
178
+ ### Failure examples
179
+
180
+ Many articles are not open-access, and publishers explicitly restrict or discourage text and data mining. This example is expected to FAIL:
181
+
182
+ ```bash
183
+ fulltext-download 10.1109/GROUP4.2007.4347715 -o papers
184
+ ```
185
+
186
+ The `error` field lists every route tried and why it failed. A failure almost always means the article is paywalled with no open-access copy, or that a host blocked automated access.
187
+
188
+ If you see an error like ``Failed to load APS cookies``, please make sure you are running Python using an application that has full disk access.
189
+
190
+ ### Verification
191
+
192
+ A file that starts with `%PDF-` is not proof of anything: open-access indexes occasionally map a DOI to an unrelated document, and a supporting-information file can carry the article's title. After every route the package extracts the first two pages and checks that the Crossref title is there, rejects files that open with a Supporting Information heading, and rejects Elsevier XML records that contain no body text. A rejected file is deleted and the next route is tried. `--no-check` / `check=False` turns this off.
193
+
194
+ ### Methods and fallback logic
195
+
196
+ The tool is composed of multiple sub-tools intended to support various publishers. The tool order depends on the publisher.
197
+
198
+ | Publisher / source | Default tool order |
199
+ | ------------------ | ------------------ |
200
+ | Elsevier | `unpaywall` → `elsevier` (PDF when entitled, else XML) → `europepmc` → `osti` → `semantic` |
201
+ | Springer / Nature | `springerpdf` (nature.com, SpringerLink) → `unpaywall` → `europepmc` → `springeropen` (XML) → `osti` → `semantic` |
202
+ | Wiley | `wiley` → `unpaywall` → `europepmc` → `osti` → `semantic` |
203
+ | APS | `aps` → `unpaywall` → `crossref_tdm` → `europepmc` → `osti` → `semantic` |
204
+ | ACS, RSC, AIP | `unpaywall` → `europepmc` → `crossref_tdm` → `osti` → `semantic` |
205
+ | PLOS | `plos` → `unpaywall` |
206
+ | eLife | `elife` → `unpaywall` |
207
+ | Cambridge | `cambridge` → `unpaywall` → `europepmc` → `osti` → `semantic` |
208
+ | arXiv | `arxiv` → `unpaywall` |
209
+ | ChemRxiv | `chemrxiv` → `paperscraper` → `unpaywall` |
210
+ | bioRxiv, medRxiv | `biorxiv` → `unpaywall` → `paperscraper` |
211
+ | MDPI | `mdpi` → `unpaywall` → `europepmc` → `semantic` |
212
+ | Zenodo | `zenodo` |
213
+ | Others | `unpaywall` → `europepmc` → `crossref_tdm` → `osti` → `semantic` → `elsevier` |
214
+
215
+ arXiv, PMC and OpenReview ids go straight to `arxiv`, `pmc` and `openreview`. `pmc` fetches Europe PMC's PDF render and, when that endpoint refuses (it throttles hosts that ask for many articles in a row), the full-text JATS XML from Europe PMC's REST service or from NCBI's efetch, which also serves author manuscripts (`NCBI_API_KEY` is optional and raises NCBI's rate limit).
216
+
217
+ What the less obvious tools do:
218
+
219
+ * `elsevier` asks for the PDF first and keeps it only when the API key is entitled to the full PDF; Elsevier otherwise answers with HTTP 200 and a PDF containing only the article's first page, so the tool discards that and takes the full-text XML instead, writing a markdown rendering next to it. Abstract-only XML is rejected. The returned path always carries the extension of the format actually written.
220
+ * `crossref_tdm` tries every full-text link registered with Crossref, including the `unspecified` content-type links that APS, ACS and RSC use; they return the PDF on an entitled network.
221
+ * `europepmc` downloads PMC-hosted open-access articles and the repository copies (usually author manuscripts) listed in Europe PMC's record for the DOI. When the record says the article's full text is in PMC (author manuscripts deposited under funder mandates), it takes the PMC copy: the PDF render, or the JATS XML when that endpoint refuses.
222
+ * `osti` queries the OSTI API for the DOI and downloads the accepted manuscript that DOE-funded articles receive on osti.gov about a year after publication. It needs no credentials; records still under embargo have no full text and the tool moves on.
223
+ * `semantic` downloads the open-access PDF Semantic Scholar has indexed for the DOI, mostly arXiv and institutional-repository copies of subscription articles.
224
+ * `unpaywall` and `semantic` also accept repository landing pages: when an index lists the page rather than the file (HAL, DSpace, Columbia Academic Commons), the tool reads the `citation_pdf_url` tag the page carries for Google Scholar and downloads that.
225
+ * `chemrxiv` goes through the Cambridge Open Engage API, which works from hosts that chemrxiv.org itself blocks.
226
+ * `biorxiv` asks the bioRxiv API which server (bioRxiv or medRxiv) holds the DOI and which version is current, then fetches that PDF. Requests are paced (the site answers 429 with a 100 s Retry-After after a burst) and the transient 503s it returns are retried; when the API itself is throttling, the unversioned URL, which redirects to the current version, is tried on both servers.
227
+ * `mdpi` builds the article's path on MDPI's CDN (`mdpi-res.com`) from the Crossref record; www.mdpi.com itself refuses requests from cloud-provider address ranges.
228
+ * `zenodo` downloads the PDF attached to a Zenodo record (10.5281 DOIs); a concept DOI resolves to the latest version.
229
+ * `wiley` is also used for society journals hosted on Wiley Online Library (AGU and others): Crossref lists their full-text links on wiley.com, and the TDM API serves them. Likewise `elsevier` is added for journals whose Crossref links point at Elsevier, and it closes the default list because Elsevier's API also serves society journals it distributes (ASH's Blood) under their own publisher name; a non-Elsevier DOI costs one quick 404.
230
+ * `semantic` also downloads the arXiv version named in a record's `externalIds` when the record lists no PDF, and with `SEMANTIC_SCHOLAR_API_KEY` searches by title for a second record of the same paper (the search endpoint answers 429 without a key). Requests are spaced one second apart, Semantic Scholar's limit.
231
+
232
+ Downloads send a browser User-Agent, retry with a plain one for repositories that serve PDFs only to non-browser clients, and, with the `tls` extra, once more with a Chrome TLS fingerprint. Wiley requests are paced to 30 per 10 minutes (the published limit is 60, but the API answers HTTP 500 from about 35 on), Crossref requests to its polite-pool limit, and transient 429/5xx responses are retried once.
233
+
234
+ Routes that return preprints or accepted manuscripts (`arxiv`, `chemrxiv`, `biorxiv`, `osti`, `semantic`, repository copies from `unpaywall` and `europepmc`) set `note` in the result. See ``PUBLISHER_TOOL_MAP`` in ``downloader.py``.
235
+
236
+ > **Tip** – Scraping-based methods (`springerpdf`, `elife`, `cambridge`, etc.) can break if sites change layout or due to access limits; favour official APIs and Unpaywall for large-scale downloads.
237
+
238
+ ### Customising the tool sequence
239
+
240
+ ```python
241
+ from fulltext_article_downloader import fetch
242
+ fetch("10.1017/S0885715624000484", "papers", tools=["unpaywall", "cambridge"]) # override default order
243
+ ```
244
+
245
+ ### Override at runtime:
246
+
247
+ ```python
248
+ from fulltext_article_downloader import PUBLISHER_TOOL_MAP
249
+ PUBLISHER_TOOL_MAP["Elsevier BV"] = ["elsevier", "unpaywall"]
250
+ ```
251
+
252
+ ---
253
+
254
+ ## 5. License and Disclaimer.
255
+
256
+ BSD 3-Clause. See the `LICENSE` file.
257
+
258
+ Use this tool **only** for content you are legally entitled to access. Respect publisher terms and copyright laws. It does not use Sci-Hub or similar sites and does not try to get around access controls. The authors are **not** responsible for misuse.
259
+
260
+ Speed-coded by computron on vibes (ChatGPT 4.0) and caffeine; extended by Xu Huang with Claude.
@@ -0,0 +1,29 @@
1
+ import os
2
+ import logging
3
+ import sys
4
+
5
+ __version__ = "0.1.0"
6
+
7
+ # Load API keys from configuration file if present
8
+ def _load_api_keys():
9
+ """Load API keys from configuration file into environment variables, if not already set."""
10
+ config_path = os.path.expanduser("~/.fulltext_keys")
11
+ try:
12
+ if os.path.exists(config_path):
13
+ with open(config_path, 'r') as f:
14
+ for line in f:
15
+ line = line.strip()
16
+ if not line or line.startswith('#') or '=' not in line:
17
+ continue
18
+ key, value = line.split('=', 1)
19
+ key = key.strip()
20
+ value = value.strip()
21
+ if key and value and key not in os.environ:
22
+ os.environ[key] = value
23
+ except Exception as e:
24
+ # If any error occurs, we simply don't load keys (user can still set them manually)
25
+ logging.warning(f"Could not load API keys from config file: {e}")
26
+
27
+ _load_api_keys()
28
+
29
+ from .downloader import download_article, bulk_download_articles, fetch, fetch_many, get_publisher_from_doi, PUBLISHER_TOOL_MAP, DEFAULT_TOOLS