CLI

CLI to manage Trilium by exposing SDK functionality.

Configuration

The tool can be configured via any of the following, in order of precedence:

  • .yaml file

    • Supports multiple Trilium instances

  • Command-line options

  • Environment variables

  • .env file

.yaml file example

# mapping of instance names to info
instances:
  my-notes:
    # connection info, either "token" or "password" required
    host: "http://localhost:8080"
    token: "MY_TOKEN"
    password: "MY_PASSWORD"

    # optional fully-qualified class name of root note for tree push
    root_note_fqcn: "my_notes.root.RootNote"

    # optional data dir which overrides root_data_dir
    data_dir: "./trilium_data/my-notes"

# top-level data dir with subfolders per instance
root_data_dir:
  "./trilium_data"

Usage

trilium-alchemy

trilium-alchemy Usage: trilium-alchemy [OPTIONS] COMMAND [ARGS]... TriliumAlchemy CLI Toolkit                                                     ╭─ Options ────────────────────────────────────────────────────────────────────╮ *--hostTEXTTrilium host, e.g. http://localhost:8080       [env var: TRILIUM_HOST]                        [default: None]                                [required]                                     --tokenTEXTETAPI token                                    [env var: TRILIUM_TOKEN]                       [default: None]                                --passwordTEXTTrilium password                               [env var: TRILIUM_PASSWORD]                    [default: None]                                --instanceTEXTInstance name as configured in .yaml           [env var: TRILIUM_INSTANCE]                    [default: None]                                --config-fileFILE.yaml file containing instance info, only      applicable with --instance                     [env var: TRILIUM_ALCHEMY_CONFIG_FILE]         [default: trilium-alchemy.yaml]                --helpShow this message and exit.                    ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Commands ───────────────────────────────────────────────────────────────────╮ check Check Trilium connection                                             db    Database maintenance operations                                      tree  Operations on tree or subtree                                        ╰──────────────────────────────────────────────────────────────────────────────╯

check

check Usage: trilium-alchemy check [OPTIONS] Check Trilium connection                                                       ╭─ Options ────────────────────────────────────────────────────────────────────╮ --helpShow this message and exit.                                  ╰──────────────────────────────────────────────────────────────────────────────╯

db

db Usage: trilium-alchemy db [OPTIONS] COMMAND [ARGS]... Database maintenance operations                                                ╭─ Options ────────────────────────────────────────────────────────────────────╮ --data-dirDIRECTORYDirectory containing Trilium database, if not   specified in config file                        [env var: TRILIUM_DATA_DIR]                     [default: None]                                 --helpShow this message and exit.                     ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Commands ───────────────────────────────────────────────────────────────────╮ backup  Backup database, optionally copying to destination path            restore Restore database from file                                         ╰──────────────────────────────────────────────────────────────────────────────╯
backup
backup Usage: trilium-alchemy db backup [OPTIONS] Backup database, optionally copying to destination path                        ╭─ Options ────────────────────────────────────────────────────────────────────╮ --nameTEXTName of backup in Trilium data dir to generate,     e.g. 'now' will write 'backup-now.db'               [default: now]                                      --auto-nameWhether to use current datetime as name instead of  --name option                                       --verifyWhether to verify by ensuring backup's mtime is <   10 seconds ago (requires db --data-dir)             --destPATHOptional destination database file or folder to     copy backup; if folder, filename will use current   datetime (requires db --data-dir)                   [default: None]                                     --overwriteWhether to overwrite destination file if it already exists                                              --helpShow this message and exit.                         ╰──────────────────────────────────────────────────────────────────────────────╯
restore
restore Usage: trilium-alchemy db restore [OPTIONS] SRC Restore database from file                                                     ╭─ Arguments ──────────────────────────────────────────────────────────────────╮ *srcFILESource database file                                     [default: None]                                          [required]                                               ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Options ────────────────────────────────────────────────────────────────────╮ --dry-runDon't copy, only print source/destination paths         --yes-yDon't ask for confirmation before overwriting           document.db                                             --helpShow this message and exit.                             ╰──────────────────────────────────────────────────────────────────────────────╯

tree

tree Usage: trilium-alchemy tree [OPTIONS] COMMAND [ARGS]... Operations on tree or subtree                                                  ╭─ Options ────────────────────────────────────────────────────────────────────╮ --note-idTEXTNote id on which to perform operation                 [default: root]                                       --searchTEXTSearch string to identify note on which to perform    operation, e.g. '#myProjectRoot'                      [default: None]                                       --helpShow this message and exit.                           ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Commands ───────────────────────────────────────────────────────────────────╮ export Export subtree to .zip file                                         import Import subtree from .zip file                                       push   Push declarative note subtree to target note                        ╰──────────────────────────────────────────────────────────────────────────────╯
export
export Usage: trilium-alchemy tree export [OPTIONS] DEST Export subtree to .zip file                                                    ╭─ Arguments ──────────────────────────────────────────────────────────────────╮ *destFILEDestination .zip file                                   [default: None]                                         [required]                                              ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Options ────────────────────────────────────────────────────────────────────╮ --format[html|markdown]Export format                            [default: html]                          --overwriteWhether to overwrite destination file if it already exists                        --helpShow this message and exit.              ╰──────────────────────────────────────────────────────────────────────────────╯
import
import Usage: trilium-alchemy tree import [OPTIONS] SRC Import subtree from .zip file                                                  ╭─ Arguments ──────────────────────────────────────────────────────────────────╮ *srcFILESource .zip file                                         [default: None]                                          [required]                                               ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Options ────────────────────────────────────────────────────────────────────╮ --helpShow this message and exit.                                  ╰──────────────────────────────────────────────────────────────────────────────╯
push
push Usage: trilium-alchemy tree push [OPTIONS] [NOTE_FQCN] Push declarative note subtree to target note                                   ╭─ Arguments ──────────────────────────────────────────────────────────────────╮ note_fqcn[NOTE_FQCN]Fully-qualified class name of                  BaseDeclarativeNote subclass                   [default: None]                                ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Options ────────────────────────────────────────────────────────────────────╮ --dry-runOnly show pending changes                               --yes-yDon't ask for confirmation before committing changes    --helpShow this message and exit.                             ╰──────────────────────────────────────────────────────────────────────────────╯