anki-cli is a Linux-focused command-line tool for working with existing Anki collections, built on top of Anki’s official Python library.
It supports two core operations:
add: add one note to an existing decksync: sync an existing collection to AnkiWeb (media sync enabled by default)
This project uses uv for dependency management.
-
Install dependencies:
uv sync
-
Editable installs as a tool with
uv:uv tool install -e ./
You can operate on an Anki collection in one of two ways:
- Profile mode (recommended): pass
--profile NAME(optionally--anki-dir PATH). - Collection path mode: pass
--collection PATHpointing atcollection.anki2(or a profile folder).
Notes:
--profileand--collectionare mutually exclusive.- If neither is provided, the CLI attempts to find a default profile; if it can’t, it will ask you to pass
--profile.
Adds exactly one note per invocation. The target deck must already exist.
- Command:
anki-cli add --deck "Deck Name" [--notetype "Basic"] -- <field1_html> <field2_html> ...
Examples:
- Add a Basic note:
anki-cli --profile "User 1" add --deck "Default" -- "Front" "Back"
Syncs the collection to AnkiWeb.
- Media sync is enabled by default; disable it with
--no-media.
Examples:
-
Sync in profile mode (prompts for credentials if needed and may persist an auth key to Anki prefs):
anki-cli --profile "User 1" sync
-
Sync by collection path (requires credentials each run; does not persist them):
anki-cli --collection /path/to/collection.anki2 sync --username you@example.com --password "..."