Introduction
Spaced repetition is the gold standard for medical memorization, and Anki is the king of spaced repetition apps. However, the bottleneck is often creating the cards. Manually typing “Front” and “Back” for hundreds of drug interactions or anatomical landmarks is inefficient.
If you have your notes in a spreadsheet or a text file, you can automate this entire process using Python. You don’t need to be a coder to use this script—just copy, paste, and run.
The Tool: Genanki
We will use a Python library called genanki.[1][2][3][4][5] It is designed specifically to generate .apkg files (Anki packages) that you can double-click to import directly into your desktop app.
Prerequisites
- Install Python on your computer.
- Open your terminal/command prompt and run:Â pip install genanki pandas
The Script
Create a file named create_deck.py and paste the following code. This script assumes you have a CSV file named notes.csv with two columns: “Question” and “Answer”.codePython
import genanki
import pandas as pd
import random
# 1. Load your notes
data = pd.read_csv('notes.csv')
# 2. Create a unique Model (The Card Layout)
my_model = genanki.Model(
1607392319,
'Simple Medical Model',
fields=[
{'name': 'Question'},
{'name': 'Answer'},
],
templates=[
{
'name': 'Card 1',
'qfmt': '{{Question}}',
'afmt': '{{FrontSide}}<hr id="answer">{{Answer}}',
},
])
# 3. Create the Deck
my_deck = genanki.Deck(
2059400110,
'Pathology Week 1')
# 4. Loop through CSV and add cards
for index, row in data.iterrows():
note = genanki.Note(
model=my_model,
fields=[str(row['Question']), str(row['Answer'])]
)
my_deck.add_note(note)
# 5. Export
genanki.Package(my_deck).write_to_file('pathology_output.apkg')
print("Deck created successfully!")
How It Works
- The Model:Â This defines how your card looks. We used a basic “Front/Back” style, but you can add CSS to style it (e.g., making the font larger or adding a hospital logo).
- The Deck: The genanki.Deck function creates the container for your cards. The random numbers (like 2059400110) are unique IDs—you can change them to any random number if you create multiple decks.
- The Loop:Â The script reads your Excel/CSV row by row, creating a card for every line.
Why Automate?
This workflow allows you to take notes during a lecture directly into a spreadsheet (Question in column A, Answer in column B). By the time the lecture ends, you run the script, and your study material is ready. This shifts your time investment from formatting to learning.
