Your first Anki deck
This guide runs the repository’s minimal Rust example. You need Git, Rust 1.92 or later, and Anki to review the result.
Run the example
Section titled “Run the example”git clone https://github.com/morehardy/anki-forge.gitcd anki-forgecargo run -q -p anki_forge --example target_api_basicThe first run compiles the project and its dependencies. It writes spanish.apkg in the repository root. The following source is taken directly from anki_forge/examples/target_api_basic.rs:
use anki_forge::prelude::*;
fn main() -> anyhow::Result<()> {
let mut deck = Deck::new("Spanish");
deck.basic()
.note("hola", "hello")
.stable_id("es:hola")
.add()?;
deck.write_apkg("spanish.apkg")?.ensure_success()?;
Ok(())
}Open the deck
Section titled “Open the deck”Open spanish.apkg with Anki, confirm the import, and open the Spanish deck. The card asks hola; reveal the answer to see hello.
You can also download the website’s Basic example to try the result before compiling.
Read the code
Section titled “Read the code”Deck::new("Spanish") creates a deck. The Basic builder adds a note with front and back fields. stable_id("es:hola") gives the note a name that can survive edits to its content.
write_apkg(...) returns a build report. Call ensure_success() to fail the program if the report contains errors. For a fuller diagnostic flow, read Projects and diagnostics.
Make it yours
Section titled “Make it yours”To use the library outside this checkout, follow Add to your application. The core concepts explain notes, cards and the choice between Deck and Project.
Add another note with a different stable ID, change the deck name, or try a Cloze example. For custom fields and media, use the project API and template bundles.
Before updating a deck that you have already distributed, keep a copy of the previous package. The update guide explains comparison builds and identity lockfiles.