Skip to content
forked from lervag/apy

CLI script for interacting with local Anki collection

License

Notifications You must be signed in to change notification settings

denismaciel/apy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

apy

Anki is a flash card program which makes remembering things easy. apy is a Python script for easily adding cards to Anki.

Important:

  • This is currently WORK IN PROGRESS, and there may still be some major changes.
  • The current version should be compatible with Anki 2.1.26.
  • This script and its author(s) are not affiliated/associated with the main Anki project in any way.
  • Use this software entirely at your own risk. Frequent backups are encouraged.
Version Version note
HEAD Development branch
0.5.1 Started using patch releases
0.5 Minor improvements
0.4 Minor improvements
0.3 Compatible with Anki 2.1.26
0.2 Compatible with Anki 2.1.23
0.1 Compatible with Anki 2.1.13

Table of Contents

Install instructions

To install apy, you can do something like this:

# Install latest version
pip install --user git+https://github.com/lervag/apy.git#egg=apy

# One can also do
git clone https://github.com/lervag/apy.git
pip install -e .

Important: apy uses the python API from the Anki desktop app. So please make sure to install the Anki source. Note that the releases on Ankiweb only include precompiled binaries. Ankiweb recommends that one uses these precompiled binaries, but for apy to work one needs the Anki source to be available. These are typically included if one installs from repositories (e.g. with sudo apt install anki or pacman -S anki). One may also download the source either from the "Development" tab on Ankiweb or from github.

apy assumes that the Anki source is available at /usr/share/anki. If you put it somewhere else, then you must set the environment variable APY_ANKI_PATH, e.g. export APY_ANKI_PATH=/my/path/to/anki.

Usage

apy --help

Configuration

apy loads configuration from ~/.config/apy/apy.json. The following keys are currently recognized:

  • pngCommands/svgCommands: Set LaTeX commands to generate PNG/SVG files. This is inspired by the Edit LaTeX build process addon to Anki.
  • base: Specify where apy should look for your Anki database. This is usually something like /home/your_name/.local/share/Anki2/

An example configuration:

{
  "base": "/home/your_name/.local/share/Anki2/",
  "pngCommands": [
    ["latex", "-interaction=nonstopmode", "tmp.tex"],
    ["dvipng", "-D", "150", "-T", "tight", "-bg", "Transparent",
      "tmp.dvi", "-o", "tmp.png"]
  ],
  "svgCommands": [
    ["lualatex", "-interaction=nonstopmode", "tmp.tex"],
    ["pdfcrop", "tmp.pdf", "tmp.pdf"],
    ["pdf2svg", "tmp.pdf", "tmp.svg"]
  ]
}

Zsh completion

There is also a zsh completion file available. To use it, one may symlink or copy it to a location that is already in ones fpath variable, or one may add the apy/completion directory to the fpath list.

As an example, one may first symlink the _apy file:

mkdir -p ~/.local/zsh-functions
ln -s /path/to/apy/completion/_apy ~/.local/zsh-functions

Then add the following line to ones .zshrc file:

fpath=($HOME/.local/zsh-functions $fpath)

Relevant resources

Here are a list of relevant resources for learning how to work with the Anki databases and code:

Alternatives

Here are some alternatives to apy from which I've drawn inspiration. I've also added a short note on why I did not just settle for the alternative.

Ankiconnect

Ankiconnect is an Anki plugin 2055492159) hosted on github.

Ankiconnect enables external applications to communicate with Anki over a network interface. The exposed API makes it possible to execute queries against the user’s card deck, automatically create new vocabulary and Kanji flash cards, and more.

A couple of relevant applications that use Ankiconnect:

  • Anki Quick Adder: A Chrome extension to add words to Anki desktop quickly.

  • Anki-editor is an emacs plugin for making Anki cards with Org.

  • anki-cli is a simple nodejs based command-line interface for Anki.

The Dealbreaker: I wanted a script that does not require Anki to be running.

Anki::Import - Anki note generation made easy

Anki::Import (see also here) allows one to "Efficiently generate Anki notes with your text editor for easy import into Anki". Quote:

Inputting notes into Anki can be a tedious chore. Anki::Import lets you you generate Anki notes with your favorite text editor (e.g. vim, BBEdit, Atom, etc.) so you can enter formatted notes into Anki's database more efficiently.

The Dealbreaker: This sounds very good, except there are too many steps. I didn't want to have to open Anki desktop. It should work flawlessly directly from the terminal.

AnkiVim

AnkiVim may be used to "Use vim to rapidly write textfiles immediately importable into anki(1)."

The Dealbreaker: Similar to Anki::Import: I didn't want to have to open Anki desktop. It should work flawlessly directly from the terminal.

Knowledge (Vim plugin)

Knowledge is a Vim plugin for generating flash cards to either Anki or Mnemosyne.

The Dealbreaker: It has a single, open issue, which seems to indicate that the application does not work very well and/or is not well maintained.

Ankisync

Ankisync seems somewhat promising, in that it exposes an API for working with Anki collections from Python. It is a successor to AnkiTools, which is stated to be "an Anki *.apkg and collection.anki2 reader and editor".

The Dealbreaker: It does not include any features to add or edit notes (as far as I could tell).

Genanki

Genanki is a library for generating Anki decks.

The Dealbreaker: It is quite close to being something I wanted, except that it needs to run as a plugin to Anki desktop to generate notes to a local collection. It does not seem to allow editing/adding to a local collection outside of Anki desktop.

About

CLI script for interacting with local Anki collection

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 99.7%
  • Dockerfile 0.3%