0.0
The project is in a healthy, maintained state
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",
  note_type_name: "Basic",
  fields: { Front: "What is Ruby?", Back: "A programming language" },
  tags: ["programming"]
)

# Get note details
notes = client.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 } } }]

See the RubyDoc documentation for the complete API. More usage examples are available in the examples/ folder.

Development

bundle install
bundle exec rake

Integration tests require a running AnkiConnect instance and modify the active collection. Use a disposable profile.

bundle exec rake test:integration

Acknowledgments

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