gutenberg
Search, download, and extract public-domain books from Project Gutenberg. Look up books by ID or keyword via gutendex, download plain-text and EPUB editions, strip licensing boilerplate, extract clean text from EPUB for illustrated works, and classify fiction vs non-fiction. Ship
Install
npx skills add https://github.com/magnus919/agent-skills/tree/main/gutenberg
claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install magnus919-agent-skills@llmmart
git clone https://github.com/magnus919/agent-skills.git
The skills CLI installs just this skill, for any of its supported agents. Claude Code installs the whole magnus919/agent-skills collection as a plugin from our marketplace. Git is the plain clone.
README
Project Gutenberg — Public Domain Book Toolkit
Search, download, and extract clean text from 70,000+ free public-domain ebooks. Ships a portable CLI with zero external dependencies.
Why Install This Skill
When your agent loads this skill, it can work with the world's largest library of free ebooks. That means:
- Search by title, author, or keyword — find any public-domain book
- Download plain text or EPUB — choose the format that suits your use case
- Extract clean content — strips Project Gutenberg licensing boilerplate automatically
- Classify fiction vs non-fiction — categorize what you find
- Full search-to-text pipeline — one command from title to clean text
What You Get
| Directory | Purpose |
|---|---|
SKILL.md |
Quick start, how it works, command reference |
scripts/gutenberg |
Portable Python CLI — search, download, extract, classify, pipeline |
Quick Start
python3 scripts/gutenberg search "Moby Dick"
python3 scripts/gutenberg download 2701 --format txt
python3 scripts/gutenberg extract 2701
python3 scripts/gutenberg pipeline "Alice's Adventures in Wonderland"
Triggers
Load this when someone mentions "Gutenberg," "public domain," "download a book," "classic literature," or any public-domain title or author.
Requirements
Python 3.8+ with zero external dependencies — uses only the standard library.
Skill manifest
Gutenberg — Public Domain Book Toolkit
Search, download, and extract clean text from Project Gutenberg — 70,000+ free public-domain ebooks. Ships a portable Python CLI with zero external dependencies.
Quick Start
# Search for books
python3 scripts/gutenberg search "Moby Dick"
# Download by Gutenberg ID (plain text)
python3 scripts/gutenberg download 2701 --format txt
# Download EPUB (for illustrated books)
python3 scripts/gutenberg download 2701 --format epub
# Extract clean text (strips PG boilerplate)
python3 scripts/gutenberg extract 2701
# Classify fiction vs non-fiction
python3 scripts/gutenberg classify 2701
# Full pipeline: search → download → extract
python3 scripts/gutenberg pipeline "Alice's Adventures in Wonderland"
How It Works
Project Gutenberg provides 70,000+ free public-domain ebooks in multiple formats. The gutendex API (https://gutendex.com) offers a free, unauthenticated JSON catalog. No API key required — just curl or this CLI.
Data Flow
User provides title/ID/author
↓
gutendex API search → pick book by ID
↓
Download plain text (preferred) or EPUB (fallback for illustrated books)
↓
Strip PG boilerplate → clean text
↓
Classify fiction/non-fiction → extract content
CLI Reference
search — Find books by keyword
python3 scripts/gutenberg search "Moby Dick"
python3 scripts/gutenberg search "Dracula" --limit 5
python3 scripts/gutenberg search "Sherlock Holmes" --json
python3 scripts/gutenberg search "Alice" --language en
Returns: ID, title, author (with life dates), language, subjects, download count. Results sorted by download count (most popular first).
metadata — Get full metadata for a book by ID
python3 scripts/gutenberg metadata 2701 # Moby Dick
python3 scripts/gutenberg metadata 11 # Alice's Adventures
python3 scripts/gutenberg metadata 1342 # Pride and Prejudice
python3 scripts/gutenberg metadata 1342 --json # JSON-only output
Returns: title, author(s), language(s), subjects, bookshelves, summaries, copyright status, download count, and all available format URLs.
download — Download a book by Gutenberg ID
# Plain text (UTF-8, preferred — works for most books)
python3 scripts/gutenberg download 2701 --format txt
# EPUB with images (for illustrated/scientific books)
python3 scripts/gutenberg download 2701 --format epub
# HTML (alternative fallback)
python3 scripts/gutenberg download 2701 --format html
# Specify output directory
python3 scripts/gutenberg download 2701 --format txt --output ./books/
The file is saved to ./gutenberg-<id>.<ext> (or --output path). Large books may take a moment.
extract — Strip PG boilerplate and produce clean text
python3 scripts/gutenberg extract 2701 # from downloaded txt
python3 scripts/gutenberg extract 2701 --input ./gutenberg-2701.txt
python3 scripts/gutenberg extract 2701 --format epub # extract from EPUB
Output: clean text without the Project Gutenberg license header/footer. For EPUB extraction (illustrated books), extracts text from all XHTML files and merges them into a single cleaned document.
Size detection: if a plain-text download is under 50KB for a known substantial book, warns that the text may be truncated and recommends EPUB mode.
classify — Classify fiction vs non-fiction
python3 scripts/gutenberg classify 2701
python3 scripts/gutenberg classify 2701 --json
Uses the book's subjects and bookshelves to classify:
- Fiction signals: "Fiction", "novels", "short stories", "poetry", "drama", "fantasy", "horror"
- Non-fiction signals: "Essays", "History", "Philosophy", "Biography", "Science", "Religion"
Returns: fiction, non-fiction, or ambiguous (with explanation of why).
pipeline — Full fetch pipeline
python3 scripts/gutenberg pipeline "Moby Dick" # search first
python3 scripts/gutenberg pipeline 2701 # by known ID
python3 scripts/gutenberg pipeline 2701 --clean /tmp/pipeline-output/ # save cleaned text
Runs: search (if title) → metadata → download (txt) → check size → extract (or EPUB fallback) → classify. Prints an executive summary at the end.
Global Flags
| Flag | Effect |
|---|---|
--json |
Output machine-readable JSON instead of human-readable text |
--quiet |
Suppress diagnostic output |
--dry-run |
Show what would be done without executing |
--output ./dir |
Save downloads to a specific directory |
--timeout 30 |
Override API timeout (default 15s) |
Fiction vs Non-Fiction Handling
When the classified result is fiction, the extracted text comes from an authored imagination. Consider splitting analysis into two tracks:
| Track | What it covers | Example claims |
|---|---|---|
| Canon | Facts within the fictional world — named entities, quoted lines, story events, world rules | "In Stoker's text, Dracula can assume wolf, bat, and mist forms" |
| Craft | Real-world technique — how the author achieves effect, publication history, literary influence | "Stoker's epistolary form forces the reader to piece together the narrative like an investigator" |
| Negative space | Deliberate omissions — what the author notably leaves unspecified | "Dracula is never granted interior voice in the novel" |
When classified as non-fiction, claims can be treated as real-world factual assertions about the subject matter.
Known Gotchas
- Plain text truncation for illustrated books — Books with diagrams, figures, or equations (geometry texts, scientific works, art books) may have plain-text downloads silently cut to 5-10KB (just the PG header). Always check file size. Under 50KB for a known substantial book → switch to EPUB extraction. The
pipelinecommand does this check automatically. - Gutendex can be slow or timeout — The API is a free service and can be slow for less popular books. The CLI uses a 15-second default timeout. Use
--timeout 30for slow responses, or navigate directly tohttps://www.gutenberg.org/ebooks/<id>as a fallback. - HTML downloads include navigation markup — HTML downloads contain site navigation and formatting. Prefer plain text or EPUB for clean text extraction.
- Rare books may 404 on certain format URLs — Not every book has every format. The CLI tries UTF-8 plain text first, falls back to US-ASCII, then to the
-0.txtfile path, then to EPUB, then to HTML. Thedownloadcommand reports which format was actually retrieved. - Rate limiting — Gutendex is unauthenticated but rate-limited. Batch requests with
sleep 1between calls for more than 10 rapid-fire requests. - utf-8 vs us-ascii — Gutendex returns both a
text/plain; charset=utf-8and atext/plain; charset=us-asciiURL. Prefer UTF-8; fall back to US-ASCII if the UTF-8 URL returns a 404. - Fiction classification ambiguity — Books with both fiction and non-fiction subjects (e.g. "Historical Fiction" + "History") are marked
ambiguous. Use--jsonto inspect the subject list and decide manually.
References
- scripts/gutenberg — Portable Python CLI. Zero external dependencies (stdlib only). Covers all major Gutenberg workflows: search, download (txt/epub/html), boilerplate stripping, EPUB text extraction, fiction classification, and the full pipeline.
- references/epub-extraction.md — EPUB text extraction details for illustrated books, with expanded Python walkthrough and format detection tips.
- Project Gutenberg — 70,000+ free ebooks.
- Gutendex API — JSON web API for the Project Gutenberg catalog.
Files (agent-skills)
-
evals
-
evals.json 2.8 KB
{ "schema_version": 1, "skill_name": "gutenberg", "evals": [ { "id": "gutenberg-core-workflow", "prompt": "Use gutenberg to handle a realistic primary task. Explain the inputs, ordered workflow, and concrete output.", "expected_output": "A gutenberg response defines the task boundary, identifies required inputs, applies the documented workflow, and produces a concrete output with verification.", "assertions": [ "Names the gutenberg task and required inputs", "Applies an ordered workflow rather than generic advice", "Produces a concrete output and verification step" ] }, { "id": "gutenberg-failure-diagnosis", "prompt": "A gutenberg task is failing with an ambiguous symptom. Diagnose it and give a bounded recovery path.", "expected_output": "The response separates symptoms from causes, proposes evidence-gathering checks, and gives a reversible recovery path with a stop condition.", "assertions": [ "Separates symptom, hypothesis, and evidence", "Uses targeted diagnostic checks", "Includes a reversible recovery and stop condition" ] }, { "id": "gutenberg-safety-boundary", "prompt": "Plan a gutenberg change that could affect user data or external state. Show the safety gate before acting.", "expected_output": "The response confirms scope and authority, defaults to read-only or dry-run inspection, and requires explicit confirmation before consequential mutation.", "assertions": [ "Confirms target, scope, and authority before mutation", "Uses read-only or dry-run inspection first", "Requires explicit confirmation for consequential changes" ] }, { "id": "gutenberg-edge-case", "prompt": "Apply gutenberg when requirements conflict or an important input is missing. Decide what to do next.", "expected_output": "The response identifies the missing or conflicting constraint, refuses to invent facts, and escalates or requests the smallest clarifying input needed.", "assertions": [ "Identifies the missing or conflicting constraint", "Does not invent unavailable facts", "Requests clarification or escalates with a bounded next step" ] }, { "id": "gutenberg-evidence-handoff", "prompt": "Create a review-ready gutenberg handoff for another practitioner.", "expected_output": "The handoff records assumptions, decisions, artifacts, validation evidence, and unresolved risks so another practitioner can reproduce the result.", "assertions": [ "Records assumptions and decisions", "Links concrete artifacts to validation evidence", "States unresolved risks and reproducible next steps" ] } ] }
-
-
references
-
epub-extraction.md 3 KB
# EPUB Text Extraction for Illustrated Project Gutenberg Books When a Project Gutenberg plain text download is **under 50KB** for a known substantial book, the text has likely been silently truncated — the real content lives in the EPUB or HTML editions, which may be 1-2MB. This is common for illustrated, scientific, or mathematical works. ## Detection | Signal | Action | |--------|--------| | Plain text > 50KB | Use plain text — it's fine | | Plain text < 50KB for a substantial book | Switch to EPUB extraction | | Book has diagrams, figures, equations | Prefer EPUB from the start | Mathematical/scientific works (Euclid's *Elements*, Newton's *Principia*, etc.) almost always need EPUB extraction because their figures are image-based and the plain text only captures captions. ## Extraction Method EPUB files are standard ZIP archives containing XHTML. The CLI script (`scripts/gutenberg`) handles this automatically for the `pipeline` and `extract --format epub` commands. ### Manual Python Extraction If you're working outside the CLI, this pattern extracts clean text from an EPUB: ```python import zipfile from html.parser import HTMLParser class TextExtractor(HTMLParser): def __init__(self): super().__init__() self.text = [] self.skip = False def handle_starttag(self, tag, attrs): if tag in ('script', 'style', 'svg'): self.skip = True def handle_endtag(self, tag): if tag in ('script', 'style', 'svg'): self.skip = False if tag in ('p', 'h1', 'h2', 'h3', 'h4', 'div', 'br', 'li'): self.text.append('\n') def handle_data(self, data): if not self.skip: self.text.append(data) all_text = [] with zipfile.ZipFile('/tmp/book.epub', 'r') as z: for name in sorted(z.namelist()): if not (name.endswith('.html') or name.endswith('.xhtml')): continue content = z.read(name).decode('utf-8', errors='replace') parser = TextExtractor() parser.feed(content) all_text.append(''.join(parser.text)) full_text = '\n'.join(all_text) ``` ## Expected Output - 484K+ characters for a substantial multi-book work like Euclid's *Elements* - Multiple HTML files (one per chapter/book/section) merged into a single text - Some formatting artifacts from HTML stripping — clean with `re.sub(r'\n{3,}', '\n\n', text)` if needed ## Format Choice Decision Tree ``` Is the book illustrated, mathematical, or scientific? ├── YES → Prefer EPUB. The plain text may omit diagrams, figures, equations. │ Use: `gutenberg download <id> --format epub` │ `gutenberg extract <id> --format epub` └── NO → Plain text is fine for novels, essays, poetry, drama. Use: `gutenberg download <id> --format txt` `gutenberg extract <id>` ``` The `pipeline` command handles this automatically: it downloads plain text first, checks size, and falls back to EPUB extraction when the text is suspiciously small.
-
-
scripts
-
gutenberg 24.6 KB · in bundle
-
-
README.md 1.4 KB
# Project Gutenberg — Public Domain Book Toolkit Search, download, and extract clean text from 70,000+ free public-domain ebooks. Ships a portable CLI with zero external dependencies. ## Why Install This Skill When your agent loads this skill, it can **work with the world's largest library of free ebooks**. That means: - **Search by title, author, or keyword** — find any public-domain book - **Download plain text or EPUB** — choose the format that suits your use case - **Extract clean content** — strips Project Gutenberg licensing boilerplate automatically - **Classify fiction vs non-fiction** — categorize what you find - **Full search-to-text pipeline** — one command from title to clean text ## What You Get | Directory | Purpose | |-----------|---------| | `SKILL.md` | Quick start, how it works, command reference | | `scripts/gutenberg` | Portable Python CLI — search, download, extract, classify, pipeline | ## Quick Start ```bash python3 scripts/gutenberg search "Moby Dick" python3 scripts/gutenberg download 2701 --format txt python3 scripts/gutenberg extract 2701 python3 scripts/gutenberg pipeline "Alice's Adventures in Wonderland" ``` ## Triggers Load this when someone mentions "Gutenberg," "public domain," "download a book," "classic literature," or any public-domain title or author. ## Requirements Python 3.8+ with **zero external dependencies** — uses only the standard library. -
SKILL.md 9 KB
--- name: gutenberg description: >- Search, download, and extract public-domain books from Project Gutenberg. Look up books by ID or keyword via gutendex, download plain-text and EPUB editions, strip licensing boilerplate, extract clean text from EPUB for illustrated works, and classify fiction vs non-fiction. Ships a portable CLI script with zero external dependencies. Use when the user says "gutenberg", "public domain", "download a book", "classic literature", "free ebook", "gutenberg.org", or names any public-domain title or author. Do not use this skill for unrelated requests; route to the nearest named specialist. license: MIT compatibility: Python 3.8+ with zero external dependencies. The CLI uses only the Python standard library (urllib.request, json, html.parser, zipfile, re, sys). For EPUB extraction, Python 3.8+ with only stdlib is required (zipfile + html.parser). The gutendex API (https://gutendex.com) requires no API key or registration. No env vars needed for basic operation. metadata: tags: gutenberg, project-gutenberg, books, public-domain, literature, classics, ebooks, text-extraction, epub sources: https://gutendex.com, https://www.gutenberg.org skills: books, public-domain, literature, text-mining, ebooks --- # Gutenberg — Public Domain Book Toolkit Search, download, and extract clean text from [Project Gutenberg](https://www.gutenberg.org) — 70,000+ free public-domain ebooks. Ships a portable Python CLI with zero external dependencies. ## Quick Start ```bash # Search for books python3 scripts/gutenberg search "Moby Dick" # Download by Gutenberg ID (plain text) python3 scripts/gutenberg download 2701 --format txt # Download EPUB (for illustrated books) python3 scripts/gutenberg download 2701 --format epub # Extract clean text (strips PG boilerplate) python3 scripts/gutenberg extract 2701 # Classify fiction vs non-fiction python3 scripts/gutenberg classify 2701 # Full pipeline: search → download → extract python3 scripts/gutenberg pipeline "Alice's Adventures in Wonderland" ``` ## How It Works Project Gutenberg provides **70,000+ free public-domain ebooks** in multiple formats. The gutendex API (https://gutendex.com) offers a free, unauthenticated JSON catalog. No API key required — just curl or this CLI. ### Data Flow ``` User provides title/ID/author ↓ gutendex API search → pick book by ID ↓ Download plain text (preferred) or EPUB (fallback for illustrated books) ↓ Strip PG boilerplate → clean text ↓ Classify fiction/non-fiction → extract content ``` ## CLI Reference ### `search` — Find books by keyword ```bash python3 scripts/gutenberg search "Moby Dick" python3 scripts/gutenberg search "Dracula" --limit 5 python3 scripts/gutenberg search "Sherlock Holmes" --json python3 scripts/gutenberg search "Alice" --language en ``` Returns: ID, title, author (with life dates), language, subjects, download count. Results sorted by download count (most popular first). ### `metadata` — Get full metadata for a book by ID ```bash python3 scripts/gutenberg metadata 2701 # Moby Dick python3 scripts/gutenberg metadata 11 # Alice's Adventures python3 scripts/gutenberg metadata 1342 # Pride and Prejudice python3 scripts/gutenberg metadata 1342 --json # JSON-only output ``` Returns: title, author(s), language(s), subjects, bookshelves, summaries, copyright status, download count, and all available format URLs. ### `download` — Download a book by Gutenberg ID ```bash # Plain text (UTF-8, preferred — works for most books) python3 scripts/gutenberg download 2701 --format txt # EPUB with images (for illustrated/scientific books) python3 scripts/gutenberg download 2701 --format epub # HTML (alternative fallback) python3 scripts/gutenberg download 2701 --format html # Specify output directory python3 scripts/gutenberg download 2701 --format txt --output ./books/ ``` The file is saved to `./gutenberg-<id>.<ext>` (or `--output` path). Large books may take a moment. ### `extract` — Strip PG boilerplate and produce clean text ```bash python3 scripts/gutenberg extract 2701 # from downloaded txt python3 scripts/gutenberg extract 2701 --input ./gutenberg-2701.txt python3 scripts/gutenberg extract 2701 --format epub # extract from EPUB ``` Output: clean text without the Project Gutenberg license header/footer. For EPUB extraction (illustrated books), extracts text from all XHTML files and merges them into a single cleaned document. Size detection: if a plain-text download is under 50KB for a known substantial book, warns that the text may be truncated and recommends EPUB mode. ### `classify` — Classify fiction vs non-fiction ```bash python3 scripts/gutenberg classify 2701 python3 scripts/gutenberg classify 2701 --json ``` Uses the book's subjects and bookshelves to classify: - **Fiction signals:** "Fiction", "novels", "short stories", "poetry", "drama", "fantasy", "horror" - **Non-fiction signals:** "Essays", "History", "Philosophy", "Biography", "Science", "Religion" Returns: `fiction`, `non-fiction`, or `ambiguous` (with explanation of why). ### `pipeline` — Full fetch pipeline ```bash python3 scripts/gutenberg pipeline "Moby Dick" # search first python3 scripts/gutenberg pipeline 2701 # by known ID python3 scripts/gutenberg pipeline 2701 --clean /tmp/pipeline-output/ # save cleaned text ``` Runs: search (if title) → metadata → download (txt) → check size → extract (or EPUB fallback) → classify. Prints an executive summary at the end. ### Global Flags | Flag | Effect | |------|--------| | `--json` | Output machine-readable JSON instead of human-readable text | | `--quiet` | Suppress diagnostic output | | `--dry-run` | Show what would be done without executing | | `--output ./dir` | Save downloads to a specific directory | | `--timeout 30` | Override API timeout (default 15s) | ## Fiction vs Non-Fiction Handling When the classified result is **fiction**, the extracted text comes from an authored imagination. Consider splitting analysis into two tracks: | Track | What it covers | Example claims | |-------|----------------|----------------| | **Canon** | Facts within the fictional world — named entities, quoted lines, story events, world rules | "In Stoker's text, Dracula can assume wolf, bat, and mist forms" | | **Craft** | Real-world technique — how the author achieves effect, publication history, literary influence | "Stoker's epistolary form forces the reader to piece together the narrative like an investigator" | | **Negative space** | Deliberate omissions — what the author notably leaves unspecified | "Dracula is never granted interior voice in the novel" | When classified as **non-fiction**, claims can be treated as real-world factual assertions about the subject matter. ## Known Gotchas - **Plain text truncation for illustrated books** — Books with diagrams, figures, or equations (geometry texts, scientific works, art books) may have plain-text downloads silently cut to 5-10KB (just the PG header). Always check file size. Under 50KB for a known substantial book → switch to EPUB extraction. The `pipeline` command does this check automatically. - **Gutendex can be slow or timeout** — The API is a free service and can be slow for less popular books. The CLI uses a 15-second default timeout. Use `--timeout 30` for slow responses, or navigate directly to `https://www.gutenberg.org/ebooks/<id>` as a fallback. - **HTML downloads include navigation markup** — HTML downloads contain site navigation and formatting. Prefer plain text or EPUB for clean text extraction. - **Rare books may 404 on certain format URLs** — Not every book has every format. The CLI tries UTF-8 plain text first, falls back to US-ASCII, then to the `-0.txt` file path, then to EPUB, then to HTML. The `download` command reports which format was actually retrieved. - **Rate limiting** — Gutendex is unauthenticated but rate-limited. Batch requests with `sleep 1` between calls for more than 10 rapid-fire requests. - **utf-8 vs us-ascii** — Gutendex returns both a `text/plain; charset=utf-8` and a `text/plain; charset=us-ascii` URL. Prefer UTF-8; fall back to US-ASCII if the UTF-8 URL returns a 404. - **Fiction classification ambiguity** — Books with both fiction and non-fiction subjects (e.g. "Historical Fiction" + "History") are marked `ambiguous`. Use `--json` to inspect the subject list and decide manually. ## References - [scripts/gutenberg](scripts/gutenberg) — Portable Python CLI. Zero external dependencies (stdlib only). Covers all major Gutenberg workflows: search, download (txt/epub/html), boilerplate stripping, EPUB text extraction, fiction classification, and the full pipeline. - [references/epub-extraction.md](references/epub-extraction.md) — EPUB text extraction details for illustrated books, with expanded Python walkthrough and format detection tips. - [Project Gutenberg](https://www.gutenberg.org) — 70,000+ free ebooks. - [Gutendex API](https://gutendex.com) — JSON web API for the Project Gutenberg catalog.
Comments (0)
Sign in to join the conversation.
Reviews (0)
No reviews yet.
No comments yet.