0.0
No release in over 3 years
AnkiConnect provides a simple HTTP API to communicate with Anki. This Ruby gem is a wrapper around that API.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

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:

  1. Open Anki
  2. Go to Tools → Add-ons (⇧⌘A on macOS)
  3. Click "Get Add-ons..."
  4. Enter the code 2055492159 and click OK
  5. 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_connect

Usage

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 console

Acknowledgments

  • Anki-Connect by FooSoft for the excellent Anki plugin
  • Anki for the amazing spaced repetition software