Command-line interface for Anki via AnkiConnect
Project description
Anki CLI
Features
- Complete API Coverage - 60+ commands covering all AnkiConnect operations
- AI Agent Ready - SKILL.md for discoverable capabilities
- CLI-Anything Compatible - Follows agent-harness pattern
- Batch Operations - Add multiple cards, bulk tag management
- Search & Filter - Full Anki search syntax support
- Review Automation - Control review sessions programmatically
Prerequisites
- Install Anki: https://apps.ankiweb.net/
- Install AnkiConnect plugin: https://ankiweb.net/shared/info/2055492159
- Python 3.8+
Installation
cd anki-cli
pip install -e .
# Verify installation
anki-cli --help
anki-cli version
Quick Start
# List all decks
anki-cli deck-list
# Add a flashcard
anki-cli add-note -d "English" -m Basic -t vocabulary Front:Hello Back:你好
# Search for cards
anki-cli find-notes "deck:English"
# Start reviewing
anki-cli gui-review "English"
Command Reference
System Commands
anki-cli version # Get AnkiConnect version
anki-cli sync # Sync with AnkiWeb
anki-cli profiles # List profiles
anki-cli check-database # Check database
Deck Management
anki-cli deck-list # List decks
anki-cli deck-stats "Deck Name" # Deck statistics
anki-cli create-deck "New Deck" # Create deck
anki-cli delete-deck "Old Deck" # Delete deck
Note Operations
anki-cli add-note -d DECK -m MODEL -t TAGS Field:Value ...
anki-cli notes-info NOTE_ID [NOTE_ID ...]
anki-cli update-note NOTE_ID Field:NewValue
anki-cli delete-notes NOTE_ID [NOTE_ID ...]
Tag Management
anki-cli add-tags NOTE_IDS... TAGS
anki-cli remove-tags NOTE_IDS... TAGS
anki-cli replace-tags NOTE_IDS... OLD_TAG NEW_TAG
anki-cli clear-tags # Remove unused tags
Card State
anki-cli suspend NOTE_IDS... # Suspend from reviews
anki-cli unsuspend NOTE_IDS... # Resume reviews
anki-cli are-suspended NOTE_IDS... # Check status
anki-cli are-due CARD_IDS... # Check if due
anki-cli forget CARD_IDS... # Reset to new
anki-cli set-due-date CARD_IDS... DAYS # Reschedule
Search (Full Anki syntax supported)
anki-cli find-notes "deck:English is:due"
anki-cli find-cards "tag:vocabulary prop:interval>7"
anki-cli find-notes "rated:7 -is:suspended"
GUI Operations
anki-cli gui-add # Open Add dialog
anki-cli gui-edit NOTE_ID # Open Edit dialog
anki-cli gui-current # Get current card
anki-cli gui-browser "query" # Open browser
anki-cli gui-review "Deck Name" # Start review
anki-cli gui-exit # Close Anki
Statistics
anki-cli today-stats # Cards reviewed today
anki-cli reviews-by-day # History by day
anki-cli collection-stats # Full stats HTML
Anki Search Syntax
| Syntax | Description |
|---|---|
deck:Name |
Cards in deck |
tag:Name |
Cards with tag |
is:new |
New cards |
is:due |
Due cards |
is:suspended |
Suspended cards |
prop:due<=7 |
Due within 7 days |
prop:interval>30 |
Interval > 30 days |
added:7 |
Added in last 7 days |
rated:1 |
Reviewed today |
front:text |
Search front field |
Combine with AND (space), OR (or), - (negate), () (group).
Examples
Create vocabulary cards
anki-cli add-note -d "French" -m Basic \
Front:"Bonjour" Back:"Hello" -t lesson1
Batch import from file
# notes.txt (tab-separated):
# Bonjour Hello
# Merci Thank you
# Au revoir Goodbye
anki-cli add-notes -d "French" -m Basic -t lesson1 notes.txt
Suspend old cards
# Suspend cards not reviewed in 90 days
anki-cli suspend $(anki-cli find-cards "rated:90 -prop:due<=90")
Review workflow
# Check what's due
anki-cli find-notes "deck:Biology is:due"
# Start review
anki-cli gui-review "Biology"
# During review, answer cards
anki-cli answer $CARD_ID 3 # 3 = Good
AI Agent Usage
This CLI is designed for AI agent integration:
- Discoverable: Run
anki-cli --helpor read SKILL.md - Structured output: All commands return parseable text
- Error handling: Clear error messages on stderr
- Batch operations: Efficient bulk actions
Example Agent Workflow
# Pseudocode for AI agent
def create_study_session(topic):
# 1. Check if deck exists
decks = run("anki-cli deck-list")
if topic not in decks:
run(f"anki-cli create-deck {topic}")
# 2. Generate cards from content
cards = generate_flashcards(topic) # AI generates
for front, back in cards:
run(f"anki-cli add-note -d {topic} Front:{front} Back:{back}")
# 3. Start review
run(f"anki-cli gui-review {topic}")
Troubleshooting
"Cannot connect to AnkiConnect"
- Make sure Anki is running
- Verify AnkiConnect plugin is installed (Tools > Add-ons)
- Check AnkiConnect is configured for port 8765
"Deck not found"
- Deck names are case-sensitive
- Use quotes for names with spaces:
"My Deck"
"Note/Model not found"
- List existing:
anki-cli model-list - Default model is "Basic"
Advanced: Multi-Action Requests
For efficiency, execute multiple actions in one request:
# actions.txt (one JSON per line):
{"action":"createDeck","params":{"deck":"NewDeck"}}
{"action":"addNote","params":{"note":{"deckName":"NewDeck",...}}}
anki-cli multi actions.txt
Resources
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
ankicli_tool-0.1.0.tar.gz
(12.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ankicli_tool-0.1.0.tar.gz.
File metadata
- Download URL: ankicli_tool-0.1.0.tar.gz
- Upload date:
- Size: 12.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0cdf1c4e33816611eb6a49ea553c979900ccb0196984bf0a438602d46639e247
|
|
| MD5 |
2fe542e9fac6717fd7376132b7b89925
|
|
| BLAKE2b-256 |
b34d8645a779a56776676632abc4cf6ff950f49afea520c19a971b15f20cd2a7
|
File details
Details for the file ankicli_tool-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ankicli_tool-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a06af74534152cabedfc3d53affac78e78f575515ec769e23f3cf4676b0b535
|
|
| MD5 |
703897a30aff380b7b899c035bbc14fb
|
|
| BLAKE2b-256 |
5c635977e9f939a66a6f45fbd665f0d22048f3c1d614208472e63e16871f2660
|