Starting out developing an add-on: Looking for resources, references, general advice

Hello

I’m new to working with the Anki codebase and developing add-ons. My aim with this post is to receive feedback / guidance from more experienced developers. The post will describe my goal, what I’ve done so far, the approach I’m pursuing as of right now and lastly a list of questions I’d like to have answered.

Goal:

I’m trying to create an add-on that allows me to cut down on the time required to create new cards. I’m learning Russian. I’ve attached a picture of a card for a noun below and added some additional information. My process is as follows:

  1. Get lemmatized version of the word
  2. Look the word up on Wiktionary
  3. Copy accent
  4. Choose definition(s) and / or translation(s) and copy / create them myself
  5. Go to the russian Wiktionary page and retrieve declension table to paste in
  6. Go to Yandex and copy a suitable image
  7. Copy the example sentence from my ebook-reader
  8. Use forvo-dl to automatically retrieve audio file and paste it into the field

This process is also done for verbs and adjectives, although there are some differences. In general however, many of these steps can be automated. I have found a suitable data-source (openrussian database) that has most of the information I require.

The idea is that I get the lemmatized word, paste it into the first field, then hit a shortcut and the add-on will automatically paste in the accented version of the word, the declension table (or inflection for verbs).

As extensions going forward, I’d like to be able to automatically change the card type depending on the type of word (verb, noun adjective etc.).

What I’ve done so far:

I have familiarized myself with PyQt and Python.

So far I’ve added a new button to the editor view, registered a new short-cut to call my method, added some menu items, read values from Editor view fields and displayed some information. Just been trying some stuff.

I have downloaded add-ons and used them as references to see how other add-ons do these things. While looking through the add-ons I have often found myself digging into the Anki source-code to understand what’s going on (and still struggling). Doing even simple things seem to be needlessly cumbersome (although this might just be because I don’t know what I’m doing).

My proposed approach going forward

So far my approach would be to focus mainly on the Editor view. I’d read the value from the first input field, then have my add-on retrieve all of the required information and paste it in the other fields based on some configuration. Then save from the Editor view.

My questions are:

  • Is my approach to read and write information to the Editor view (GUI) sensible?
  • Is it easier (or possible) to create Cards differently and save directly to the deck (or to the database)?
  • How does the split between Python / JS work in the Editor view?
  • Are there any good resources I can read into to get a better overall understanding of how to interface with Anki?
  • Are there any best practices for add-on development?
  • Are there any well written add-ons that I can use to learn and to reference?
1 Like

Is my approach to read and write information to the Editor view (GUI) sensible?

Yes, I think this is a common approach. I used it in all my dictionary add-ons so far.

Is it easier (or possible) to create Cards differently and save directly to the deck (or to the database)?

A common pattern is to also provide a browser menu item to process all selected notes in bulk.

How does the split between Python / JS work in the Editor view?

AFAIK, given what you’ve described, you don’t have to touch the JS side of the editor to accomplish what you want. Reading and writing to the editor fields can be done from Python.

Are there any good resources I can read into to get a better overall understanding of how to interface with Anki?

Besides the offical guide (which you’ve probably already read), I don’t think there are many step-by-step guides for add-on development.
You can follow the development threads here in the forums and ask questions when in doubt.
Other than that, your best bet is to dive into Anki’s codebase and other add-ons’ code.
For that, I recommend picking up a good code editor like VSCode and taking advantage of Anki’s packages on PyPi (See anki and aqt) for code completion and instant access to the source code.

Are there any best practices for add-on development?

The official guide has some dos and don’ts that can be regarded as “best practices”. Things like:

Are there any well written add-ons that I can use to learn and to reference?

  • Pretty much any add-on written by the most prolific add-on author Glutanimate. Checkout out his GitHub for examples: glutanimate (Aristotelis) · GitHub
  • I also recommend studying some of Soren Bjornstad’s add-ons: LPCG and TiddlyRemember.
    I’m most familiar with LPCG’s code as I maintain a fork of it. I learned a lot from it when I was just getting started two years ago and I adopted many practices from it (e.g. The add-on’s folder structure, writing build & test scripts, etc.)
    LPCG is one of the highest quality add-ons in my opinion. Everything from code, documentation, and testing is an excellent opportunity to learn from.
  • Take a look at some add-ons written by Anki’s author at ankitects/anki-addons. Most of them are short and simple enough to get started with. There also some demos under the demos folder that show how to do certain things.
  • More specific to your questions, you can check out popular dictionary add-ons like AutoDefine, Cambridge Dictionary, and CC-CEDICT, or some of my (less popular) add-ons like Wiktionary and TRDict.

If you’re willing to share the source code of your work on the add-on so far on GitHub, I’ll check it out!

3 Likes