Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Ankivalenz

Ankivalenz is a tool for generating Anki cards from Markdown files. Read my blog post for more information on the "Why" of Ankivalenz.

Tutorial

In this walk-through we will write our notes as Markdown files, and use Ankivalenz to generate an Anki deck with Anki cards extracted from our Markdown files.

Installation

Ankivalenz is distributed as a Python package, and requires Python 3.10+. To install:

$ pip3 install ankivalenz

Initialize project

Create a folder for your notes:

$ mkdir Notes
$ cd Notes

Ankivalenz needs a configuration file, containing the name and ID of the Anki deck. This can be generated with ankivalenz init:

$ ankivalenz init .

Write a note

Add the following to a file named Cell.md:

# Cell

## Types

- Prokaryotic ?:: does not contain a nucleus
- Eukaryotic ?:: contains a nucleus

Generate Anki deck

Run Ankivalenz:

$ ankivalenz run .

This generates a file Notes.apkg that can be imported to Anki. Open Anki and go to File -> Import, and find Notes.apkg.

Updating Anki deck

If you make changes to your notes, you can update the Anki deck by running ankivalenz run again. It is not possible to mark cards as deleted, so if you remove a note, the corresponding card will remain in the Anki deck. To work around this issue, all cards are tagged with a timestamp, and you can use the Anki browser to delete cards with an old timestamp. Running ankivalenz run will provide you with the filter needed to delete orphaned cards:

$ ankivalenz run .
- Added 3 notes to deck Biology in Biology.apkg
- Import the .apkg file into Anki (File -> Import)
- Find and delete orphaned notes with this filter (Browse):
    deck:Biology -tag:ankivalenz:updated:1666899823

Review

The new Anki deck will have two cards:

Question Answer Path
Prokaryotic does not contain a nucleus Cell > Types
Eukaryotic contains a nucleus Cell > Types

This is what the first note looks like in Anki:

Anki review

Syntax

Front/back cards

Ankivalenz supports front/back cards, where the front is the question and the back is the answer. To create a front/back card, add a new list item with the question, followed by ?:: and the answer:

- Color of the sun ?:: Yellow

You can flip the order of the question and answer by using ::? instead:

- Anwer ::? Question

Two-way cards

Two-way cards can be created with :::

- Side 1 :: Side 2

This will create two cards in Anki:

Front Back
Side 1 Side 2
Side 2 Side 1

Standalone questions/answers

Sometimes you want to create a note refering to the parent heading. This can be done with standalone questions/answers:

- Sun
  - ::? The star in our solar system

This will create a note with the answer "Sun" and the question "The star in our solar system". The other types of delimeters ("::" and "?::") can be used in the same way.

Cloze cards

Ankivalenz supports cloze deletion1, where the answer is hidden in the question. To create a cloze card, add a new list item with the question, using Anki's cloze syntax:

- The {{c1::sun}} is {{c2::yellow}}.

Nested lists

Lists can be nested:

- Solar System
  - Star ?:: Sun
  - Planet
    - Earth ?:: Blue
    - Mars ?:: Red

The headings for the nested lists become a part of the notes' paths:

Question Answer Path
Star Sun Solar System
Earth Blue Solar System > Planet
Mars Red Solar System > Planet

Math

Ankivalenz supports inline math:

- Inline math: $1 + 2$

Configuration

ankivalenz.json takes the following options:

Option Description
deck_name The name of the Anki deck.
deck_id The ID of the Anki deck.
input_path The path to the folder containing the Markdown files.
  1. https://docs.ankiweb.net/editing.html#cloze-deletion

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ankivalenz-1.0.0a3.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ankivalenz-1.0.0a3-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file ankivalenz-1.0.0a3.tar.gz.

File metadata

  • Download URL: ankivalenz-1.0.0a3.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.6 Darwin/24.0.0

File hashes

Hashes for ankivalenz-1.0.0a3.tar.gz
Algorithm Hash digest
SHA256 1d956ee0a33367d8a409e6da3e93a12ecf4bd119ee71225c5051ce9a83f46e63
MD5 350701f7f6fa883c57a4971ee140bad1
BLAKE2b-256 f77890107f9eef484ba8fd678c2ef79ff9bd5db047021d29f0eaf093ea741dbe

See more details on using hashes here.

File details

Details for the file ankivalenz-1.0.0a3-py3-none-any.whl.

File metadata

  • Download URL: ankivalenz-1.0.0a3-py3-none-any.whl
  • Upload date:
  • Size: 10.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.6 Darwin/24.0.0

File hashes

Hashes for ankivalenz-1.0.0a3-py3-none-any.whl
Algorithm Hash digest
SHA256 1f721f4c7b0fda861c3d896f4b5a721be72926285d1433e2aa7e9e583b009586
MD5 7a7e8a2fb0279bea0bfb3cf973c678d4
BLAKE2b-256 ad794b128c3259d070d7e6e2146a7f7871f3f21d2b89fd6813272e82dd726d21

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page