Tools for programmatically generating cards?

Hi. I wanna start creating decks for a class I am in. I am looking into tools which I can use to programmatically generate decks either as code or as configuration. I have looked through a few but I am not sure which one to commit to so I was hoping to get some input from people who have delved in this.

The two I found that look fine are these:

  1. genanki to define cards as Python code.
  2. anki-panky to define cards in Markdown.

My main concern is that the projects aren’t actively updated. For example, genanki last tagged release was more than a year ago even though the main branch received commits a couple months ago. There are other options like genanki-rs but that is even less active.

Now this isn’t inherently problematic since I don’t expect the projects to receive updates for no reason. But I wanted to check regardless.

Any advice is welcome. Thank you very much for reading.

1 Like

there’s a lot more duplicative efforts, but here’s the ones i have written down that still updates:

it should be okay to use tools built even older than you think. fundamentally the DB inside decks stay relatively unchanged, and Anki is able to import old decks anyways. (maybe not v2.0 era decks though? that’s like 7 years ago?)

2 Likes

I can’t believe it. I scoured GitHub for so long but those two GitHub repos never showed up. Thank you so much.

There is a simpler way, do not have to install any additional tools or plug-ins, directly with anki desktop comes with a debugging console (ctrl + shift + ;), paste the code to execute can be.
For example, the following code is to automatically add 1 ~ 9 multiplication example:

from anki.notes import Note
from anki.collection import AddNoteRequest
from aqt import mw, gui_hooks
import random

deck_id = mw.col.decks.by_name('Default')['id']
note_id = mw.col.models.by_name('Cloze')['id']

requests = []
for x in range(1, 10):
  for y in range(1, 10):
    z = x * y
    note = Note(mw.col, note_id)
    note['Text'] = f'{{{{c1::{x}}}}} X {{{{c2::{y}}}}} = {{{{c3::{z}}}}}'
    request = AddNoteRequest(note, deck_id)
    requests.append(request)

changes = mw.col.add_notes(requests)
gui_hooks.operation_did_execute(changes, None)

2 Likes

you may even be interested in just using the anki Python module outside of Anki https://addon-docs.ankiweb.net/the-anki-module.html. Though, i myself don’t know whether it would work for your needs.

2 Likes

Hey, I’m the anki-panky maintainer. If you end up using it and want some features let me know!!! I’d love to make the functionality better. I just need a reason to haha.

Also I suppose the one you go with will depend on your needs. My project excels at cards that utilise a lot of maths and code as it uses the Pandoc compiler underneath but out the box it excels at just regular front-back cards (more complicated cards would probably require some custom config hook or some bollocks to inject your own html maybe). Also it’s really good at nested decks as it just uses the file hierarchy as the deck structure. Cards also aren’t duplicated on import.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.