AnkiConnect Ruby
AnkiConnect provides a simple HTTP API to communicate with Anki. This Ruby gem is a wrapper around that API.
Installation
First, install the AnkiConnect addon in Anki:
- Open Anki
- Go to Tools → Add-ons (⇧⌘A on macOS)
- Click "Get Add-ons..."
- Enter the code
2055492159and click OK - Restart Anki
Anki must be kept running in the background for other applications to use AnkiConnect. You can verify that AnkiConnect is running by visiting localhost:8765 in your browser. If the server is running, you will see { "apiVersion": "AnkiConnect v.6" }.
Then add this line to your application's Gemfile:
gem 'anki_connect'Or install it yourself:
gem install anki_connectUsage
require 'anki_connect'
# Create a client (default: localhost:8765)
client = AnkiConnect::Client.new
# Get all decks
decks = client.deck_names
# Add a new note
note_id = client.add_note(
deck_name: "Default",
model_name: "Basic",
fields: { Front: "What is Ruby?", Back: "A programming language" },
tags: ["programming"]
)
# Get note details
notes = client.get_notes(query: "deck:Default")
# => [{ "noteId" => 1234567890,
# "modelName" => "Basic",
# "tags" => ["programming"],
# "fields" => { "Front" => { "value" => "What is Ruby?", "order" => 0 },
# "Back" => { "value" => "A programming language", "order" => 1 } } }]For a complete list of all API methods, see the RubyDoc documentation. More examples in the examples/ directory.
Development
# Install dependencies
bundle install
# Open console with gem loaded
bundle exec rake consoleAcknowledgments
- Anki-Connect by FooSoft for the excellent Anki plugin
- Anki for the amazing spaced repetition software