anki-card-maker
Automatically extracts knowledge points from study materials and generates flashcards in "front question + back answer" format, outputting a CSV file ready for direct import into Anki.
Two working modes are supported:
- auto mode: Rule-based extraction of definitions, Q&A pairs, lists, and other structured knowledge from Markdown/plain text
- json mode: Accepts pre-constructed JSON flashcard data and formats it as Anki CSV
Quick Start
# Auto-extract flashcards from Markdown notes
python scripts/generate_flashcards.py --input notes.md --output flashcards.csv
# Generate Anki CSV from JSON data (ideal for agent calls)
python scripts/generate_flashcards.py --mode json --input cards.json --output flashcards.csv
# Use via stdin/stdout
cat notes.md | python scripts/generate_flashcards.py > flashcards.csv
Agent Workflow
When a user provides study materials and requests flashcard generation, the recommended workflow is:
- Read the material: Read the study material file provided by the user
- Intelligent extraction: Analyze the material content, extract core knowledge points, and generate high-quality Q&A pairs. Follow these principles:
- Each card focuses on a single knowledge point (minimum information principle)
- Use precise question format on the front; avoid vague questions
- Provide concise but complete answers on the back
- Cover core concepts, definitions, formulas, cause-and-effect relationships, comparisons, etc.
- Generate CSV: Write the extracted Q&A pairs as JSON, then call the script to convert to Anki CSV
- Deliver the file: Inform the user of the output path and import instructions
Agent Call Example
Construct extracted knowledge points as a JSON array and convert to CSV via --mode json:
cat <<'EOF' > /tmp/cards.json
[
{"front": "What is photosynthesis?", "back": "The process by which plants use light energy to convert CO₂ and H₂O into organic matter while releasing O₂", "tags": "biology"},
{"front": "What is the chemical equation for photosynthesis?", "back": "6CO₂ + 6H₂O → C₆H₁₂O₆ + 6O₂", "tags": "biology"}
]
EOF
python scripts/generate_flashcards.py --mode json --input /tmp/cards.json --output flashcards.csv
Parameters
| Parameter |
Description |
Default |
--input, -i |
Input file path |
stdin |
--output, -o |
Output CSV file path |
stdout |
--mode, -m |
Extraction mode: auto (rule-based) or json (structured input) |
auto |
--no-tags |
Omit the tags column |
tags included |
--separator, -s |
CSV separator: \t, ;, , |
Tab |
Output Format
The generated CSV follows the Anki import specification:
#separator:Tab
#html:true
#columns:Front Back Tags
What is photosynthesis? The process by which plants use light energy to convert CO₂ and H₂O into organic matter while releasing O₂ biology
How to Import into Anki
- Open Anki → File → Import
- Select the generated CSV file
- Anki will automatically detect the separator and column mapping
- Confirm and click "Import"
Knowledge Structures Supported in Auto Mode
| Structure Type |
Example |
Generated Flashcard |
| Definition (Term: Definition) |
Photosynthesis: Plants use light energy... |
Q: What is photosynthesis? A: Plants use light energy... |
| Q&A pair |
Q: What is DNA? A: Deoxyribonucleic acid |
Extracted directly as a flashcard |
| Heading + list |
## Organelles - Mitochondria - Ribosome |
Q: What are the key points of Organelles? A: List |
| Heading + paragraph |
## Newton's First Law An object at rest... |
Q: Explain: Newton's First Law A: Paragraph content |
Prerequisites
- Python 3.6+
- No additional dependencies required (uses standard library only)
1---2name: anki-card-maker3description: Extract key knowledge from study materials (text, Markdown, notes) and generate front-question + back-answer flashcards, producing an Anki-compatible CSV file ready for import. Trigger when users mention flashcards, Anki, spaced repetition, need to convert notes into Q&A pairs, or request memory cards or review cards from their study content.4license: MIT5---67# anki-card-maker89Automatically extracts knowledge points from study materials and generates flashcards in "front question + back answer" format, outputting a CSV file ready for direct import into [Anki](https://apps.ankiweb.net/).1011Two working modes are supported:12- **auto mode**: Rule-based extraction of definitions, Q&A pairs, lists, and other structured knowledge from Markdown/plain text13- **json mode**: Accepts pre-constructed JSON flashcard data and formats it as Anki CSV1415## Quick Start1617```bash18# Auto-extract flashcards from Markdown notes19python scripts/generate_flashcards.py --input notes.md --output flashcards.csv2021# Generate Anki CSV from JSON data (ideal for agent calls)22python scripts/generate_flashcards.py --mode json --input cards.json --output flashcards.csv2324# Use via stdin/stdout25cat notes.md | python scripts/generate_flashcards.py > flashcards.csv26```2728## Agent Workflow2930When a user provides study materials and requests flashcard generation, the recommended workflow is:31321. **Read the material**: Read the study material file provided by the user332. **Intelligent extraction**: Analyze the material content, extract core knowledge points, and generate high-quality Q&A pairs. Follow these principles:34 - Each card focuses on a single knowledge point (minimum information principle)35 - Use precise question format on the front; avoid vague questions36 - Provide concise but complete answers on the back37 - Cover core concepts, definitions, formulas, cause-and-effect relationships, comparisons, etc.383. **Generate CSV**: Write the extracted Q&A pairs as JSON, then call the script to convert to Anki CSV394. **Deliver the file**: Inform the user of the output path and import instructions4041### Agent Call Example4243Construct extracted knowledge points as a JSON array and convert to CSV via `--mode json`:4445```bash46cat <<'EOF' > /tmp/cards.json47[48 {"front": "What is photosynthesis?", "back": "The process by which plants use light energy to convert CO₂ and H₂O into organic matter while releasing O₂", "tags": "biology"},49 {"front": "What is the chemical equation for photosynthesis?", "back": "6CO₂ + 6H₂O → C₆H₁₂O₆ + 6O₂", "tags": "biology"}50]51EOF52python scripts/generate_flashcards.py --mode json --input /tmp/cards.json --output flashcards.csv53```5455## Parameters5657| Parameter | Description | Default |58|---|---|---|59| `--input, -i` | Input file path | stdin |60| `--output, -o` | Output CSV file path | stdout |61| `--mode, -m` | Extraction mode: `auto` (rule-based) or `json` (structured input) | auto |62| `--no-tags` | Omit the tags column | tags included |63| `--separator, -s` | CSV separator: `\t`, `;`, `,` | Tab |6465## Output Format6667The generated CSV follows the Anki import specification:6869```70#separator:Tab71#html:true72#columns:Front Back Tags73What is photosynthesis? The process by which plants use light energy to convert CO₂ and H₂O into organic matter while releasing O₂ biology74```7576### How to Import into Anki77781. Open Anki → File → Import792. Select the generated CSV file803. Anki will automatically detect the separator and column mapping814. Confirm and click "Import"8283## Knowledge Structures Supported in Auto Mode8485| Structure Type | Example | Generated Flashcard |86|---|---|---|87| Definition (Term: Definition) | `Photosynthesis: Plants use light energy...` | Q: What is photosynthesis? A: Plants use light energy... |88| Q&A pair | `Q: What is DNA? A: Deoxyribonucleic acid` | Extracted directly as a flashcard |89| Heading + list | `## Organelles - Mitochondria - Ribosome` | Q: What are the key points of Organelles? A: List |90| Heading + paragraph | `## Newton's First Law An object at rest...` | Q: Explain: Newton's First Law A: Paragraph content |9192## Prerequisites9394- Python 3.6+95- No additional dependencies required (uses standard library only)