Convert CSV files to Anki deck packages with ease
Project description
CSV to Anki Converter
Convert CSV files to Anki deck packages (.apkg files) with ease! This project provides two Python scripts for different use cases: command-line conversion and automatic batch processing.
๐ Features
- โ Convert CSV files with 'Front' and 'Back' columns to Anki decks
- โ Support for HTML formatting in flashcards
- โ Two conversion modes: command-line and automatic batch processing
- โ Customizable deck names and output file paths
- โ Input and output directory support
- โ Proper error handling and validation
- โ Batch processing of multiple CSV files
- โ Cross-platform compatibility (Windows, macOS, Linux)
๐ Requirements
- Python 3.8 or higher
- pip (Python package installer)
๐ง Installation
Option 1: Install from PyPI (Recommended)
pip install csv-to-anki-converter
After installation, you can use the command-line tool:
# Convert a single file
csv-to-anki your_file.csv
# Batch convert all CSV files in a directory
csv-to-anki --batch --input-dir ./csv_files --output-dir ./anki_decks
Option 2: Install from Source
-
Clone or download this repository
git clone https://github.com/yourusername/csv-to-anki-converter.git cd csv-to-anki-converter
-
Install required dependencies
pip install -r requirements.txt
๐ Usage
Using the Installed Package (Recommended)
After installing via pip install csv-to-anki-converter, you can use the csv-to-anki command:
Single File Conversion
# Basic usage
csv-to-anki your_file.csv
# With custom options
csv-to-anki your_file.csv --deck-name "My Study Deck" --output my_deck.apkg
Batch Conversion
# Convert all CSV files in current directory
csv-to-anki --batch
# Convert from specific directories
csv-to-anki --batch --input-dir ./csv_files --output-dir ./anki_decks
Using the Standalone Scripts
If you downloaded the source code, you can use the standalone Python scripts:
1. Command Line Version (csv_to_anki.py)
Perfect for converting specific CSV files with custom options.
Basic Usage
python csv_to_anki.py your_file.csv
Advanced Usage
# Custom deck name
python csv_to_anki.py your_file.csv --deck-name "My Study Deck"
# Custom output file
python csv_to_anki.py your_file.csv --output my_deck.apkg
# Both custom name and output
python csv_to_anki.py your_file.csv --deck-name "German Vocabulary" --output german.apkg
# Verbose output
python csv_to_anki.py your_file.csv --verbose
Options
--deck-name, -n: Custom name for the Anki deck--output, -o: Custom output file path--verbose, -v: Enable verbose output--help, -h: Show help message
2. Automatic Batch Converter (auto_csv_to_anki.py)
Great for batch processing multiple CSV files.
Basic Usage
# Convert all CSV files in current directory
python auto_csv_to_anki.py
# Use custom input directory
python auto_csv_to_anki.py --input-dir ./csv_files
# Use custom output directory
python auto_csv_to_anki.py --output-dir ./anki_decks
# Use both custom directories
python auto_csv_to_anki.py --input-dir ./csv_files --output-dir ./anki_decks
Options
--input-dir, -i: Directory to search for CSV files (default: current directory)--output-dir, -o: Directory to save .apkg files (default: current directory)--help, -h: Show help message
๐ CSV Format
Your CSV file should have exactly two columns named 'Front' and 'Back':
Front,Back
"What is the capital of France?","Paris"
"What is 2+2?","4"
"What is <b>HTML</b>?","<b>H</b>yper<b>T</b>ext <b>M</b>arkup <b>L</b>anguage"
HTML Support
The converter supports HTML formatting in both Front and Back fields:
<b>text</b>- Bold text<i>text</i>- Italic text<u>text</u>- Underlined text<br>- Line break<sub>text</sub>- Subscript<sup>text</sup>- Superscript- And more standard HTML tags
๐ Project Structure
csv-to-anki-converter/
โโโ csv_to_anki.py # Command line converter
โโโ auto_csv_to_anki.py # Automatic batch converter
โโโ demo.py # Demo script
โโโ requirements.txt # Dependencies
โโโ README.md # This file
โโโ LICENSE # MIT License
โโโ examples/ # Sample CSV files
โโโ test.csv
โโโ french.csv
โโโ programming.csv
โโโ simple_programming.csv
๐งช Testing
Run the demo script to test both converters:
python demo.py
This will:
- Test the command line converter with a sample file
- Test the automatic converter with default settings
- Test the automatic converter with custom directories
๐ Examples
Example 1: Simple Vocabulary
Front,Back
"Hello","Hola"
"Goodbye","Adiรณs"
"Please","Por favor"
"Thank you","Gracias"
Example 2: Programming Terms
Front,Back
"What is Python?","A high-level programming language"
"What is HTML?","HyperText Markup Language"
"What is CSS?","Cascading Style Sheets"
Example 3: Math with HTML Formatting
Front,Back
"What is the formula for area of a circle?","A = ฯ ร r<sup>2</sup>"
"What is <b>E=mcยฒ</b>?","Einstein's mass-energy equivalence equation"
"What is H<sub>2</sub>O?","Water molecule"
๐ค Which Script Should I Use?
Use csv_to_anki.py when:
- You want to convert a specific CSV file
- You need custom deck names or output file names
- You want to process files from different directories
- You need verbose output for debugging
Use auto_csv_to_anki.py when:
- You have multiple CSV files to convert
- You want automatic naming (file name becomes deck name)
- You prefer a simple "run and done" approach
- You want to batch process all CSV files in a directory
๐ง Troubleshooting
Common Issues
-
"No module named 'pandas'" or "No module named 'genanki'"
- Install dependencies:
pip install -r requirements.txt
- Install dependencies:
-
"CSV file must contain 'Front' and 'Back' columns"
- Ensure your CSV has exactly these column names (case-sensitive)
-
"No CSV files found"
- Check that your CSV files are in the correct directory
- Verify file extensions are
.csv
-
HTML warnings
- These are informational and don't affect functionality
- They appear when HTML tags are detected in your content
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
๐ Support
If you encounter any issues or have questions, please open an issue on GitHub.
Happy studying with Anki! ๐
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file csv_to_anki_converter-1.0.0.tar.gz.
File metadata
- Download URL: csv_to_anki_converter-1.0.0.tar.gz
- Upload date:
- Size: 22.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3bf15fcd8241b45e88b189f9b9cdb3145a76446159a29dea1c2cb3f8c0ca2548
|
|
| MD5 |
8a91592fff92b4563493c9e5005f0d2d
|
|
| BLAKE2b-256 |
e0e947201c1c66a2f7dd14ac3d27b127739d256e92e0d71019ffdd62a138adb6
|
File details
Details for the file csv_to_anki_converter-1.0.0-py3-none-any.whl.
File metadata
- Download URL: csv_to_anki_converter-1.0.0-py3-none-any.whl
- Upload date:
- Size: 9.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a3c5d06b797aa9e28ec753d85b89c6796bb34504aa1a4b0156902ef59dae808d
|
|
| MD5 |
30193f80af4680c680d2d218e9718272
|
|
| BLAKE2b-256 |
ccde0a1fd9ffbbc9a079d20ce5535876e6cf53c01cf3963dd006f9bfc6f4b2e5
|