Anki Forums

How to check anki version inside an addon?

Recently Anki is filled with deprecation warnings as:

1788670778\representation\'joinedFields' is deprecated: please use 'joined_fields'
1788670778\representation\'byName' is deprecated: please use 'by_name'
1788670778\representation\'getConf' is deprecated: please use 'get_config'

One way I have been fixing with was with:

join_fields = anki_object.joined_fields if hasattr(anki_object, 'joined_fields') else anki_object.joinedFields

However, I cannot use this for this other warning because there is nothing to check with hasattr:

CrowdAnki\representation\ is deprecated: no longer required

Is there an Anki version I can check as in this example:

if anki_major > 3 and anki_minor < 40:

You can use the version variable exported from anki.

from anki import version as anki_version

parts = anki_version.split(".")
major = int(parts[0])
minor = int(parts[1])
point_release = int(parts[2])

if point_release < 40:

There’s also a anki.utils.point_version() which does similar. If you can convince the add-on author to target only the newer version going forward, that makes things much easier - a new branch can be created that uses the PEP8 syntax, and users who have not upgraded yet can continue to use the previous release of the add-on.