This project automates the creation of Anki cards for Swedish words using freely available tools:
git clone https://gitlab.com/rezaT/anki-ai-swedish.git
cd anki-ai-swedishpip install huggingface_hub requests wgetpip install huggingface_hubhuggingface-cli loginThis will prompt you to paste your Hugging Face token. You can create one for free here (select "Read" access when creating the token, huggingface-cli command will save the token to ~/.cache/huggingface/token).
Download and install Anki if you haven't already, from https://apps.ankiweb.net/.
- Open Anki.
- Go to
Tools→Add-ons→Get Add-ons. - Paste the following code:
2055492159 - Click "OK" and restart Anki.
Ensure Anki is running, then test the connection:
curl localhost:8765Example output:
{"apiVersion": "AnkiConnect v.6"}We use a customized card, run the setup script to add it to Anki:
python setup_anki_card_type.pyThe custom card has:
- Fields: Front, Back, Extra (toggles to show sentences, context, etc.), Audio, Video
Important: Anki needs to be running for the card to be added.
The workflow is:
- Input a Swedish word.
- Fetch JSON response from the KTH Lexin API.
- Strip/clean relevant content (definitions, examples, grammar).
- Use DeepSeek V3 via Hugging Face Inference API to summarize the content into a formatted Anki card.
- Send the card to Anki via AnkiConnect.
Run the script:
python main.py <swedish_word>To make the script accessible from anywhere, create a symbolic link under /usr/bin:
sudo ln -s <path_to_main.py> /usr/bin/anki-add && sudo chmod +x /usr/bin/anki-addNow you can run the script using:
anki-add <swedish_word> <extra context>Extra context is optional, it can be e.g. a sentence to include in the flashcard.
anki-add programmerare<Front>programmer</Front>
<Back>programmerare</Back>
<Extra>
(en programmerare, programmeraren, programmerare, programmerarna)
Person som programmerar
<i>He works as a programmer at a tech company.</i>
Han jobbar som programmerare på ett teknikföretag.
</Extra>The script supports three modes depending on the input:
-
Word only:
anki-add <word>
Creates a flashcard from the Lexin dictionary definition. -
Word + context:
anki-add <word> "<sentence or context>"
Creates a flashcard from Lexin and includes your provided sentence/context. -
Context only:
anki-add "" "<sentence or context>"
Creates a flashcard directly from your sentence without dictionary lookup.
This project is licensed under the LGPL 3 License. Please observe the license for the acknowledged sources: