Skip to content

pianobin/anki_reshuffle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

Anki Deck Reshuffler

Randomizes the order of new (unseen) cards in an Anki .apkg deck file.

How it works

Anki .apkg files are ZIP archives containing a SQLite database (collection.anki2 or collection.anki21). Each card has a due field that controls its position in the new-card queue. This script:

  1. Extracts the .apkg to a temporary directory
  2. Opens the SQLite collection database
  3. Finds every card with queue = 0 (new / unseen cards)
  4. Assigns them a freshly shuffled set of position numbers
  5. Repacks the archive

Only new cards are affected — cards already in review or relearning are left untouched.

Requirements

  • Python 3.10+
  • No third-party packages (uses only stdlib: sqlite3, zipfile, json, random)

Setup

# Clone the repo
git clone https://github.com/your-username/anki_reshuffle.git
cd anki_reshuffle

# Create and activate a virtual environment
python3 -m venv .venv
source .venv/bin/activate        # macOS / Linux
# .venv\Scripts\activate         # Windows

# To deactivate when done:
deactivate

Usage

# Reshuffle all new cards (overwrites input, saves a .bak backup)
python reshuffle.py MyDeck.apkg

# Write reshuffled deck to a new file
python reshuffle.py MyDeck.apkg MyDeck_reshuffled.apkg

# Reshuffle only a specific deck (sub-decks are included automatically)
python reshuffle.py MyDeck.apkg --deck "Japanese::Vocabulary"

# Reproducible shuffle with a fixed seed
python reshuffle.py MyDeck.apkg --seed 42

# List all deck names inside an .apkg
python reshuffle.py MyDeck.apkg --list-decks

Options

Flag Description
output Optional output path. Omit to overwrite the input (a .bak is created).
--deck DECK_NAME Limit reshuffling to one deck and its sub-decks.
--seed SEED Integer seed for a reproducible shuffle.
--list-decks Print all deck names in the .apkg and exit.

Workflow tip

Import the reshuffled deck into Anki via File > Import. If you reshuffled in place (no output argument), your original deck is preserved as MyDeck.apkg.bak.

About

Python script that shuffles the order of Anki decks

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages