- Python 86.3%
- Nix 9.4%
- JavaScript 4.3%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
|
|
||
| nix | ||
| src/trilium_anki | ||
| tests | ||
| trilium-scripts | ||
| .gitignore | ||
| .python-version | ||
| flake.lock | ||
| flake.nix | ||
| LICENSE | ||
| pyproject.toml | ||
| README.md | ||
| uv.lock | ||
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
- Run
trilium-anki serve(keep it running; e.g. a systemd user service). - In Trilium, create a JS frontend note, paste
trilium-scripts/create-flashcards.js, and add the label#run=frontendStartup. - 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
TriliumClozenote type carrying the source noteId and a content hash — re-running on the same note never duplicates cards. - Cards are tagged
aiandtrilium-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