anki-share

A website for sharing anki decks
Python
Flask
SQLite
Celery
HTML
CSS
JavaScript

About this project

I created anki-share because I was frustrated. I am a high school student, so I often make small Anki decks that I learn in a day or two. I was unable to share them with my friends that don't use Anki - they would have to install it, and for those using IOS, they would have to buy the app first. So I usually ended up inserting the cards to something like quizlet manually.

This project aims to provide a very simple way of sharing small Anki decks. You can simply upload a deck of Anki cards and send the URL to anyone. They can then view and study the deck on any device, without having to install anything or create any accounts.

You can see an example uploaded deck for yourself here. To read more about this project, please visit the website and read the readme file on github.

Key features

Future plans

I plan on continuing the development of anki-share. I want to add more social features for sharing the decks publicly (login system, likes, ...). I also want to focus on adding support for more anki features (schleduled card review, cards with more than 2 fields, ...).

Technical details

In this section I aim to provide some information on how to process .apkg anki decks in python. The information I found on this topic was scarse and often inaccurate or outdated.

.apkg versions

Afaik the .apkg files come in 2 different versions. All of them are a zip file containing an sqlite database alongside of media files.

Older versions

Older versions of anki use a simple approach described above. There is an sqlite database (either collection.anki2 or collection.anki21, depending on the version). Then there is a file called media. It is a json file mapping the original filenames or media attachments to their new names. The new names are just numbers starting at 0.

Newer versions

In newer versions of Anki, things are a lot more complicated. The files are compressed and some of them are encoded using media buffers.

The cards are now stored in a file called collection.anki21b. It is a sqlite database with the same structure as collection.anki21 in older versions, but it is compressed using zstd. It can be decompressed using (for example) pyzstd and then read the same way as collection.anki21.

The media file in newer versions is not json, but it is serialized using protocol buffers. Deserializing it is not so easy. You have to obtain the .proto files from anki's github. A lot of articles say that you only need the import_export.proto file form there, but you actually need all of them. You then need to generate files for your programming languages (python in my case) using protoc. Then you can finally import the files into your project and use them to read the contents of media file.

The files of the media themselves (called 0, 1, 2 etc. in the apkg file) are compressed using zstd and can be decompressed in the same way as collection.anki21b.