# Generate Anki flashcards with Rust

Canonical page: https://ankiforge.dev/docs/quickstart/
Language: en
Description: Install the public Rust package, write a Spanish flashcard, and export a persistent APKG file.

Use Rust 1.92 or later. For another language, choose [Node / TypeScript or Python](https://ankiforge.dev/docs/languages/).

## Install

```sh
cargo new anki-deck
cd anki-deck
cargo add ankiforge@0.3.1
```

## Export your first deck

Save this complete program as `src/main.rs`:

```rust
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(())
}
```

```sh
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](https://ankiforge.dev/generated/spanish.apkg).

## Continue

Follow the [JSON to Anki recipe](https://ankiforge.dev/docs/json-to-anki/#rust) for a complete media and update task.

Add [images and audio](https://ankiforge.dev/docs/media/), [custom note types](https://ankiforge.dev/docs/custom-notetypes/), or [Image Occlusion](https://ankiforge.dev/docs/image-occlusion/). Keep the original distribution APKG before [comparing and publishing an update](https://ankiforge.dev/docs/updates/). Read the [Rust API](https://ankiforge.dev/docs/rust-api/) or [verified environments](https://ankiforge.dev/docs/compatibility/) for details.
