Skip to main content

Convert books and ebooks into Anki flashcards using Anthropic's Claude API.

Project description

epub2anki

Convert books and ebooks into Anki flashcards using Anthropic's Claude API.

Overview

epub2anki transforms your EPUB books into Anki decks (.apkg files). It parses the table of contents and internal book structure, divides the text into manageable chunks, and requests an LLM (Claude) to generate comprehensive and useful Anki flashcards.

Features

  • Structural Parsing: Uses the EPUB's Table of Contents to intelligently split the book into coherent sections.
  • LLM Flashcard Generation: Uses Anthropic's API to construct high-quality flashcards summarizing key concepts.
  • Batch Processing: Can utilize Anthropic's Batch API for up to 50% cost savings on API calls.
  • Resilient Coaching & Caching: Uses SQLite to cache generated notes, meaning if the process is interrupted, you won't be charged twice for previously processed sections!
  • Direct Anki Export: Outputs a ready-to-import .apkg file.

Prerequisites

Installation

You can install epub2anki using pip or uv:

pip install epub2anki

Or using uv (recommended):

uv tool install epub2anki

Usage

Basic usage:

export ANTHROPIC_API_KEY="your-api-key-here"
epub2anki path/to/your/book.epub

This will parse the EPUB, split it into chunks of ~50,000 characters, generate flashcards using the claude-haiku-4-5 model, and finally place a <book-name>.apkg file in the decks/ directory.

Advanced Usage & Batching

To save 50% on API costs, use the --batch flag. This will submit all generation requests to the Anthropic Batch API:

epub2anki path/to/your/book.epub --batch

Note: The Batch API operates asynchronously and takes 5 minutes to 24 hours to finish. epub2anki will submit the batch and return a Batch ID.

Once your batch is ready (you can check your Anthropic Console), run the script again using --fetch-batch:

epub2anki path/to/your/book.epub --fetch-batch msgbat_XXXXXXX

This will retrieve the completed responses from Anthropic, save them into the local cache, and generate your .apkg deck.

Command-Line Arguments

usage: epub2anki [-h] [--batch] [--fetch-batch FETCH_BATCH] [--deck-id DECK_ID]
                 [--chunk-size CHUNK_SIZE] [--model MODEL] [--retries RETRIES]
                 [--db-path DB_PATH] [--output-dir OUTPUT_DIR]
                 [--rate-max-requests RATE_MAX_REQUESTS] [--rate-max-input RATE_MAX_INPUT]
                 [--rate-max-output RATE_MAX_OUTPUT] [--rate-window RATE_WINDOW]
                 book_path

Generate Anki flashcards from EPUB books using an LLM.

positional arguments:
  book_path             Path to the EPUB book.

options:
  -h, --help            show this help message and exit
  --batch               Use Anthropic's async Batch API for 50% lower costs.
  --fetch-batch ID      Fetch an existing batch ID from Anthropic and build the deck.
  --deck-id DECK_ID     Unique integer ID for the Anki deck.
  --chunk-size SIZE     Maximum text size per LLM prompt (default: 50000).
  --model MODEL         Anthropic model (default: claude-haiku-4-5).
  --output-dir DIR      Directory to save the finished .apkg file (default: decks).

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

epub2anki-0.1.0.tar.gz (97.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

epub2anki-0.1.0-py3-none-any.whl (18.2 kB view details)

Uploaded Python 3

File details

Details for the file epub2anki-0.1.0.tar.gz.

File metadata

  • Download URL: epub2anki-0.1.0.tar.gz
  • Upload date:
  • Size: 97.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for epub2anki-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ea6302a5fe07cdfb51da326ef34453384a1bd34995d94d90e2e9b4e3c439f8b5
MD5 923d695a3e5dce0b43ad661190118594
BLAKE2b-256 1ceec6753e478a377c4ba4de50e7b22ce9d81e859f74f4870f39c92b24346093

See more details on using hashes here.

Provenance

The following attestation bundles were made for epub2anki-0.1.0.tar.gz:

Publisher: publish.yml on MatteoGaetzner/epub2anki

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file epub2anki-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: epub2anki-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 18.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for epub2anki-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 204a24af2fcdf0f93a7fbe20b73def9ffc5c89f0ffd5c3d5f2fbb5d3afbc220e
MD5 84a264b920a20aab1416047819517b5a
BLAKE2b-256 f4a2a82a5c3de570a6cc844668737161f791766355bc143e0b097c727fdf84a9

See more details on using hashes here.

Provenance

The following attestation bundles were made for epub2anki-0.1.0-py3-none-any.whl:

Publisher: publish.yml on MatteoGaetzner/epub2anki

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page