Skip to content

Build your personal knowledge base with Trilium Notes

feat(import): add Google Keep (Takeout) importer

Elian Dorana8d7552eb0f8
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index c834369e36..a3b5476bc6 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -257,6 +257,13 @@
"choose_file": "Notion export (.zip)",
"import": "Import"
},
+ "keep_import": {
+ "name": "Google Keep",
+ "description": "Import notes from a Google Keep export (.zip).",
+ "description_long": "In Google Takeout, export your Keep data as a .zip, then choose the resulting file here.",
+ "choose_file": "Google Keep export (.zip)",
+ "import": "Import"
+ },
"evernote_import": {
"name": "Evernote",
"description": "Import notes from an Evernote export (.enex).",
diff --git a/apps/client/src/widgets/dialogs/import_providers/index.ts b/apps/client/src/widgets/dialogs/import_providers/index.ts
index 24b89aeabe..a471c540be 100644
--- a/apps/client/src/widgets/dialogs/import_providers/index.ts
+++ b/apps/client/src/widgets/dialogs/import_providers/index.ts
@@ -1,4 +1,5 @@
import evernoteProvider from "./evernote.js";
+import keepProvider from "./keep.js";
import notionProvider from "./notion.js";
import oneNoteProvider from "./onenote.js";
import type { ImportProvider } from "./types.js";
@@ -7,6 +8,6 @@ import type { ImportProvider } from "./types.js";
* Registry of available import providers. Append new providers here; the generic import dialog
* renders the picker and each provider's panel automatically.
*/
-export const importProviders: ImportProvider[] = [oneNoteProvider, notionProvider, evernoteProvider];
+export const importProviders: ImportProvider[] = [oneNoteProvider, notionProvider, keepProvider, evernoteProvider];
export type { ImportProvider, ImportProviderPanelProps } from "./types.js";
diff --git a/apps/client/src/widgets/dialogs/import_providers/keep.tsx b/apps/client/src/widgets/dialogs/import_providers/keep.tsx
new file mode 100644
index 0000000000..c223ffe6bc
--- /dev/null
+++ b/apps/client/src/widgets/dialogs/import_providers/keep.tsx
@@ -0,0 +1,66 @@
+import { useCallback, useEffect, useRef, useState } from "preact/hooks";
+
+import { t } from "../../../services/i18n.js";
+import importService from "../../../services/import.js";
+import Button from "../../react/Button.js";
+import FormFileUpload from "../../react/FormFileUpload.js";
+import FormGroup from "../../react/FormGroup.js";
+import type { ImportProvider, ImportProviderPanelProps } from "./types.js";
+
+function KeepPanel({ parentNoteId, closeDialog, setFooter }: ImportProviderPanelProps) {
+ const [file, setFile] = useState<File | null>(null);
+
+ const onChange = useCallback((files: FileList | null) => setFile(files?.[0] ?? null), []);
+
+ const doImport = useCallback(async () => {
+ if (!file) {
+ return;
+ }
+
+ // Close immediately and let the shared import toasts (registered in import.ts) report progress,
+ // completion and any error. `format: "keep"` routes the upload to the Google Keep importer on the
+ // shared file-import endpoint, overriding the .zip extension's default (the generic zip importer).
+ // uploadFiles surfaces any upload error via its own toast; swallow the rejection so this void-ed
+ // call doesn't raise an unhandled rejection.
+ closeDialog();
+ await importService.uploadFiles("notes", parentNoteId, [file], { format: "keep", safeImport: "true", shrinkImages: "false" }).catch(() => {});
+ }, [file, parentNoteId, closeDialog]);
+
+ // Keep the latest import handler in a ref so the footer effect depends only on `file` being present,
+ // never on doImport's identity — otherwise re-pushing the footer on every change would loop with the
+ // parent re-rendering us back (see the Notion/OneNote panels for the same reasoning).
+ const doImportRef = useRef(doImport);
+ doImportRef.current = doImport;
+
+ useEffect(() => {
+ setFooter(
+ <Button
+ text={t("keep_import.import")}
+ kind="primary"
+ disabled={!file}
+ onClick={() => void doImportRef.current()}
+ />
+ );
+ }, [file, setFooter]);
+
+ useEffect(() => () => setFooter(null), [setFooter]);
+
+ return (
+ <div className="keep-panel">
+ <p>{t("keep_import.description_long")}</p>
+ <FormGroup name="keep-file" label={t("keep_import.choose_file")}>
+ <FormFileUpload onChange={onChange} />
+ </FormGroup>
+ </div>
+ );
+}
+
+const provider: ImportProvider = {
+ id: "keep",
+ name: t("keep_import.name"),
+ icon: "bx bxs-file-archive",
+ description: t("keep_import.description"),
+ Panel: KeepPanel
+};
+
+export default provider;
diff --git a/apps/server/src/assets/translations/en/server.json b/apps/server/src/assets/translations/en/server.json
index 67a19bfc78..bcfecc1e94 100644
--- a/apps/server/src/assets/translations/en/server.json
+++ b/apps/server/src/assets/translations/en/server.json
@@ -322,6 +322,9 @@
"notion_import": {
"root-title": "Notion import"
},
+ "keep_import": {
+ "root-title": "Google Keep import"
+ },
"pdf": {
"export_filter": "PDF Document (*.pdf)",
"unable-to-export-message": "The current note could not be exported as a PDF.",
diff --git a/packages/trilium-core/src/routes/api/import.ts b/packages/trilium-core/src/routes/api/import.ts
index a8290b05fb..695b4eb42b 100644
--- a/packages/trilium-core/src/routes/api/import.ts
+++ b/packages/trilium-core/src/routes/api/import.ts
@@ -10,6 +10,7 @@ import type BNote from "../../becca/entities/bnote.js";
import { ValidationError } from "../../errors.js";
import * as cls from "../../services/context.js";
import enexImportService from "../../services/import/enex.js";
+import keepImportService from "../../services/import/keep/importer.js";
import notionImportService from "../../services/import/notion/importer.js";
import opmlImportService from "../../services/import/opml.js";
import singleImportService from "../../services/import/single.js";
@@ -60,6 +61,10 @@ async function importNotesToBranch(req: ImportRequest<{ parentNoteId: string }>)
// indistinguishable from a Trilium export without inspecting its contents. The Notion import
// dialog tags the upload, so we route it to the Notion importer rather than the generic zip.
note = await notionImportService.importNotion(taskContext, file.buffer, parentNote);
+ } else if (format === "keep" && typeof file.buffer !== "string") {
+ // Like Notion, a Google Keep (Takeout) export is just a `.zip` indistinguishable from a Trilium
+ // export by extension alone, so the Keep import dialog tags the upload to route it here.
+ note = await keepImportService.importKeep(taskContext, file.buffer, parentNote);
} else if (extension === ".zip" && options.explodeArchives && typeof file.buffer !== "string") {
note = await zipImportService.importZip(taskContext, file.buffer, parentNote);
} else if (extension === ".opml" && options.explodeArchives) {
diff --git a/packages/trilium-core/src/services/import/keep/importer.spec.ts b/packages/trilium-core/src/services/import/keep/importer.spec.ts
new file mode 100644
index 0000000000..15761983e3
--- /dev/null
+++ b/packages/trilium-core/src/services/import/keep/importer.spec.ts
@@ -0,0 +1,81 @@
+import { describe, expect, it } from "vitest";
+
+import { parseNote } from "./importer.js";
+
+describe("Google Keep importer — parseNote", () => {
+ it("parses a titled plain-text note: title, paragraphs and original timestamps", () => {
+ const json = JSON.stringify({
+ title: "Asdf",
+ textContent: "Hi there. ",
+ createdTimestampUsec: 1763069966429000,
+ userEditedTimestampUsec: 1763069966429000
+ });
+
+ const note = parseNote("Asdf.json", json);
+
+ expect(note).toEqual({
+ title: "Asdf",
+ content: "<p>Hi there. </p>",
+ utcDateCreated: "2025-11-13 21:39:26.429Z",
+ utcDateModified: "2025-11-13 21:39:26.429Z"
+ });
+ });
+
+ it("falls back to the (timestamp) filename for an untitled note", () => {
+ const json = JSON.stringify({ title: "", textContent: "Dsaa" });
+
+ const note = parseNote("2025-11-13T23_39_37.236+02_00.json", json);
+
+ expect(note?.title).toBe("2025-11-13T23_39_37.236+02_00");
+ });
+
+ it("renders a multi-line body as one paragraph per line, escaping HTML", () => {
+ const json = JSON.stringify({ textContent: "Heading 1\nHeading 2\nBold & <b>italic</b>" });
+
+ const note = parseNote("note.json", json);
+
+ expect(note?.content).toBe("<p>Heading 1</p><p>Heading 2</p><p>Bold &amp; &lt;b&gt;italic&lt;/b&gt;</p>");
+ });
+
+ it("renders a checklist as a CKEditor task list with checked state, skipping empty items", () => {
+ const json = JSON.stringify({
+ listContent: [
+ { text: "This is a note with", isChecked: false },
+ { text: "check", isChecked: true },
+ { text: "", isChecked: false }
+ ]
+ });
+
+ const note = parseNote("list.json", json);
+
+ expect(note?.content).toBe(
+ `<ul class="todo-list">` +
+ `<li><label class="todo-list__label"><input type="checkbox" disabled="disabled"><span class="todo-list__label__description">This is a note with</span></label></li>` +
+ `<li><label class="todo-list__label"><input type="checkbox" checked="checked" disabled="disabled"><span class="todo-list__label__description">check</span></label></li>` +
+ `</ul>`
+ );
+ });
+
+ it("uses distinct created/modified timestamps when both are present", () => {
+ const json = JSON.stringify({
+ textContent: "x",
+ createdTimestampUsec: 1782029545375000,
+ userEditedTimestampUsec: 1782029654353000
+ });
+
+ const note = parseNote("note.json", json);
+
+ expect(note?.utcDateCreated).toBe("2026-06-21 08:12:25.375Z");
+ expect(note?.utcDateModified).toBe("2026-06-21 08:14:14.353Z");
+ });
+
+ it("leaves timestamps undefined and content empty for a bare note", () => {
+ const note = parseNote("empty.json", JSON.stringify({}));
+
+ expect(note).toEqual({ title: "empty", content: "", utcDateCreated: undefined, utcDateModified: undefined });
+ });
+
+ it("skips a malformed JSON entry rather than throwing", () => {
+ expect(parseNote("broken.json", "{ not valid json")).toBeNull();
+ });
+});
diff --git a/packages/trilium-core/src/services/import/keep/importer.ts b/packages/trilium-core/src/services/import/keep/importer.ts
new file mode 100644
index 0000000000..cdf911b39a
--- /dev/null
+++ b/packages/trilium-core/src/services/import/keep/importer.ts
@@ -0,0 +1,182 @@
+/**
+ * Imports a Google Keep (Google Takeout) export zip into a Trilium note tree.
+ *
+ * Takeout exports each Keep note as `<title-or-timestamp>.json` (plus a redundant `.html`/`.txt` and any
+ * attachment files alongside). Keep has no hierarchy — notes are a flat list organised only by labels — so
+ * this importer creates every note directly under a single "Google Keep import" root. This first iteration
+ * reconstructs only the *basic structure*: each note's title, body (plain text or checklist) and original
+ * timestamps. Labels, attachments, colours, pinned/archived/trashed flags and rich-text (the JSON's
+ * `textContentHtml`) are deliberately deferred.
+ *
+ * Invoked from the shared file-import dispatcher (routes/api/import.ts) when the upload is tagged
+ * `format=keep`, so progress, completion and failure are reported by that dispatcher's TaskContext — this
+ * service just builds the tree and returns its root note, like the zip/notion importers.
+ */
+
+import { t } from "i18next";
+
+import type BNote from "../../../becca/entities/bnote.js";
+import noteService from "../../notes.js";
+import protectedSessionService from "../../protected_session.js";
+import type TaskContext from "../../task_context.js";
+import dateUtils from "../../utils/date.js";
+import { getZipProvider } from "../../zip_provider.js";
+
+/** A checklist row in a Keep note (`listContent`). */
+interface KeepListItem {
+ text?: string;
+ isChecked?: boolean;
+}
+
+/** The subset of a Keep Takeout note JSON this iteration reads. */
+interface KeepNote {
+ title?: string;
+ /** Body of a plain-text note. */
+ textContent?: string;
+ /** Body of a checklist note; mutually exclusive with `textContent`. */
+ listContent?: KeepListItem[];
+ /** Creation/last-edit timestamps, in microseconds since the Unix epoch. */
+ createdTimestampUsec?: number;
+ userEditedTimestampUsec?: number;
+}
+
+interface ParsedNote {
+ title: string;
+ /** Body HTML; empty when the note has neither text nor list content. */
+ content: string;
+ utcDateCreated?: string;
+ utcDateModified?: string;
+}
+
+async function importKeep(taskContext: TaskContext<"importNotes">, fileBuffer: Uint8Array, importRootNote: BNote): Promise<BNote> {
+ const notes = await parseNotes(fileBuffer);
+ taskContext.setTotalCount(notes.length);
+
+ return createNotes(importRootNote, notes, taskContext);
+}
+
+/** Reads every note (.json entry) out of the zip, parsing its title, dates and body. */
+async function parseNotes(fileBuffer: Uint8Array): Promise<ParsedNote[]> {
+ const provider = getZipProvider();
+ const filenameEncoding = await provider.detectFilenameEncoding(fileBuffer);
+
+ const notes: ParsedNote[] = [];
+ await provider.readZipFile(fileBuffer, async (entry, readContent) => {
+ const path = entry.fileName;
+ // Each note is a .json file; the redundant per-note .html/.txt, the Labels.txt index and the
+ // attachment binaries are skipped. (Labels.txt also ends in a non-.json extension, so it's covered.)
+ if (!path.toLowerCase().endsWith(".json") || isDirectory(path)) {
+ return;
+ }
+
+ const parsed = parseNote(path, new TextDecoder().decode(await readContent()));
+ if (parsed) {
+ notes.push(parsed);
+ }
+ }, filenameEncoding);
+
+ return notes;
+}
+
+export function parseNote(path: string, json: string): ParsedNote | null {
+ let note: KeepNote;
+ try {
+ note = JSON.parse(json) as KeepNote;
+ } catch {
+ // A non-note JSON (or a malformed entry) is skipped rather than failing the whole import.
+ return null;
+ }
+
+ // Untitled Keep notes export with an empty `title`; their filename is the note's timestamp, which at
+ // least keeps them distinguishable.
+ const title = note.title?.trim() || removeExtension(baseName(path)) || "Untitled";
+
+ return {
+ title,
+ content: buildContent(note),
+ utcDateCreated: usecToUtc(note.createdTimestampUsec),
+ utcDateModified: usecToUtc(note.userEditedTimestampUsec)
+ };
+}
+
+/** Builds a note's body HTML from its plain-text or checklist content (whichever is present). */
+function buildContent(note: KeepNote): string {
+ if (note.listContent?.length) {
+ const items = note.listContent
+ .filter((item) => item.text)
+ .map((item) => {
+ // Match the canonical CKEditor task-list serialization (checked before disabled).
+ const attributes = item.isChecked ? ` checked="checked" disabled="disabled"` : ` disabled="disabled"`;
+ return `<li><label class="todo-list__label"><input type="checkbox"${attributes}><span class="todo-list__label__description">${escapeHtml(item.text ?? "")}</span></label></li>`;
+ });
+ return items.length ? `<ul class="todo-list">${items.join("")}</ul>` : "";
+ }
+
+ if (note.textContent) {
+ return note.textContent
+ .split("\n")
+ .map((line) => `<p>${escapeHtml(line)}</p>`)
+ .join("");
+ }
+
+ return "";
+}
+
+/**
+ * Creates the (flat) note tree under a fresh "Google Keep import" root — Keep has no page hierarchy, so
+ * every note is parented directly under that root. Returns the root.
+ */
+function createNotes(importRootNote: BNote, notes: ParsedNote[], taskContext: TaskContext<"importNotes">): BNote {
+ const isProtected = importRootNote.isProtected && protectedSessionService.isProtectedSessionAvailable();
+
+ const rootNote = noteService.createNewNote({ parentNoteId: importRootNote.noteId, title: t("keep_import.root-title"), content: "", type: "text", mime: "text/html", isProtected }).note;
+ rootNote.addLabel("iconClass", "bx bx-import");
+
+ for (const parsed of notes) {
+ const { note } = noteService.createNewNote({
+ parentNoteId: rootNote.noteId,
+ title: parsed.title,
+ content: parsed.content,
+ type: "text",
+ mime: "text/html",
+ isProtected
+ });
+
+ // Preserve Keep's original timestamps. Must run after createNewNote's content save, which would
+ // otherwise re-stamp the modification date with "now".
+ if (parsed.utcDateCreated || parsed.utcDateModified) {
+ note.setDateCreatedAndModified(parsed.utcDateCreated, parsed.utcDateModified ?? parsed.utcDateCreated);
+ }
+
+ taskContext.increaseProgressCount();
+ }
+
+ return rootNote;
+}
+
+/** Converts a Keep microsecond-epoch timestamp to Trilium's UTC DB format, or undefined if absent/invalid. */
+function usecToUtc(usec: number | undefined): string | undefined {
+ if (!usec) {
+ return undefined;
+ }
+ const date = new Date(usec / 1000);
+ return Number.isNaN(date.getTime()) ? undefined : dateUtils.utcDateTimeStr(date);
+}
+
+function escapeHtml(text: string): string {
+ return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
+}
+
+function isDirectory(path: string): boolean {
+ return path.endsWith("/");
+}
+
+function baseName(path: string): string {
+ return path.split("/").pop() ?? path;
+}
+
+function removeExtension(name: string): string {
+ return name.replace(/\.[^.]+$/, "");
+}
+
+export default { importKeep };