Skip to main content

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

  1. Clone or download this repository

    git clone https://github.com/yourusername/csv-to-anki-converter.git
    cd csv-to-anki-converter
    
  2. 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:

  1. Test the command line converter with a sample file
  2. Test the automatic converter with default settings
  3. 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

  1. "No module named 'pandas'" or "No module named 'genanki'"

    • Install dependencies: pip install -r requirements.txt
  2. "CSV file must contain 'Front' and 'Back' columns"

    • Ensure your CSV has exactly these column names (case-sensitive)
  3. "No CSV files found"

    • Check that your CSV files are in the correct directory
    • Verify file extensions are .csv
  4. 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


Download files

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

Source Distribution

csv_to_anki_converter-1.0.0.tar.gz (22.3 kB view details)

Uploaded Source

Built Distribution

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

csv_to_anki_converter-1.0.0-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

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

Hashes for csv_to_anki_converter-1.0.0.tar.gz
Algorithm Hash digest
SHA256 3bf15fcd8241b45e88b189f9b9cdb3145a76446159a29dea1c2cb3f8c0ca2548
MD5 8a91592fff92b4563493c9e5005f0d2d
BLAKE2b-256 e0e947201c1c66a2f7dd14ac3d27b127739d256e92e0d71019ffdd62a138adb6

See more details on using hashes here.

File details

Details for the file csv_to_anki_converter-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for csv_to_anki_converter-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a3c5d06b797aa9e28ec753d85b89c6796bb34504aa1a4b0156902ef59dae808d
MD5 30193f80af4680c680d2d218e9718272
BLAKE2b-256 ccde0a1fd9ffbbc9a079d20ce5535876e6cf53c01cf3963dd006f9bfc6f4b2e5

See more details on using hashes here.

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