Generate Anki flashcards with Rust
Use Rust 1.92 or later. For another language, choose Node / TypeScript or Python.
Install
Section titled “Install”cargo new anki-deckcd anki-deckcargo add ankiforge@0.3.1Export your first deck
Section titled “Export your first deck”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(())
}cargo runThe 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.
Continue
Section titled “Continue”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.