No description
  • Python 86.3%
  • Nix 9.4%
  • JavaScript 4.3%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-07-13 18:30:35 -05:00
nix fix: make CLI and Trilium button work outside the systemd unit 2026-07-13 11:37:25 -05:00
src/trilium_anki fix: friendly one-line errors for unreachable Anki/Trilium 2026-07-13 18:30:35 -05:00
tests feat: overridable card style, Back Extra field, robust math-in-cloze 2026-07-13 12:18:47 -05:00
trilium-scripts fix: make CLI and Trilium button work outside the systemd unit 2026-07-13 11:37:25 -05:00
.gitignore feat: add Nix flake package and NixOS module 2026-07-13 08:52:33 -05:00
.python-version feat: generate Anki cloze cards from Trilium notes via LLM 2026-07-13 08:26:31 -05:00
flake.lock feat: add Nix flake package and NixOS module 2026-07-13 08:52:33 -05:00
flake.nix feat: add Nix flake package and NixOS module 2026-07-13 08:52:33 -05:00
LICENSE feat: generate Anki cloze cards from Trilium notes via LLM 2026-07-13 08:26:31 -05:00
pyproject.toml refactor: replace trilium-py with minimal ETAPI client 2026-07-13 08:52:33 -05:00
README.md feat: overridable card style, Back Extra field, robust math-in-cloze 2026-07-13 12:18:47 -05:00
uv.lock refactor: replace trilium-py with minimal ETAPI client 2026-07-13 08:52:33 -05:00

trilium-anki

Generate Anki cloze flashcards from your Trilium Notes with an LLM — local (Ollama) or cloud (Anthropic, OpenAI, anything OpenAI-compatible).

Pick a note in Trilium, press a button (or run one command), and atomic cloze cards land in an Anki deck that mirrors your Trilium note hierarchy (Physics > Optics > Lenses → Physics::Optics::Lenses), tagged ai so you can review and prune them.

Prerequisites

  • Trilium with an ETAPI token: Options → ETAPI → Create new ETAPI token
  • Anki with the AnkiConnect add-on (code 2055492159), Anki running
  • An LLM endpoint: Ollama locally, or an Anthropic/OpenAI API key

Install

uvx trilium-anki --help        # run without installing
# or
pipx install trilium-anki

Configure

trilium-anki config init

Edit ~/.config/trilium-anki/config.toml:

[trilium]
url = "http://localhost:8080"
token = "your-etapi-token"

[llm]
# Ollama (local)
base_url = "http://localhost:11434/v1"
api_key = "ollama"
model = "gemma3:4b"

# Anthropic (OpenAI-compatible endpoint)
# base_url = "https://api.anthropic.com/v1/"
# api_key = "sk-ant-..."
# model = "claude-haiku-4-5"

Every value can also be set via TRILIUM_ANKI_* environment variables (e.g. TRILIUM_ANKI_LLM_API_KEY).

Custom card style

The prompt is split into style (what makes a good card — overridable) and a fixed output-format contract (so parsing keeps working). Prefer problem-solving cards over fact recall? Different atomicity? Set your own guidance:

[llm]
style = "You create flashcards focused on problem-solving strategies..."
# or
style_file = "~/.config/trilium-anki/style.txt"

Use

CLI

trilium-anki generate <noteId> --dry-run   # preview cards
trilium-anki generate <noteId>             # add them to Anki
trilium-anki generate <noteId> --force     # add more cards to an already-processed note

The noteId is shown in Trilium's note info dialog and in the URL hash.

Button inside Trilium

  1. Run trilium-anki serve (keep it running; e.g. a systemd user service).
  2. In Trilium, create a JS frontend note, paste trilium-scripts/create-flashcards.js, and add the label #run=frontendStartup.
  3. Reload Trilium — a Create flashcards button appears in the launcher bar.

How it works

  • Note content is fetched over Trilium's ETAPI; formulas (\( … \)) are preserved and render in Anki via MathJax.
  • The LLM returns structured JSON cloze cards, added to Anki as a TriliumCloze note type carrying the source noteId and a content hash — re-running on the same note never duplicates cards.
  • Cards are tagged ai and trilium-anki; prune the bad ones during normal review or in Anki's browser.

Roadmap

  • Canvas (Excalidraw) notes → image occlusion cards via vision models
  • Optional pre-import review UI
  • MCP server exposing the same pipeline

Development

uv sync
uv run pytest

License

MIT