A flexible and dynamic tool for generating Anki decks from CSV files. Simply drop your CSV files into the csv folder and run the generator to create Anki decks automatically - no code changes required for new deck types! Designed specifically for language learning with intelligent tagging and customization options.
- Zero-configuration deck generation: Drop CSV files in the folder and generate decks instantly
- Automatic CSV structure detection: Automatically detects fields and creates appropriate card templates
- Smart card type detection: Identifies if a CSV should be a cloze deletion or basic card format
- Multi-language support: Tag decks with different language identifiers
- Command-line interface: Easy to use with flexible options
- Intelligent tagging system: Automatically generates relevant tags for language learning
- Custom tag support: Define your own tagging rules based on filename patterns
- Template customization: Create and use custom card templates and CSS styling
- Media support: Include images and audio files in your decks
- Bulk operations: Generate multiple decks at once and optionally merge them
- Generation history: Keep track of all generated decks with timestamps and tags
- Clone this repository:
git clone https://github.com/dimalama/anki.git
cd anki- Install uv (if not already installed):
curl -LsSf https://astral.sh/uv/install.sh | sh- Create a virtual environment and install dependencies:
uv venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
uv pip install -r requirements.txtThe simplest way to generate decks from all your CSV files:
python auto_generate_decks.pyThis will:
- Scan the
csv/directory for all CSV files - Generate an Anki deck for each CSV file
- Save the decks to the
apkg/directory
The script now uses a command-based interface with several subcommands:
python auto_generate_decks.py generate --language frenchGenerate decks for specific CSV files only:
python auto_generate_decks.py generate --files vocabulary.csv grammar.csvGenerate and merge multiple decks into one:
python auto_generate_decks.py generate --merge --merge-name "Complete Spanish Course"Create cards with both directions (e.g., English→Spanish and Spanish→English):
python auto_generate_decks.py generate --files vocabulary.csv --reversedShow tags that would be applied to specific CSV files:
python auto_generate_decks.py tags --show vocabulary.csv grammar.csvAdd custom tags for files matching a pattern:
python auto_generate_decks.py tags --add --pattern "*_verb_*.csv" --tags verb grammarConfigure a custom template for basic cards:
python auto_generate_decks.py template --type basic --file templates/basic_template.jsonUpdate the CSS styling for all cards:
python auto_generate_decks.py template --css templates/custom_style.csspython auto_generate_decks.py historyThe generator works with any CSV structure. Here are some examples:
Basic Cards (Front/Back):
English,Spanish
Hello,Hola
Goodbye,Adiós
Cloze Deletion Cards:
Text,Translation,Explanation
I {{c1::am}} a student,Yo soy un estudiante,Using ser for permanent states
You can tag your decks with any of these language identifiers:
- spanish
- english
- french
- german
- italian
- portuguese
- russian
- japanese
- chinese
- korean
- generic (default for unspecified languages)
The generator:
- Analyzes the structure of your CSV files
- Creates appropriate Anki card templates based on the columns
- Generates unique model and deck IDs based on the filename
- Creates intelligent tags based on the filename, columns, and content
- Exports the deck as an APKG file ready to import into Anki
The auto-generator includes an intelligent tagging system specifically designed for language learning:
- Language Tags:
spanish,french,german, etc. - Card Type Tags:
basicorclozedepending on the card format - Source Tags:
auto-generatedto identify machine-generated decks
The system automatically detects and adds relevant tags based on the CSV filename and content:
- Grammar Tags:
verb,noun,adjective,adverb,preposition, etc. - Content Tags:
vocabulary,grammar,translation, etc. - Language Construct Tags:
ir-a,ser-estar,por-para, etc.
A CSV file named spanish_ir_a_infinitive.csv with columns for English and Spanish would get tags like:
spanish(language)basic(card type)ir-a(language construct)future(tense)verb(part of speech)translation(content type)
These tags make it much easier to organize and find your decks in Anki.
anki/
├── anki_deck_generator/ # Core package
│ ├── __init__.py
│ ├── core.py # Core functionality
│ ├── config.py # Configuration
│ ├── cli.py # Command-line interface
│ └── auto_generator.py # Auto-generation functionality
├── csv/ # CSV files go here
├── apkg/ # Generated APKG files
├── media/ # Media files (images, audio) go here
├── config/ # Configuration files
│ └── config.json # Main configuration file
├── templates/ # Custom template files
│ ├── basic_template.json # Template for basic cards
│ ├── cloze_template.json # Template for cloze cards
│ └── custom_style.css # Custom CSS styling
├── auto_generate_decks.py # Main script
├── README.md
└── requirements.txt # Dependencies
- Create your CSV file with appropriate columns
- Place the file in the
csvdirectory - Add any referenced media files to the
mediadirectory - Run
python auto_generate_decks.py generateto generate the deck
No code changes are required for new CSV files or deck types!
You can generate multiple decks at once by placing multiple CSV files in the csv directory and running:
python auto_generate_decks.py generateYou can generate multiple decks and merge them into a single deck:
python auto_generate_decks.py generate --merge --merge-name "Complete Course"The generator keeps track of all generated decks in a history file (apkg/generation_history.json). You can view this history with:
python auto_generate_decks.py historyThe generator uses a configuration file (config/config.json) that can be modified directly or through the command-line interface.
You can define custom tags to be applied to files matching specific patterns:
{
"custom_tags": {
"*_verb_*.csv": ["verb", "grammar"],
"*_vocabulary_*.csv": ["vocabulary", "basic"]
}
}You can define custom templates for your cards:
{
"templates": {
"basic": {
"name": "Basic Card",
"qfmt": "{{Front}}",
"afmt": "{{FrontSide}}<hr><div class=\"back-content\"><b>{{Back}}</b></div>"
},
"cloze": {
"name": "Cloze Card",
"qfmt": "{{cloze:Text}}<br><div class=\"hint\">{{Hint}}</div>",
"afmt": "{{cloze:Text}}<hr><div class=\"translation\"><b>Translation:</b> {{Translation}}</div>"
}
},
"css": "/* Custom CSS styling */\n.card { font-family: Arial; }"
}Place your media files in the media/ directory and reference them in your CSV files:
- For images:
<img src="image.jpg"> - For audio:
[sound:audio.mp3]
- genanki - For generating Anki decks
- pandas - For CSV processing
- pathlib - For path manipulation
- json - For configuration file handling
MIT