Skip to content

Generate Anki flashcards with Rust

Use Rust 1.92 or later. For another language, choose Node / TypeScript or Python.

Terminal window
cargo new anki-deck
cd anki-deck
cargo add ankiforge@0.3.1

Save this complete program as src/main.rs:

use ankiforge::{BuildOptions, Note, Project};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut project = Project::new("spanish")?.default_deck("Spanish");
    project.add("es:hola", Note::basic("hola", "hello"))?;
    let output = project.build(BuildOptions::to("spanish.apkg"))?;
    println!("{}", output.artifact().path().display());
    Ok(())
}

Terminal window
cargo run

The program writes a persistent spanish.apkg. Open it in Anki, import it and study hola → hello in the Spanish deck. Exporting needs no Anki installation.

The namespace spanish and stable key es:hola identify this note through later content changes. You can also download the website’s Basic example.

Follow the JSON to Anki recipe for a complete media and update task.

Add images and audio, custom note types, or Image Occlusion. Keep the original distribution APKG before comparing and publishing an update. Read the Rust API or verified environments for details.

View Markdown