Anki Release (Dependency Locker)
Anki-release is a Python meta-package designed to lock the dependencies required for the Anki desktop application's Python components, ensuring a consistent and compatible environment for developers building on the Anki backend. It does not provide direct user-facing API but facilitates the installation of the core `anki` and `aqt` libraries along with their many transitive dependencies. It follows Anki's rapid release cadence, with the current version being 25.9.2.
Warnings
- breaking Anki (and thus anki-release) is licensed under AGPL-3.0-or-later. Using Anki's backend in a closed-source application generally requires a specific exception from the developers or adherence to the AGPL's terms, which often means open-sourcing your derived work.
- gotcha The `anki-release` package provides the *backend* and GUI components for the desktop application, not the Anki desktop application installer itself. Running `pip install anki-release` will set up the Python environment but won't install the executable application. Users typically interact with the Anki desktop app downloaded from AnkiWeb.
- breaking Anki's internal architecture, especially how it handles the collection backend, has undergone significant changes (e.g., transition to Rust-based `rslib` wrapped by Python). These changes can affect direct interactions with the `anki` package, potentially breaking code relying on older internal structures.
- gotcha The version numbers for `anki-release` (e.g., 25.9.2) are directly tied to the Anki desktop application's release versions, not independent Python package versions. This means changes are frequent and often non-backward compatible without clear 'major' version breaks in the traditional Python sense.
- gotcha When importing or updating packaged decks (.apkg files) using the Anki backend, be aware that scheduling information might be included unintentionally. This can lead to unexpected review intervals or card states if not handled correctly.
Install
-
pip install anki-release
Imports
- Collection
from anki.collection import Collection
- mw
from aqt import mw
Quickstart
import os
from anki.collection import Collection
from anki.stdrepl import repl
# NOTE: For anki-release, the primary use case is to ensure backend dependencies.
# The actual Anki backend interaction is via the 'anki' package.
# Create a temporary Anki collection for demonstration
# In a real scenario, you'd likely open an existing collection.
COLLECTION_PATH = os.environ.get('ANKI_TEST_COLLECTION_PATH', 'temp_collection.anki2')
# Ensure the directory exists if not in the current working directory
collection_dir = os.path.dirname(COLLECTION_PATH)
if collection_dir and not os.path.exists(collection_dir):
os.makedirs(collection_dir)
# Open or create an Anki collection
col = Collection(COLLECTION_PATH)
print(f"Opened Anki collection at: {col.path}")
# Example: Get number of notes (0 for a new collection)
print(f"Number of notes: {col.note_count()}")
# Clean up the temporary collection if created new
# In a real application, you'd manage persistence carefully.
# col.close()
# if not os.environ.get('ANKI_TEST_COLLECTION_PATH'):
# os.remove(COLLECTION_PATH)
# Anki's internal Python environment might use a custom REPL for debugging
# For general scripting, standard Python interactions apply.
# You might interact with objects like col.models, col.decks, etc.