Anki Deck Generator

I wrote some starter code to generate a CSV file that can be imported directly into Anki to create a deck based on the notebook that’s being created in out study group.

This code through the notebook and for every Level 3 header or below attempts to create a new card. The card front will be the code examples contained in the section. The card back will be the header of the section saying what the symbol is, and all the code output/answers. The goal is to remember both the symbol names AND what they do. For example one card looks like this:

Card Front:
Screen Shot 2022-07-07 at 9.53.56 PM

Card Back:
Screen Shot 2022-07-07 at 9.54.06 PM

Things that could be improved/done differently:

  • Maybe this could be run through CI as something to be kept up to date and available as part of the apl-study repo
  • Handle the exception when there is no code output. Probably several other code improvements could be made by studying nbprocess and seeing how they deal with notebooks.
  • Could consider creating a separate card for each code example, instead of 1 card for each section.
  • Could try to optimize formatting to make cards more aesthetically pleasing
  • There is another import format that’s not csv. Is that feasible to use and more flexible?
  • Could try writing it in APL :smiley:

If I end up using Anki a bunch I will put more time into it, but for now it’s good enough for me. I want to try using Anki for a while so I have a better idea of what would be helpful before I do too much and this gets me started. If anyone improves on this please share here for everyone to benefit!

import json
import pandas as pd

nb = json.load(open('APL.ipynb'))
front = ''
back = ''
cards = []
for cell in nb['cells']:
    if (cell['cell_type'] == 'markdown') and ('###' in ''.join(cell['source'])):
        if front != '': cards.append(pd.DataFrame([[front,back]]))
        back = '<br/>'.join(cell['source']) + '<br/>'
        front = ''
    elif cell['cell_type'] == 'code':
        front = front + '<br/>'.join(cell['source']) + '<br/>'
            back = back + '<br/>'.join(cell['outputs'][0]['data']['text/html']) + '<br/>'

Nice one!

A suggestion: Piotr Wozniak recommends the each card has a minimal single question. So that would suggest each card should just have a single input/output pair, rather than all of them.

(I can see some benefits of doing them all at once for a function in a single card too though – just passing along this thought in case it’s helpful.)


That’s good to know - I will make that change later today and update the code above. The other thing I was considering is which direction to go for glyph names. (ie Remember english name from glyph vs remember glyph from english name).

Maybe I should have a card for both? I need to read up on this!

Also: I am thinking I will maintain a copy of the APL notebook that has a couple of additions that will let me generate a couple more cards automatically:

  1. Includes key shortcut
  2. Includes a plain english simple as possible description of what it is.

Is this something that you would want added to the notebook your are creating, or should I do that separately?


New, and greatly improved version!


Import the csv decks from this repo: GitHub - Isaac-Flath/anki

Card Types

  • Markdown Cards: L3/4/5 Headers that have a symbol in backticks
    • Symbol → Name: Given symbol in backticks (front), predict description of symbol (back)
    • Name → Symbol: Given description of symbol (front), predict symbol (back)
  • Code Cards: Code cells with both code and output present
    • Given code (front) predict output (back)


Symbol → Name:

Screen Shot 2022-07-08 at 11.45.15 AM

Name → Symbol:

Screen Shot 2022-07-08 at 11.45.25 AM

Code → Output:

Screen Shot 2022-07-08 at 12.12.05 PM

Current Code

Here’s the repo with current code: GitHub - Isaac-Flath/anki


There are a few drawbacks in that the code cell generates the card so code cells must be self contained. If a variable that is used is defined in previous cells, the card will not show that variable :frowning: Not sure about how to fix this in a clean way other than writing the notebook with that in mind.

Possible Nbprocess Extension

I also think it would be cool for this to be an nbprocess extension for courses/educational blogs/books (either as part of nbprocess or as a seperate extension) that I might toy with (though I might not, so if inspiration hits anyone go for it). The idea would be this:

  1. Have an Anki flag that turns any code cell into an Anki card (code = front, output = back).
  2. Each notebook (article/chapter/post/w.e) has the example code, problems, or homework flagged with the Anki Flag
  3. Anki importable csv file is automatically built from the notebooks via the flag

@Ezno , I imported the deck.
Tried to Study it and got:

**Congratulations! You have finished this deck for now.**
If you wish to study outside of the regular schedule, you can use the <U+2068>custom study<U+2069> feature.'

Tried then to generate the .csv, same result…

Any suggestions?

@gsg Hmm I am unable to recreate that issue.

I have noticed that the import immediately says “successful”, but it does take about 30 seconds to complete AFTER it says the import is complete. Can you try again and wait a minute before going into study?

Can you click into view the deck - do you see the cards there?

Thank you so much for creating this tool @Ezno , I was able to generate and load the file into my local Anki app, but on macOS, it seems there are spaces between the bounding box characters? Could this be a problem with the font I’m using on the MacOS ?

Screen Shot 2022-07-08 at 2.36.01 PM

I’m not sure what you mean - What is different between this and what you see in jupyter?

The font used is SAX2. You could try downloading the font on your computer and then installing it (I think on mac you can just double click it) to get the font used on our apl-study website to see if that improves things.

I solved the problem. It was importing then under the wrong “Type”.
Anki just used the “last” Type used.
I changed it to “Basic” and it imported them…


1 Like

I think the issue might be all those <br/>

(1 2)(3 4)<br/>,"<span style=""white-space:pre; font-family: monospace"">┌→────────────┐
<br/>│ ┌→──┐ ┌→──┐ │
<br/>│ │1 2│ │3 4│ │
<br/>│ └~──┘ └~──┘ │

That extra space shows up when the <br/> gets interpreted by the Anki app.

1 Like

Ah - I see what you mean! I am pushing a fix now.

1 Like

Thank you @Ezno ! it is fixed and also, I cannot thank you enough for creating this, it will go a long way in terms of helping n00bz like me :slight_smile:


No problem! I made it for myself first and foremost, and I am glad it’s useful to others as well.

Keep in mind that some of the cards will be broken due to the limitation I mentioned above. Any code cell that is not self contained won’t make sense (ie variable assigned in one cell and test in another).

If enough people find it useful maybe we can come up with a way to address that.


Let’s change the NB cells next time we have a study group to fix that. Feel free to remind me if I forget.

1 Like

Would you prefer a PR for it? I am happy to move/copy the few variable assignments that need it prior to our next study group.

1 Like

That would be great :slight_smile: . (M merges cells in Jupyter FYI)


Alright all - I went much further down this rabbit hole than intended…

I just pushed another anki deck as an experiment. This deck is a complete “vocabulary” deck. While the previous deck builds from a jupyter notebook and has great code examples, this one is vocabulary and glyph recognition scraped direct from the dyalog documentation pages. Links are the bottom of this post.

This deck:

  • Should contains all Glyphs (Scrapes the APL documentation website for it)
  • Cards have every combination I could think of going between various names, symbol, and documentation.
  • Contains hyperlink on the back of cards to relevent doc pages


There are a lot of different type of cards, but here’s a few examples. Possibly too many cards, so I may modify this over time as I use the app and see what I need. Feel free to take the code and run it yourself and comment out any cards.append line you don’t want!

What’s the Glyph from dyadic name?

Screen Shot 2022-07-09 at 12.56.35 AM

What’s the glyph from monadic name?

Screen Shot 2022-07-09 at 12.55.44 AM

Hyperlinks in the app!

Screen Shot 2022-07-09 at 12.55.59 AM

Describe what the Glyph Does

Links to stuff

All decks are in this repo: GitHub - Isaac-Flath/anki


Wow this is amazing! coincidentally, I was creating physical flashcards last night just for the glyphs as I feel like it’s something I need to get a handle on, so this will be immensely helpful to me! Thanks so much!

1 Like

I’m just going through these and while I’m at it, I should report some things that I see. I noticed that some of the entries appear twice? I’m not sure why this might be but if I do:

grep ^⌺ apl-docs-anki.csv


grep ^⍤ apl-docs-anki.csv

I see two instances of it . I won’t copy the output but it’s easy to see.

Found the bug. I’ve pushed a fix. I made a clearer name for it to. Also added tags for each question.

Link to Repo with all decks: GitHub - Isaac-Flath/anki