Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

add storage/database connections UI (#8528)

Shahmir Varqha0ae32f1f54ee
diff --git a/frontend/src/components/databases/icons/google-drive.svg b/frontend/src/components/databases/icons/google-drive.svg
new file mode 100644
index 0000000000..a8cefd5b28
--- /dev/null
+++ b/frontend/src/components/databases/icons/google-drive.svg
@@ -0,0 +1,8 @@
+<svg viewBox="0 0 87.3 78" xmlns="http://www.w3.org/2000/svg">
+ <path d="m6.6 66.85 3.85 6.65c.8 1.4 1.95 2.5 3.3 3.3l13.75-23.8h-27.5c0 1.55.4 3.1 1.2 4.5z" fill="#0066da"/>
+ <path d="m43.65 25-13.75-23.8c-1.35.8-2.5 1.9-3.3 3.3l-25.4 44a9.06 9.06 0 0 0 -1.2 4.5h27.5z" fill="#00ac47"/>
+ <path d="m73.55 76.8c1.35-.8 2.5-1.9 3.3-3.3l1.6-2.75 7.65-13.25c.8-1.4 1.2-2.95 1.2-4.5h-27.502l5.852 11.5z" fill="#ea4335"/>
+ <path d="m43.65 25 13.75-23.8c-1.35-.8-2.9-1.2-4.5-1.2h-18.5c-1.6 0-3.15.45-4.5 1.2z" fill="#00832d"/>
+ <path d="m59.8 53h-32.3l-13.75 23.8c1.35.8 2.9 1.2 4.5 1.2h50.8c1.6 0 3.15-.45 4.5-1.2z" fill="#2684fc"/>
+ <path d="m73.4 26.5-12.7-22c-.8-1.4-1.95-2.5-3.3-3.3l-13.75 23.8 16.15 28h27.45c0-1.55-.4-3.1-1.2-4.5z" fill="#ffba00"/>
+</svg>
\ No newline at end of file
diff --git a/frontend/src/components/datasources/datasources.tsx b/frontend/src/components/datasources/datasources.tsx
index a34d427690..74379a83b9 100644
--- a/frontend/src/components/datasources/datasources.tsx
+++ b/frontend/src/components/datasources/datasources.tsx
@@ -60,7 +60,7 @@ import { ErrorBoundary } from "../editor/boundary/ErrorBoundary";
import { PythonIcon } from "../editor/cell/code/icons";
import { useAddCodeToNewCell } from "../editor/cell/useAddCell";
import { PanelEmptyState } from "../editor/chrome/panels/empty-state";
-import { AddDatabaseDialog } from "../editor/database/add-database-form";
+import { AddConnectionDialog } from "../editor/connections/add-connection-dialog";
import { DatasetColumnPreview } from "./column-preview";
import {
ColumnName,
@@ -160,12 +160,12 @@ export const DataSources: React.FC = () => {
title="No tables found"
description="Any datasets/dataframes in the global scope will be shown here."
action={
- <AddDatabaseDialog>
+ <AddConnectionDialog>
<Button variant="outline" size="sm">
Add database or catalog
<PlusIcon className="h-4 w-4 ml-2" />
</Button>
- </AddDatabaseDialog>
+ </AddConnectionDialog>
}
icon={<DatabaseIcon />}
/>
@@ -201,7 +201,7 @@ export const DataSources: React.FC = () => {
</button>
)}
- <AddDatabaseDialog>
+ <AddConnectionDialog>
<Button
variant="ghost"
size="sm"
@@ -209,7 +209,7 @@ export const DataSources: React.FC = () => {
>
<PlusIcon className="h-4 w-4" />
</Button>
- </AddDatabaseDialog>
+ </AddConnectionDialog>
</div>
<CommandList className="flex flex-col">
diff --git a/frontend/src/components/editor/actions/useNotebookActions.tsx b/frontend/src/components/editor/actions/useNotebookActions.tsx
index e4d9ded011..59207ab839 100644
--- a/frontend/src/components/editor/actions/useNotebookActions.tsx
+++ b/frontend/src/components/editor/actions/useNotebookActions.tsx
@@ -24,6 +24,7 @@ import {
FolderDownIcon,
GithubIcon,
GlobeIcon,
+ HardDrive,
Home,
ImageIcon,
KeyboardIcon,
@@ -78,9 +79,9 @@ import { newNotebookURL } from "@/utils/urls";
import { useRunAllCells } from "../cell/useRunCells";
import { useChromeActions, useChromeState } from "../chrome/state";
import { PANELS } from "../chrome/types";
+import { AddConnectionDialogContent } from "../connections/add-connection-dialog";
import { keyboardShortcutsAtom } from "../controls/keyboard-shortcuts";
import { commandPaletteAtom } from "../controls/state";
-import { AddDatabaseDialogContent } from "../database/add-database-form";
import { displayLayoutName, getLayoutIcon } from "../renderers/layout-select";
import { LAYOUT_TYPES } from "../renderers/types";
import { runServerSidePDFDownload } from "./pdf-export";
@@ -450,7 +451,19 @@ export function useNotebookActions() {
icon: <DatabaseIcon size={14} strokeWidth={1.5} />,
label: "Add database connection",
handle: () => {
- openModal(<AddDatabaseDialogContent onClose={closeModal} />);
+ openModal(<AddConnectionDialogContent onClose={closeModal} />);
+ },
+ },
+ {
+ icon: <HardDrive size={14} strokeWidth={1.5} />,
+ label: "Add remote storage",
+ handle: () => {
+ openModal(
+ <AddConnectionDialogContent
+ defaultTab="storage"
+ onClose={closeModal}
+ />,
+ );
},
},
{
diff --git a/frontend/src/components/editor/database/__tests__/secrets.test.ts b/frontend/src/components/editor/connections/__tests__/secrets.test.ts
similarity index 100%
rename from frontend/src/components/editor/database/__tests__/secrets.test.ts
rename to frontend/src/components/editor/connections/__tests__/secrets.test.ts
diff --git a/frontend/src/components/editor/connections/add-connection-dialog.tsx b/frontend/src/components/editor/connections/add-connection-dialog.tsx
new file mode 100644
index 0000000000..8a63b661cb
--- /dev/null
+++ b/frontend/src/components/editor/connections/add-connection-dialog.tsx
@@ -0,0 +1,83 @@
+/* Copyright 2026 Marimo. All rights reserved. */
+
+import { useState } from "react";
+import {
+ Dialog,
+ DialogContent,
+ DialogDescription,
+ DialogHeader,
+ DialogTitle,
+ DialogTrigger,
+} from "@/components/ui/dialog";
+import { ExternalLink } from "@/components/ui/links";
+import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
+import { AddDatabaseForm } from "./database/add-database-form";
+import { AddStorageForm } from "./storage/add-storage-form";
+
+type ConnectionTab = "databases" | "storage";
+
+export const AddConnectionDialog: React.FC<{
+ children: React.ReactNode;
+ defaultTab?: ConnectionTab;
+}> = ({ children, defaultTab = "databases" }) => {
+ const [open, setOpen] = useState(false);
+
+ return (
+ <Dialog open={open} onOpenChange={setOpen}>
+ <DialogTrigger asChild={true}>{children}</DialogTrigger>
+ <AddConnectionDialogContent
+ defaultTab={defaultTab}
+ onClose={() => setOpen(false)}
+ />
+ </Dialog>
+ );
+};
+
+export const AddConnectionDialogContent: React.FC<{
+ defaultTab?: ConnectionTab;
+ onClose: () => void;
+}> = ({ defaultTab = "databases", onClose }) => {
+ const tabHeader = (
+ <TabsList className="w-full mb-4">
+ <TabsTrigger value="databases" className="flex-1">
+ Databases & Catalogs
+ </TabsTrigger>
+ <TabsTrigger value="storage" className="flex-1">
+ Remote Storages
+ </TabsTrigger>
+ </TabsList>
+ );
+
+ return (
+ <DialogContent className="max-h-[75vh] overflow-y-auto">
+ <DialogHeader>
+ <DialogTitle>Add Connection</DialogTitle>
+ <DialogDescription>
+ Connect to a{" "}
+ <ExternalLink href="https://docs.marimo.io/guides/working_with_data/sql/#connecting-to-a-custom-database">
+ database, data catalog
+ </ExternalLink>{" "}
+ or{" "}
+ <ExternalLink href="https://docs.marimo.io/guides/working_with_data/remote_storage/">
+ remote storage
+ </ExternalLink>{" "}
+ to work with data directly from your notebook.
+ </DialogDescription>
+ </DialogHeader>
+ <Tabs defaultValue={defaultTab}>
+ <TabsContent
+ value="databases"
+ className="mt-0 focus-visible:ring-0 focus-visible:ring-offset-0"
+ >
+ <AddDatabaseForm onSubmit={onClose} header={tabHeader} />
+ </TabsContent>
+ <TabsContent
+ value="storage"
+ className="mt-0 focus-visible:ring-0 focus-visible:ring-offset-0"
+ >
+ <AddStorageForm onSubmit={onClose} header={tabHeader} />
+ </TabsContent>
+ </Tabs>
+ </DialogContent>
+ );
+};
diff --git a/frontend/src/components/editor/connections/components.tsx b/frontend/src/components/editor/connections/components.tsx
new file mode 100644
index 0000000000..1f6dcbb168
--- /dev/null
+++ b/frontend/src/components/editor/connections/components.tsx
@@ -0,0 +1,177 @@
+/* Copyright 2026 Marimo. All rights reserved. */
+
+import { zodResolver } from "@hookform/resolvers/zod";
+import React from "react";
+import { type DefaultValues, type FieldValues, useForm } from "react-hook-form";
+import type { z } from "zod";
+import { type FormRenderer, ZodForm } from "@/components/forms/form";
+import { getDefaults } from "@/components/forms/form-utils";
+import { Button } from "@/components/ui/button";
+import { FormErrorsBanner } from "@/components/ui/form";
+import {
+ Select,
+ SelectContent,
+ SelectGroup,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
+} from "@/components/ui/select";
+import { useCellActions } from "@/core/cells/cells";
+import { useLastFocusedCellId } from "@/core/cells/focus";
+import { ENV_RENDERER, SecretsProvider } from "./form-renderers";
+
+const RENDERERS: FormRenderer[] = [ENV_RENDERER];
+
+/**
+ * Grid layout for provider/database selector buttons.
+ */
+export const SelectorGrid: React.FC<{ children: React.ReactNode }> = ({
+ children,
+}) => <div className="grid grid-cols-2 md:grid-cols-3 gap-4">{children}</div>;
+
+/**
+ * A colored button tile for selecting a provider/database.
+ */
+export const SelectorButton: React.FC<{
+ name: string;
+ color: string;
+ icon: React.ReactNode;
+ onSelect: () => void;
+}> = ({ name, color, icon, onSelect }) => (
+ <button
+ type="button"
+ className="py-3 flex flex-col items-center justify-center gap-1 transition-all hover:scale-105 hover:brightness-110 rounded shadow-sm-solid hover:shadow-md-solid"
+ style={{ backgroundColor: color }}
+ onClick={onSelect}
+ >
+ {icon}
+ <span className="text-white font-medium text-lg">{name}</span>
+ </button>
+);
+
+/**
+ * Footer with Back/Add buttons and a library picker.
+ */
+export const ConnectionFormFooter = <L extends string>({
+ onBack,
+ isValid,
+ libraries,
+ preferredLibrary,
+ onLibraryChange,
+ displayNames,
+ libraryLabel = "Preferred library",
+}: {
+ onBack: () => void;
+ isValid: boolean;
+ libraries: L[];
+ preferredLibrary: L;
+ onLibraryChange: (library: L) => void;
+ displayNames: Record<L, string>;
+ libraryLabel?: string;
+}) => (
+ <div className="flex gap-2 justify-between">
+ <div className="flex gap-2">
+ <Button type="button" variant="outline" onClick={onBack}>
+ Back
+ </Button>
+ <Button type="submit" disabled={!isValid}>
+ Add
+ </Button>
+ </div>
+ <div>
+ <Select value={preferredLibrary} onValueChange={onLibraryChange}>
+ <div className="flex flex-col gap-1 items-end">
+ <SelectTrigger>
+ <SelectValue placeholder="Select a library" />
+ </SelectTrigger>
+ <span className="text-xs text-muted-foreground">{libraryLabel}</span>
+ </div>
+ <SelectContent>
+ <SelectGroup>
+ {libraries.map((library) => (
+ <SelectItem key={library} value={library}>
+ {displayNames[library] ?? library}
+ </SelectItem>
+ ))}
+ </SelectGroup>
+ </SelectContent>
+ </Select>
+ </div>
+ </div>
+);
+
+/**
+ * Returns a callback that inserts code into a new cell after the last focused cell.
+ */
+export function useInsertCode() {
+ const { createNewCell } = useCellActions();
+ const lastFocusedCellId = useLastFocusedCellId();
+
+ return (code: string) => {
+ createNewCell({
+ code,
+ before: false,
+ cellId: lastFocusedCellId ?? "__end__",
+ skipIfCodeExists: true,
+ });
+ };
+}
+
+/**
+ * Generic connection form: Zod-driven form with secrets support, a library
+ * picker, and Back/Add buttons. Used by both database and storage forms.
+ */
+export const ConnectionForm = <T extends FieldValues, L extends string>({
+ schema,
+ libraries,
+ preferredLibrary: initialPreferred,
+ displayNames,
+ libraryLabel,
+ generateCode,
+ onSubmit,
+ onBack,
+}: {
+ schema: z.ZodType<T, FieldValues>;
+ libraries: L[];
+ preferredLibrary: L;
+ displayNames: Record<L, string>;
+ libraryLabel?: string;
+ generateCode: (values: T, library: L) => string;
+ onSubmit: () => void;
+ onBack: () => void;
+}) => {
+ const defaults = getDefaults(schema);
+ const form = useForm<T>({
+ defaultValues: defaults as DefaultValues<T>,
+ resolver: zodResolver(schema),
+ reValidateMode: "onChange",
+ });
+
+ const [preferredLibrary, setPreferredLibrary] =
+ React.useState<L>(initialPreferred);
+ const insertCode = useInsertCode();
+
+ const handleSubmit = (values: T) => {
+ insertCode(generateCode(values, preferredLibrary));
+ onSubmit();
+ };
+
+ return (
+ <form onSubmit={form.handleSubmit(handleSubmit)} className="space-y-4">
+ <SecretsProvider>
+ <ZodForm schema={schema} form={form} renderers={RENDERERS}>
+ <FormErrorsBanner />
+ </ZodForm>
+ </SecretsProvider>
+ <ConnectionFormFooter
+ onBack={onBack}
+ isValid={form.formState.isValid}
+ libraries={libraries}
+ preferredLibrary={preferredLibrary}
+ onLibraryChange={setPreferredLibrary}
+ displayNames={displayNames}
+ libraryLabel={libraryLabel}
+ />
+ </form>
+ );
+};
diff --git a/frontend/src/components/editor/database/__tests__/__snapshots__/as-code.test.ts.snap b/frontend/src/components/editor/connections/database/__tests__/__snapshots__/as-code.test.ts.snap
similarity index 100%
rename from frontend/src/components/editor/database/__tests__/__snapshots__/as-code.test.ts.snap
rename to frontend/src/components/editor/connections/database/__tests__/__snapshots__/as-code.test.ts.snap
diff --git a/frontend/src/components/editor/database/__tests__/as-code.test.ts b/frontend/src/components/editor/connections/database/__tests__/as-code.test.ts
similarity index 99%
rename from frontend/src/components/editor/database/__tests__/as-code.test.ts
rename to frontend/src/components/editor/connections/database/__tests__/as-code.test.ts
index b8a549d68f..c2790b6338 100644
--- a/frontend/src/components/editor/database/__tests__/as-code.test.ts
+++ b/frontend/src/components/editor/connections/database/__tests__/as-code.test.ts
@@ -1,8 +1,8 @@
/* Copyright 2026 Marimo. All rights reserved. */
import { describe, expect, it } from "vitest";
+import { prefixSecret } from "../../secrets";
import { type ConnectionLibrary, generateDatabaseCode } from "../as-code";
import type { DatabaseConnection } from "../schemas";
-import { prefixSecret } from "../secrets";
describe("generateDatabaseCode", () => {
// Test fixtures
diff --git a/frontend/src/components/editor/connections/database/add-database-form.tsx b/frontend/src/components/editor/connections/database/add-database-form.tsx
new file mode 100644
index 0000000000..144eff3fcc
--- /dev/null
+++ b/frontend/src/components/editor/connections/database/add-database-form.tsx
@@ -0,0 +1,303 @@
+/* Copyright 2026 Marimo. All rights reserved. */
+
+import { useState } from "react";
+import type { FieldValues } from "react-hook-form";
+import type { z } from "zod";
+import { DatabaseLogo, type DBLogoName } from "@/components/databases/icon";
+import { ConnectionForm, SelectorButton, SelectorGrid } from "../components";
+import {
+ ConnectionDisplayNames,
+ type ConnectionLibrary,
+ generateDatabaseCode,
+} from "./as-code";
+import {
+ BigQueryConnectionSchema,
+ ChdbConnectionSchema,
+ ClickhouseConnectionSchema,
+ type DatabaseConnection,
+ DatabricksConnectionSchema,
+ DataFusionConnectionSchema,
+ DuckDBConnectionSchema,
+ IcebergConnectionSchema,
+ MotherDuckConnectionSchema,
+ MySQLConnectionSchema,
+ PostgresConnectionSchema,
+ PySparkConnectionSchema,
+ RedshiftConnectionSchema,
+ SnowflakeConnectionSchema,
+ SQLiteConnectionSchema,
+ SupabaseConnectionSchema,
+ TimeplusConnectionSchema,
+ TrinoConnectionSchema,
+} from "./schemas";
+
+interface ConnectionSchema {
+ name: string;
+ schema: z.ZodType<DatabaseConnection, FieldValues>;
+ color: string;
+ logo: DBLogoName;
+ connectionLibraries: {
+ libraries: ConnectionLibrary[];
+ preferred: ConnectionLibrary;
+ };
+}
+
+const DATABASES = [
+ {
+ name: "PostgreSQL",
+ schema: PostgresConnectionSchema,
+ color: "#336791",
+ logo: "postgres",
+ connectionLibraries: {
+ libraries: ["sqlalchemy", "sqlmodel"],
+ preferred: "sqlalchemy",
+ },
+ },
+ {
+ name: "MySQL",
+ schema: MySQLConnectionSchema,
+ color: "#00758F",
+ logo: "mysql",
+ connectionLibraries: {
+ libraries: ["sqlalchemy", "sqlmodel"],
+ preferred: "sqlalchemy",
+ },
+ },
+ {
+ name: "SQLite",
+ schema: SQLiteConnectionSchema,
+ color: "#003B57",
+ logo: "sqlite",
+ connectionLibraries: {
+ libraries: ["sqlalchemy", "sqlmodel"],
+ preferred: "sqlalchemy",
+ },
+ },
+ {
+ name: "DuckDB",
+ schema: DuckDBConnectionSchema,
+ color: "#FFD700",
+ logo: "duckdb",
+ connectionLibraries: {
+ libraries: ["duckdb"],
+ preferred: "duckdb",
+ },
+ },
+ {
+ name: "MotherDuck",
+ schema: MotherDuckConnectionSchema,
+ color: "#ff9538",
+ logo: "motherduck",
+ connectionLibraries: {
+ libraries: ["duckdb"],
+ preferred: "duckdb",
+ },
+ },
+ {
+ name: "Snowflake",
+ schema: SnowflakeConnectionSchema,
+ color: "#29B5E8",
+ logo: "snowflake",
+ connectionLibraries: {
+ libraries: ["sqlalchemy", "sqlmodel"],
+ preferred: "sqlalchemy",
+ },
+ },
+ {
+ name: "ClickHouse",
+ schema: ClickhouseConnectionSchema,
+ color: "#2C2C1D",
+ logo: "clickhouse",
+ connectionLibraries: {
+ libraries: ["clickhouse_connect"],
+ preferred: "clickhouse_connect",
+ },
+ },
+ {
+ name: "Timeplus",
+ schema: TimeplusConnectionSchema,
+ color: "#B83280",
+ logo: "timeplus",
+ connectionLibraries: {
+ libraries: ["sqlalchemy", "sqlmodel"],
+ preferred: "sqlalchemy",
+ },
+ },
+ {
+ name: "BigQuery",
+ schema: BigQueryConnectionSchema,
+ color: "#4285F4",
+ logo: "bigquery",
+ connectionLibraries: {
+ libraries: ["sqlalchemy", "sqlmodel"],
+ preferred: "sqlalchemy",
+ },
+ },
+ {
+ name: "ClickHouse Embedded",
+ schema: ChdbConnectionSchema,
+ color: "#f2b611",
+ logo: "clickhouse",
+ connectionLibraries: {
+ libraries: ["chdb"],
+ preferred: "chdb",
+ },
+ },
+ {
+ name: "Trino",
+ schema: TrinoConnectionSchema,
+ color: "#d466b6",
+ logo: "trino",
+ connectionLibraries: {
+ libraries: ["sqlalchemy", "sqlmodel"],
+ preferred: "sqlalchemy",
+ },
+ },
+ {
+ name: "DataFusion",
+ schema: DataFusionConnectionSchema,
+ color: "#202A37",
+ logo: "datafusion",
+ connectionLibraries: {
+ libraries: ["ibis"],
+ preferred: "ibis",
+ },
+ },
+ {
+ name: "PySpark",
+ schema: PySparkConnectionSchema,
+ color: "#1C5162",
+ logo: "pyspark",
+ connectionLibraries: {
+ libraries: ["ibis"],
+ preferred: "ibis",
+ },
+ },
+ {
+ name: "Redshift",
+ schema: RedshiftConnectionSchema,
+ color: "#522BAE",
+ logo: "redshift",
+ connectionLibraries: {
+ libraries: ["redshift"],
+ preferred: "redshift",
+ },
+ },
+ {
+ name: "Databricks",
+ schema: DatabricksConnectionSchema,
+ color: "#c41e0c",
+ logo: "databricks",
+ connectionLibraries: {
+ libraries: ["sqlalchemy", "sqlmodel", "ibis"],
+ preferred: "sqlalchemy",
+ },
+ },
+ {
+ name: "Supabase",
+ schema: SupabaseConnectionSchema,
+ color: "#238F5F",
+ logo: "supabase",
+ connectionLibraries: {
+ libraries: ["sqlalchemy", "sqlmodel"],
+ preferred: "sqlalchemy",
+ },
+ },
+] satisfies ConnectionSchema[];
+
+const DATA_CATALOGS = [
+ {
+ name: "Iceberg",
+ schema: IcebergConnectionSchema,
+ color: "#000000",
+ logo: "iceberg",
+ connectionLibraries: {
+ libraries: ["pyiceberg"],
+ preferred: "pyiceberg",
+ },
+ },
+] satisfies ConnectionSchema[];
+
+const ALL_ENTRIES = [...DATABASES, ...DATA_CATALOGS];
+
+const DatabaseSchemaSelector: React.FC<{
+ onSelect: (schema: z.ZodType<DatabaseConnection, FieldValues>) => void;
+}> = ({ onSelect }) => {
+ return (
+ <>
+ <SelectorGrid>
+ {DATABASES.map(({ name, schema, color, logo }) => (
+ <SelectorButton
+ key={name}
+ name={name}
+ color={color}
+ icon={
+ <DatabaseLogo
+ name={logo}
+ className="w-8 h-8 text-white brightness-0 invert dark:invert"
+ />
+ }
+ onSelect={() => onSelect(schema)}
+ />
+ ))}
+ </SelectorGrid>
+ <h4 className="font-semibold text-muted-foreground text-lg flex items-center gap-4 my-2">
+ Data Catalogs
+ <hr className="flex-1" />
+ </h4>
+ <SelectorGrid>
+ {DATA_CATALOGS.map(({ name, schema, color, logo }) => (
+ <SelectorButton
+ key={name}
+ name={name}
+ color={color}
+ icon={
+ <DatabaseLogo
+ name={logo}
+ className="w-8 h-8 text-white brightness-0 invert dark:invert"
+ />
+ }
+ onSelect={() => onSelect(schema)}
+ />
+ ))}
+ </SelectorGrid>
+ </>
+ );
+};
+
+export const AddDatabaseForm: React.FC<{
+ onSubmit: () => void;
+ header?: React.ReactNode;
+}> = ({ onSubmit, header }) => {
+ const [selectedSchema, setSelectedSchema] = useState<z.ZodType<
+ DatabaseConnection,
+ FieldValues
+ > | null>(null);
+
+ if (!selectedSchema) {
+ return (
+ <>
+ {header}
+ <div>
+ <DatabaseSchemaSelector onSelect={setSelectedSchema} />
+ </div>
+ </>
+ );
+ }
+
+ const entry = ALL_ENTRIES.find((e) => e.schema === selectedSchema);
+ const libs = entry?.connectionLibraries;
+
+ return (
+ <ConnectionForm<DatabaseConnection, ConnectionLibrary>
+ schema={selectedSchema}
+ libraries={libs?.libraries ?? []}
+ preferredLibrary={libs?.preferred ?? "sqlalchemy"}
+ displayNames={ConnectionDisplayNames}
+ libraryLabel="Preferred connection library"
+ generateCode={(values, library) => generateDatabaseCode(values, library)}
+ onSubmit={onSubmit}
+ onBack={() => setSelectedSchema(null)}
+ />
+ );
+};
diff --git a/frontend/src/components/editor/database/as-code.ts b/frontend/src/components/editor/connections/database/as-code.ts
similarity index 99%
rename from frontend/src/components/editor/database/as-code.ts
rename to frontend/src/components/editor/connections/database/as-code.ts
index 3226e880a8..9b2b9cad9b 100644
--- a/frontend/src/components/editor/database/as-code.ts
+++ b/frontend/src/components/editor/connections/database/as-code.ts
@@ -2,8 +2,8 @@
import dedent from "string-dedent";
import { assertNever } from "@/utils/assertNever";
+import { isSecret, unprefixSecret } from "../secrets";
import { type DatabaseConnection, DatabaseConnectionSchema } from "./schemas";
-import { isSecret, unprefixSecret } from "./secrets";
export type ConnectionLibrary =
| "sqlmodel"
diff --git a/frontend/src/components/editor/database/schemas.ts b/frontend/src/components/editor/connections/database/schemas.ts
similarity index 100%
rename from frontend/src/components/editor/database/schemas.ts
rename to frontend/src/components/editor/connections/database/schemas.ts
diff --git a/frontend/src/components/editor/database/form-renderers.tsx b/frontend/src/components/editor/connections/form-renderers.tsx
similarity index 100%
rename from frontend/src/components/editor/database/form-renderers.tsx
rename to frontend/src/components/editor/connections/form-renderers.tsx
diff --git a/frontend/src/components/editor/database/secrets.ts b/frontend/src/components/editor/connections/secrets.ts
similarity index 100%
rename from frontend/src/components/editor/database/secrets.ts
rename to frontend/src/components/editor/connections/secrets.ts
diff --git a/frontend/src/components/editor/connections/storage/__tests__/__snapshots__/as-code.test.ts.snap b/frontend/src/components/editor/connections/storage/__tests__/__snapshots__/as-code.test.ts.snap
new file mode 100644
index 0000000000..30a3843442
--- /dev/null
+++ b/frontend/src/components/editor/connections/storage/__tests__/__snapshots__/as-code.test.ts.snap
@@ -0,0 +1,100 @@
+// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
+
+exports[`generateStorageCode > Azure > basic connection with account key 1`] = `
+"from obstore.store import AzureStore
+
+store = AzureStore("my-container",
+ account_name="storageaccount",
+ account_key="base64accountkey==",
+)"
+`;
+
+exports[`generateStorageCode > Azure > with secrets 1`] = `
+"from obstore.store import AzureStore
+import os
+
+_account_name = os.environ.get("AZURE_ACCOUNT")
+_account_key = os.environ.get("AZURE_KEY")
+store = AzureStore("my-container",
+ account_name=_account_name,
+ account_key=_account_key,
+)"
+`;
+
+exports[`generateStorageCode > Azure > without account key 1`] = `
+"from obstore.store import AzureStore
+
+store = AzureStore("my-container",
+ account_name="storageaccount",
+)"
+`;
+
+exports[`generateStorageCode > GCS > with service account key 1`] = `
+"from obstore.store import GCSStore
+import json
+
+_credentials = json.loads("""{"type": "service_account", "project_id": "test"}""")
+store = GCSStore("my-bucket",
+ service_account_key=_credentials,
+)"
+`;
+
+exports[`generateStorageCode > GCS > without service account key (default credentials) 1`] = `
+"from obstore.store import GCSStore
+
+store = GCSStore("my-bucket")"
+`;
+
+exports[`generateStorageCode > Google Drive > with browser auth (no credentials) 1`] = `
+"from gdrive_fsspec import GoogleDriveFileSystem
+
+fs = GoogleDriveFileSystem(token="browser")"
+`;
+
+exports[`generateStorageCode > Google Drive > with service account credentials 1`] = `
+"from gdrive_fsspec import GoogleDriveFileSystem
+import json
+
+_creds = json.loads("""{"type": "service_account", "client_email": "[email protected]"}""")
+fs = GoogleDriveFileSystem(creds=_creds, token="service_account")"
+`;
+
+exports[`generateStorageCode > S3 > basic connection with all fields 1`] = `
+"from obstore.store import S3Store
+
+store = S3Store("my-bucket",
+ region="us-east-1",
+ access_key_id="AKIAIOSFODNN7EXAMPLE",
+ secret_access_key="wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
+)"
+`;
+
+exports[`generateStorageCode > S3 > minimal connection (bucket only) 1`] = `
+"from obstore.store import S3Store
+
+store = S3Store("my-bucket",)"
+`;
+
+exports[`generateStorageCode > S3 > with custom endpoint 1`] = `
+"from obstore.store import S3Store
+
+store = S3Store("my-bucket",
+ region="us-east-1",
+ access_key_id="AKIAIOSFODNN7EXAMPLE",
+ secret_access_key="wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
+ endpoint_url="https://minio.example.com:9000",
+)"
+`;
+
+exports[`generateStorageCode > S3 > with secrets 1`] = `
+"from obstore.store import S3Store
+import os
+
+_access_key_id = os.environ.get("AWS_ACCESS_KEY_ID")
+_secret_access_key = os.environ.get("AWS_SECRET_ACCESS_KEY")
+store = S3Store("my-bucket",
+ region="us-east-1",
+ access_key_id=_access_key_id,
+ secret_access_key=_secret_access_key,
+)"
+`;
diff --git a/frontend/src/components/editor/connections/storage/__tests__/as-code.test.ts b/frontend/src/components/editor/connections/storage/__tests__/as-code.test.ts
new file mode 100644
index 0000000000..26dacb3db0
--- /dev/null
+++ b/frontend/src/components/editor/connections/storage/__tests__/as-code.test.ts
@@ -0,0 +1,166 @@
+/* Copyright 2026 Marimo. All rights reserved. */
+import { describe, expect, it } from "vitest";
+import { prefixSecret } from "../../secrets";
+import { generateStorageCode } from "../as-code";
+import type { StorageConnection } from "../schemas";
+
+describe("generateStorageCode", () => {
+ const baseS3: StorageConnection = {
+ type: "s3",
+ bucket: "my-bucket",
+ region: "us-east-1",
+ access_key_id: "AKIAIOSFODNN7EXAMPLE",
+ secret_access_key: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
+ endpoint_url: undefined,
+ };
+
+ const baseGCS: StorageConnection = {
+ type: "gcs",
+ bucket: "my-bucket",
+ service_account_key: '{"type": "service_account", "project_id": "test"}',
+ };
+
+ const baseAzure: StorageConnection = {
+ type: "azure",
+ container: "my-container",
+ account_name: "storageaccount",
+ account_key: "base64accountkey==",
+ };
+
+ const baseGDrive: StorageConnection = {
+ type: "gdrive",
+ credentials_json:
+ '{"type": "service_account", "client_email": "[email protected]"}',
+ };
+
+ describe("S3", () => {
+ it("basic connection with all fields", () => {
+ expect(generateStorageCode(baseS3, "obstore")).toMatchSnapshot();
+ });
+
+ it("minimal connection (bucket only)", () => {
+ const conn: StorageConnection = {
+ type: "s3",
+ bucket: "my-bucket",
+ };
+ expect(generateStorageCode(conn, "obstore")).toMatchSnapshot();
+ });
+
+ it("with custom endpoint", () => {
+ const conn: StorageConnection = {
+ ...baseS3,
+ endpoint_url: "https://minio.example.com:9000",
+ };
+ expect(generateStorageCode(conn, "obstore")).toMatchSnapshot();
+ });
+
+ it("with secrets", () => {
+ const conn: StorageConnection = {
+ type: "s3",
+ bucket: "my-bucket",
+ region: "us-east-1",
+ access_key_id: prefixSecret("AWS_ACCESS_KEY_ID"),
+ secret_access_key: prefixSecret("AWS_SECRET_ACCESS_KEY"),
+ };
+ expect(generateStorageCode(conn, "obstore")).toMatchSnapshot();
+ });
+ });
+
+ describe("GCS", () => {
+ it("with service account key", () => {
+ expect(generateStorageCode(baseGCS, "obstore")).toMatchSnapshot();
+ });
+
+ it("without service account key (default credentials)", () => {
+ const conn: StorageConnection = {
+ type: "gcs",
+ bucket: "my-bucket",
+ };
+ expect(generateStorageCode(conn, "obstore")).toMatchSnapshot();
+ });
+ });
+
+ describe("Azure", () => {
+ it("basic connection with account key", () => {
+ expect(generateStorageCode(baseAzure, "obstore")).toMatchSnapshot();
+ });
+
+ it("without account key", () => {
+ const conn: StorageConnection = {
+ type: "azure",
+ container: "my-container",
+ account_name: "storageaccount",
+ };
+ expect(generateStorageCode(conn, "obstore")).toMatchSnapshot();
+ });
+
+ it("with secrets", () => {
+ const conn: StorageConnection = {
+ type: "azure",
+ container: "my-container",
+ account_name: prefixSecret("AZURE_ACCOUNT"),
+ account_key: prefixSecret("AZURE_KEY"),
+ };
+ expect(generateStorageCode(conn, "obstore")).toMatchSnapshot();
+ });
+ });
+
+ describe("Google Drive", () => {
+ it("with service account credentials", () => {
+ expect(generateStorageCode(baseGDrive, "fsspec")).toMatchSnapshot();
+ });
+
+ it("with browser auth (no credentials)", () => {
+ const conn: StorageConnection = {
+ type: "gdrive",
+ };
+ expect(generateStorageCode(conn, "fsspec")).toMatchSnapshot();
+ });
+ });
+
+ describe("invalid cases", () => {
+ it("throws for empty S3 bucket", () => {
+ expect(() =>
+ generateStorageCode(
+ { type: "s3", bucket: "" } as StorageConnection,
+ "obstore",
+ ),
+ ).toThrow();
+ });
+
+ it("throws for empty GCS bucket", () => {
+ expect(() =>
+ generateStorageCode(
+ { type: "gcs", bucket: "" } as StorageConnection,
+ "obstore",
+ ),
+ ).toThrow();
+ });
+
+ it("throws for empty Azure container", () => {
+ expect(() =>
+ generateStorageCode(
+ {
+ type: "azure",
+ container: "",
+ account_name: "acct",
+ } as StorageConnection,
+ "obstore",
+ ),
+ ).toThrow();
+ });
+
+ it("throws for empty Azure account name", () => {
+ expect(() =>
+ generateStorageCode(
+ {
+ type: "azure",
+ container: "my-container",
+ account_name: "",
+ } as StorageConnection,
+ "obstore",
+ ),
+ ).toThrow();
+ });
+ });
+});
diff --git a/frontend/src/components/editor/connections/storage/add-storage-form.tsx b/frontend/src/components/editor/connections/storage/add-storage-form.tsx
new file mode 100644
index 0000000000..26337dc1ac
--- /dev/null
+++ b/frontend/src/components/editor/connections/storage/add-storage-form.tsx
@@ -0,0 +1,135 @@
+/* Copyright 2026 Marimo. All rights reserved. */
+
+import { useState } from "react";
+import type { FieldValues } from "react-hook-form";
+import type { z } from "zod";
+import { ProtocolIcon } from "@/components/storage/components";
+import { ConnectionForm, SelectorButton, SelectorGrid } from "../components";
+import {
+ generateStorageCode,
+ type StorageLibrary,
+ StorageLibraryDisplayNames,
+} from "./as-code";
+import {
+ AzureStorageSchema,
+ GCSStorageSchema,
+ GoogleDriveStorageSchema,
+ S3StorageSchema,
+ type StorageConnection,
+} from "./schemas";
+
+interface StorageProviderSchema {
+ name: string;
+ schema: z.ZodType<StorageConnection, FieldValues>;
+ color: string;
+ protocol: string;
+ storageLibraries: {
+ libraries: StorageLibrary[];
+ preferred: StorageLibrary;
+ };
+}
+
+const STORAGE_PROVIDERS = [
+ {
+ name: "Amazon S3",
+ schema: S3StorageSchema,
+ color: "#232F3E",
+ protocol: "s3",
+ storageLibraries: {
+ libraries: ["obstore"],
+ preferred: "obstore",
+ },
+ },
+ {
+ name: "Google Cloud Storage",
+ schema: GCSStorageSchema,
+ color: "#4285F4",
+ protocol: "gcs",
+ storageLibraries: {
+ libraries: ["obstore"],
+ preferred: "obstore",
+ },
+ },
+ {
+ name: "Azure Blob Storage",
+ schema: AzureStorageSchema,
+ color: "#0062AD",
+ protocol: "azure",
+ storageLibraries: {
+ libraries: ["obstore"],
+ preferred: "obstore",
+ },
+ },
+ {
+ name: "Google Drive",
+ schema: GoogleDriveStorageSchema,
+ color: "#177834",
+ protocol: "gdrive",
+ storageLibraries: {
+ libraries: ["fsspec"],
+ preferred: "fsspec",
+ },
+ },
+] satisfies StorageProviderSchema[];
+
+const StorageProviderSelector: React.FC<{
+ onSelect: (schema: z.ZodType<StorageConnection, FieldValues>) => void;
+}> = ({ onSelect }) => {
+ return (
+ <SelectorGrid>
+ {STORAGE_PROVIDERS.map(({ name, schema, color, protocol }) => (
+ <SelectorButton
+ key={name}
+ name={name}
+ color={color}
+ icon={
+ <span className="w-8 h-8 flex items-center justify-center">
+ <ProtocolIcon
+ protocol={protocol}
+ className="w-7 h-7 brightness-0 invert"
+ />
+ </span>
+ }
+ onSelect={() => onSelect(schema)}
+ />
+ ))}
+ </SelectorGrid>
+ );
+};
+
+export const AddStorageForm: React.FC<{
+ onSubmit: () => void;
+ header?: React.ReactNode;
+}> = ({ onSubmit, header }) => {
+ const [selectedSchema, setSelectedSchema] = useState<z.ZodType<
+ StorageConnection,
+ FieldValues
+ > | null>(null);
+
+ if (!selectedSchema) {
+ return (
+ <>
+ {header}
+ <div>
+ <StorageProviderSelector onSelect={setSelectedSchema} />
+ </div>
+ </>
+ );
+ }
+
+ const provider = STORAGE_PROVIDERS.find((p) => p.schema === selectedSchema);
+ const libs = provider?.storageLibraries;
+
+ return (
+ <ConnectionForm<StorageConnection, StorageLibrary>
+ schema={selectedSchema}
+ libraries={libs?.libraries ?? []}
+ preferredLibrary={libs?.preferred ?? "obstore"}
+ displayNames={StorageLibraryDisplayNames}
+ libraryLabel="Preferred storage library"
+ generateCode={(values, library) => generateStorageCode(values, library)}
+ onSubmit={onSubmit}
+ onBack={() => setSelectedSchema(null)}
+ />
+ );
+};
diff --git a/frontend/src/components/editor/connections/storage/as-code.ts b/frontend/src/components/editor/connections/storage/as-code.ts
new file mode 100644
index 0000000000..907ed87eeb
--- /dev/null
+++ b/frontend/src/components/editor/connections/storage/as-code.ts
@@ -0,0 +1,188 @@
+/* Copyright 2026 Marimo. All rights reserved. */
+
+import dedent from "string-dedent";
+import { assertNever } from "@/utils/assertNever";
+import { isSecret, unprefixSecret } from "../secrets";
+import { type StorageConnection, StorageConnectionSchema } from "./schemas";
+
+export type StorageLibrary = "obstore" | "fsspec";
+
+export const StorageLibraryDisplayNames: Record<StorageLibrary, string> = {
+ obstore: "Obstore",
+ fsspec: "fsspec",
+};
+
+class SecretContainer {
+ private secrets: Record<string, string> = {};
+
+ get imports(): Set<string> {
+ if (Object.keys(this.secrets).length === 0) {
+ return new Set<string>();
+ }
+ return new Set<string>(["import os"]);
+ }
+
+ print(varName: string, value: string | undefined): string {
+ if (value === undefined || value === "") {
+ return "";
+ }
+ const privateVar = `_${varName}`;
+ if (isSecret(value)) {
+ const envVar = unprefixSecret(value);
+ this.secrets[privateVar] = `os.environ.get("${envVar}")`;
+ return privateVar;
+ }
+ return `"${value}"`;
+ }
+
+ formatSecrets(): string {
+ if (Object.keys(this.secrets).length === 0) {
+ return "";
+ }
+ return Object.entries(this.secrets)
+ .map(([k, v]) => `${k} = ${v}`)
+ .join("\n");
+ }
+}
+
+function generateS3Code(
+ connection: Extract<StorageConnection, { type: "s3" }>,
+ secrets: SecretContainer,
+): { imports: Set<string>; code: string } {
+ const bucket = secrets.print("bucket", connection.bucket);
+ const imports = new Set(["from obstore.store import S3Store"]);
+ const params: string[] = [];
+
+ if (connection.region) {
+ params.push(` region=${secrets.print("region", connection.region)},`);
+ }
+ if (connection.access_key_id) {
+ params.push(
+ ` access_key_id=${secrets.print("access_key_id", connection.access_key_id)},`,
+ );
+ }
+ if (connection.secret_access_key) {
+ params.push(
+ ` secret_access_key=${secrets.print("secret_access_key", connection.secret_access_key)},`,
+ );
+ }
+ if (connection.endpoint_url) {
+ params.push(
+ ` endpoint_url=${secrets.print("endpoint_url", connection.endpoint_url)},`,
+ );
+ }
+
+ const paramsStr = params.length > 0 ? `\n${params.join("\n")}\n` : "";
+
+ const code = dedent(`
+ store = S3Store(${bucket},${paramsStr})
+ `);
+ return { imports, code };
+}
+
+function generateGCSCode(
+ connection: Extract<StorageConnection, { type: "gcs" }>,
+ secrets: SecretContainer,
+): { imports: Set<string>; code: string } {
+ const bucket = secrets.print("bucket", connection.bucket);
+ const imports = new Set(["from obstore.store import GCSStore"]);
+
+ let code: string;
+ if (connection.service_account_key) {
+ imports.add("import json");
+ code = dedent(`
+ _credentials = json.loads("""${connection.service_account_key}""")
+ store = GCSStore(${bucket},
+ service_account_key=_credentials,
+ )
+ `);
+ } else {
+ code = dedent(`
+ store = GCSStore(${bucket})
+ `);
+ }
+ return { imports, code };
+}
+
+function generateAzureCode(
+ connection: Extract<StorageConnection, { type: "azure" }>,
+ secrets: SecretContainer,
+): { imports: Set<string>; code: string } {
+ const container = secrets.print("container", connection.container);
+ const accountName = secrets.print("account_name", connection.account_name);
+ const imports = new Set(["from obstore.store import AzureStore"]);
+ const params: string[] = [`account_name=${accountName},`];
+
+ if (connection.account_key) {
+ params.push(
+ `account_key=${secrets.print("account_key", connection.account_key)},`,
+ );
+ }
+
+ const paramsStr = params.map((p) => ` ${p}`).join("\n");
+
+ const code = `store = AzureStore(${container},\n${paramsStr}\n)`;
+ return { imports, code };
+}
+
+function generateGDriveCode(
+ connection: Extract<StorageConnection, { type: "gdrive" }>,
+ secrets: SecretContainer,
+): { imports: Set<string>; code: string } {
+ const imports = new Set(["from gdrive_fsspec import GoogleDriveFileSystem"]);
+
+ if (connection.credentials_json) {
+ imports.add("import json");
+ const creds = secrets.print(
+ "credentials_json",
+ connection.credentials_json,
+ );
+ const code = dedent(`
+ _creds = json.loads("""${connection.credentials_json?.startsWith("ENV:") ? `{${creds}}` : connection.credentials_json}""")
+ fs = GoogleDriveFileSystem(creds=_creds, token="service_account")
+ `);
+ return { imports, code };
+ }
+
+ const code = dedent(`
+ fs = GoogleDriveFileSystem(token="browser")
+ `);
+ return { imports, code };
+}
+
+export function generateStorageCode(
+ connection: StorageConnection,
+ _library: StorageLibrary,
+): string {
+ StorageConnectionSchema.parse(connection);
+
+ const secrets = new SecretContainer();
+ let result: { imports: Set<string>; code: string };
+
+ switch (connection.type) {
+ case "s3":
+ result = generateS3Code(connection, secrets);
+ break;
+ case "gcs":
+ result = generateGCSCode(connection, secrets);
+ break;
+ case "azure":
+ result = generateAzureCode(connection, secrets);
+ break;
+ case "gdrive":
+ result = generateGDriveCode(connection, secrets);
+ break;
+ default:
+ assertNever(connection);
+ }
+
+ const allImports = new Set([...secrets.imports, ...result.imports]);
+ const lines = [...allImports].sort();
+ lines.push("");
+ const secretsStr = secrets.formatSecrets();
+ if (secretsStr) {
+ lines.push(secretsStr);
+ }
+ lines.push(result.code.trim());
+ return lines.join("\n");
+}
diff --git a/frontend/src/components/editor/connections/storage/schemas.ts b/frontend/src/components/editor/connections/storage/schemas.ts
new file mode 100644
index 0000000000..5da0603789
--- /dev/null
+++ b/frontend/src/components/editor/connections/storage/schemas.ts
@@ -0,0 +1,141 @@
+/* Copyright 2026 Marimo. All rights reserved. */
+import { z } from "zod";
+import { FieldOptions } from "@/components/forms/options";
+
+export const S3StorageSchema = z
+ .object({
+ type: z.literal("s3"),
+ bucket: z
+ .string()
+ .nonempty()
+ .describe(
+ FieldOptions.of({
+ label: "Bucket",
+ placeholder: "my-bucket",
+ }),
+ ),
+ region: z
+ .string()
+ .optional()
+ .describe(
+ FieldOptions.of({
+ label: "Region",
+ placeholder: "us-east-1",
+ optionRegex: ".*region.*",
+ }),
+ ),
+ access_key_id: z
+ .string()
+ .optional()
+ .describe(
+ FieldOptions.of({
+ label: "Access Key ID",
+ inputType: "password",
+ optionRegex: ".*access_key.*",
+ }),
+ ),
+ secret_access_key: z
+ .string()
+ .optional()
+ .describe(
+ FieldOptions.of({
+ label: "Secret Access Key",
+ inputType: "password",
+ optionRegex: ".*secret.*access.*",
+ }),
+ ),
+ endpoint_url: z
+ .string()
+ .optional()
+ .describe(
+ FieldOptions.of({
+ label: "Endpoint URL",
+ placeholder: "https://s3.amazonaws.com",
+ }),
+ ),
+ })
+ .describe(FieldOptions.of({ direction: "two-columns" }));
+
+export const GCSStorageSchema = z
+ .object({
+ type: z.literal("gcs"),
+ bucket: z
+ .string()
+ .nonempty()
+ .describe(
+ FieldOptions.of({
+ label: "Bucket",
+ placeholder: "my-bucket",
+ }),
+ ),
+ service_account_key: z
+ .string()
+ .optional()
+ .describe(
+ FieldOptions.of({
+ label: "Service Account Key (JSON)",
+ inputType: "textarea",
+ }),
+ ),
+ })
+ .describe(FieldOptions.of({ direction: "two-columns" }));
+
+export const AzureStorageSchema = z
+ .object({
+ type: z.literal("azure"),
+ container: z
+ .string()
+ .nonempty()
+ .describe(
+ FieldOptions.of({
+ label: "Container",
+ placeholder: "my-container",
+ }),
+ ),
+ account_name: z
+ .string()
+ .nonempty()
+ .describe(
+ FieldOptions.of({
+ label: "Account Name",
+ placeholder: "storageaccount",
+ optionRegex: ".*account.*",
+ }),
+ ),
+ account_key: z
+ .string()
+ .optional()
+ .describe(
+ FieldOptions.of({
+ label: "Account Key",
+ inputType: "password",
+ optionRegex: ".*azure.*key.*",
+ }),
+ ),
+ })
+ .describe(FieldOptions.of({ direction: "two-columns" }));
+
+export const GoogleDriveStorageSchema = z
+ .object({
+ type: z.literal("gdrive"),
+ credentials_json: z
+ .string()
+ .optional()
+ .describe(
+ FieldOptions.of({
+ label: "Service Account JSON",
+ description: "Leave empty to use browser-based authentication",
+ inputType: "textarea",
+ }),
+ ),
+ })
+ .describe(FieldOptions.of({ direction: "two-columns" }));
+
+export const StorageConnectionSchema = z.discriminatedUnion("type", [
+ S3StorageSchema,
+ GCSStorageSchema,
+ AzureStorageSchema,
+ GoogleDriveStorageSchema,
+]);
+
+export type StorageConnection = z.infer<typeof StorageConnectionSchema>;
diff --git a/frontend/src/components/editor/database/add-database-form.tsx b/frontend/src/components/editor/database/add-database-form.tsx
deleted file mode 100644
index 543d524faf..0000000000
--- a/frontend/src/components/editor/database/add-database-form.tsx
+++ /dev/null
@@ -1,420 +0,0 @@
-/* Copyright 2026 Marimo. All rights reserved. */
-
-import { zodResolver } from "@hookform/resolvers/zod";
-import { useState } from "react";
-import { useForm } from "react-hook-form";
-import type { z } from "zod";
-import { DatabaseLogo, type DBLogoName } from "@/components/databases/icon";
-import { type FormRenderer, ZodForm } from "@/components/forms/form";
-import { getDefaults } from "@/components/forms/form-utils";
-import { Button } from "@/components/ui/button";
-import {
- Dialog,
- DialogContent,
- DialogDescription,
- DialogHeader,
- DialogTitle,
- DialogTrigger,
-} from "@/components/ui/dialog";
-import { FormErrorsBanner } from "@/components/ui/form";
-import { ExternalLink } from "@/components/ui/links";
-import {
- Select,
- SelectContent,
- SelectGroup,
- SelectItem,
- SelectTrigger,
- SelectValue,
-} from "@/components/ui/select";
-import { useCellActions } from "@/core/cells/cells";
-import { useLastFocusedCellId } from "@/core/cells/focus";
-import {
- ConnectionDisplayNames,
- type ConnectionLibrary,
- generateDatabaseCode,
-} from "./as-code";
-import { ENV_RENDERER, SecretsProvider } from "./form-renderers";
-import {
- BigQueryConnectionSchema,
- ChdbConnectionSchema,
- ClickhouseConnectionSchema,
- type DatabaseConnection,
- DatabricksConnectionSchema,
- DataFusionConnectionSchema,
- DuckDBConnectionSchema,
- IcebergConnectionSchema,
- MotherDuckConnectionSchema,
- MySQLConnectionSchema,
- PostgresConnectionSchema,
- PySparkConnectionSchema,
- RedshiftConnectionSchema,
- SnowflakeConnectionSchema,
- SQLiteConnectionSchema,
- SupabaseConnectionSchema,
- TimeplusConnectionSchema,
- TrinoConnectionSchema,
-} from "./schemas";
-
-interface Props {
- onSubmit: () => void;
-}
-
-interface ConnectionSchema {
- name: string;
- schema: z.ZodType<DatabaseConnection>;
- color: string;
- logo: DBLogoName;
- connectionLibraries: {
- libraries: ConnectionLibrary[];
- preferred: ConnectionLibrary;
- };
-}
-
-// default to sqlalchemy because it has fewer dependencies
-const DATABASES = [
- {
- name: "PostgreSQL",
- schema: PostgresConnectionSchema,
- color: "#336791",
- logo: "postgres",
- connectionLibraries: {
- libraries: ["sqlalchemy", "sqlmodel"],
- preferred: "sqlalchemy",
- },
- },
- {
- name: "MySQL",
- schema: MySQLConnectionSchema,
- color: "#00758F",
- logo: "mysql",
- connectionLibraries: {
- libraries: ["sqlalchemy", "sqlmodel"],
- preferred: "sqlalchemy",
- },
- },
- {
- name: "SQLite",
- schema: SQLiteConnectionSchema,
- color: "#003B57",
- logo: "sqlite",
- connectionLibraries: {
- libraries: ["sqlalchemy", "sqlmodel"],
- preferred: "sqlalchemy",
- },
- },
- {
- name: "DuckDB",
- schema: DuckDBConnectionSchema,
- color: "#FFD700",
- logo: "duckdb",
- connectionLibraries: {
- libraries: ["duckdb"],
- preferred: "duckdb",
- },
- },
- {
- name: "MotherDuck",
- schema: MotherDuckConnectionSchema,
- color: "#ff9538",
- logo: "motherduck",
- connectionLibraries: {
- libraries: ["duckdb"],
- preferred: "duckdb",
- },
- },
- {
- name: "Snowflake",
- schema: SnowflakeConnectionSchema,
- color: "#29B5E8",
- logo: "snowflake",
- connectionLibraries: {
- libraries: ["sqlalchemy", "sqlmodel"],
- preferred: "sqlalchemy",
- },
- },
- {
- name: "ClickHouse",
- schema: ClickhouseConnectionSchema,
- color: "#2C2C1D",
- logo: "clickhouse",
- connectionLibraries: {
- libraries: ["clickhouse_connect"],
- preferred: "clickhouse_connect",
- },
- },
- {
- name: "Timeplus",
- schema: TimeplusConnectionSchema,
- color: "#B83280",
- logo: "timeplus",
- connectionLibraries: {
- libraries: ["sqlalchemy", "sqlmodel"],
- preferred: "sqlalchemy",
- },
- },
- {
- name: "BigQuery",
- schema: BigQueryConnectionSchema,
- color: "#4285F4",
- logo: "bigquery",
- connectionLibraries: {
- libraries: ["sqlalchemy", "sqlmodel"],
- preferred: "sqlalchemy",
- },
- },
- {
- name: "ClickHouse Embedded",
- schema: ChdbConnectionSchema,
- color: "#f2b611",
- logo: "clickhouse",
- connectionLibraries: {
- libraries: ["chdb"],
- preferred: "chdb",
- },
- },
- {
- name: "Trino",
- schema: TrinoConnectionSchema,
- color: "#d466b6",
- logo: "trino",
- connectionLibraries: {
- libraries: ["sqlalchemy", "sqlmodel"],
- preferred: "sqlalchemy",
- },
- },
- {
- name: "DataFusion",
- schema: DataFusionConnectionSchema,
- color: "#202A37",
- logo: "datafusion",
- connectionLibraries: {
- libraries: ["ibis"],
- preferred: "ibis",
- },
- },
- {
- name: "PySpark",
- schema: PySparkConnectionSchema,
- color: "#1C5162",
- logo: "pyspark",
- connectionLibraries: {
- libraries: ["ibis"],
- preferred: "ibis",
- },
- },
- {
- name: "Redshift",
- schema: RedshiftConnectionSchema,
- color: "#522BAE",
- logo: "redshift",
- connectionLibraries: {
- libraries: ["redshift"],
- preferred: "redshift",
- },
- },
- {
- name: "Databricks",
- schema: DatabricksConnectionSchema,
- color: "#c41e0c",
- logo: "databricks",
- connectionLibraries: {
- libraries: ["sqlalchemy", "sqlmodel", "ibis"],
- preferred: "sqlalchemy",
- },
- },
- {
- name: "Supabase",
- schema: SupabaseConnectionSchema,
- color: "#238F5F",
- logo: "supabase",
- connectionLibraries: {
- libraries: ["sqlalchemy", "sqlmodel"],
- preferred: "sqlalchemy",
- },
- },
-] satisfies ConnectionSchema[];
-
-const DATA_CATALOGS = [
- {
- name: "Iceberg",
- schema: IcebergConnectionSchema,
- color: "#000000",
- logo: "iceberg",
- connectionLibraries: {
- libraries: ["pyiceberg"],
- preferred: "pyiceberg",
- },
- },
-] satisfies ConnectionSchema[];
-
-const DatabaseSchemaSelector: React.FC<{
- onSelect: (schema: z.ZodType<DatabaseConnection>) => void;
-}> = ({ onSelect }) => {
- const renderItem = ({ name, schema, color, logo }: ConnectionSchema) => {
- return (
- <button
- type="button"
- key={name}
- className="py-3 flex flex-col items-center justify-center gap-1 transition-all hover:scale-105 hover:brightness-110 rounded shadow-sm-solid hover:shadow-md-solid"
- style={{ backgroundColor: color }}
- onClick={() => onSelect(schema)}
- >
- <DatabaseLogo
- name={logo}
- className="w-8 h-8 text-white brightness-0 invert dark:invert"
- />
- <span className="text-white font-medium text-lg">{name}</span>
- </button>
- );
- };
-
- return (
- <>
- <div className="grid grid-cols-2 md:grid-cols-3 gap-4">
- {DATABASES.map(renderItem)}
- </div>
- <h4 className="font-semibold text-muted-foreground text-lg flex items-center gap-4">
- Data Catalogs
- <hr className="flex-1" />
- </h4>
- <div className="grid grid-cols-2 md:grid-cols-3 gap-4">
- {DATA_CATALOGS.map(renderItem)}
- </div>
- </>
- );
-};
-
-const RENDERERS: FormRenderer[] = [ENV_RENDERER];
-
-const DatabaseForm: React.FC<{
- schema: z.ZodType<DatabaseConnection>;
- onSubmit: () => void;
- onBack: () => void;
-}> = ({ schema, onSubmit, onBack }) => {
- const form = useForm<DatabaseConnection>({
- defaultValues: getDefaults(schema),
- resolver: zodResolver(
- schema as unknown as z.ZodType<unknown, DatabaseConnection>,
- ),
- reValidateMode: "onChange",
- });
-
- const connectionLibraries = [...DATABASES, ...DATA_CATALOGS].find(
- (s) => s.schema === schema,
- )?.connectionLibraries;
- const [preferredConnection, setPreferredConnection] =
- useState<ConnectionLibrary>(connectionLibraries?.preferred ?? "sqlalchemy");
-
- const { createNewCell } = useCellActions();
- const lastFocusedCellId = useLastFocusedCellId();
-
- const handleInsertCode = (code: string) => {
- createNewCell({
- code,
- before: false,
- cellId: lastFocusedCellId ?? "__end__",
- skipIfCodeExists: true,
- });
- };
-
- const handleSubmit = (values: DatabaseConnection) => {
- handleInsertCode(generateDatabaseCode(values, preferredConnection));
- onSubmit();
- };
-
- return (
- <form onSubmit={form.handleSubmit(handleSubmit)} className="space-y-4">
- <SecretsProvider>
- <ZodForm schema={schema} form={form} renderers={RENDERERS}>
- <FormErrorsBanner />
- </ZodForm>
- </SecretsProvider>
- <div className="flex gap-2 justify-between">
- <div className="flex gap-2">
- <Button type="button" variant="outline" onClick={onBack}>
- Back
- </Button>
- <Button type="submit" disabled={!form.formState.isValid}>
- Add
- </Button>
- </div>
- <div>
- <Select
- value={preferredConnection}
- onValueChange={(value) =>
- setPreferredConnection(value as ConnectionLibrary)
- }
- >
- <div className="flex flex-col gap-1 items-end">
- <SelectTrigger>
- <SelectValue placeholder="Select a library" />
- </SelectTrigger>
- <span className="text-xs text-muted-foreground">
- Preferred connection library
- </span>
- </div>
- <SelectContent>
- <SelectGroup>
- {connectionLibraries?.libraries.map((library) => (
- <SelectItem key={library} value={library}>
- {ConnectionDisplayNames[library]}
- </SelectItem>
- ))}
- </SelectGroup>
- </SelectContent>
- </Select>
- </div>
- </div>
- </form>
- );
-};
-
-const AddDatabaseForm: React.FC<Props> = ({ onSubmit }) => {
- const [selectedSchema, setSelectedSchema] =
- useState<z.ZodType<DatabaseConnection> | null>(null);
-
- if (!selectedSchema) {
- return <DatabaseSchemaSelector onSelect={setSelectedSchema} />;
- }
-
- return (
- <DatabaseForm
- schema={selectedSchema}
- onSubmit={onSubmit}
- onBack={() => setSelectedSchema(null)}
- />
- );
-};
-
-export const AddDatabaseDialog: React.FC<{
- children: React.ReactNode;
-}> = ({ children }) => {
- const [open, setOpen] = useState(false);
-
- return (
- <Dialog open={open} onOpenChange={setOpen}>
- <DialogTrigger asChild={true}>{children}</DialogTrigger>
- <AddDatabaseDialogContent onClose={() => setOpen(false)} />
- </Dialog>
- );
-};
-
-export const AddDatabaseDialogContent: React.FC<{
- onClose: () => void;
-}> = ({ onClose }) => {
- return (
- <DialogContent className="max-h-[75vh] overflow-y-auto">
- <DialogHeader className="mb-4">
- <DialogTitle>Add Connection</DialogTitle>
- <DialogDescription>
- Connect to your database or data catalog to query data directly from
- your notebook. Learn more about how to connect to your database in our{" "}
- <ExternalLink href="https://docs.marimo.io/guides/working_with_data/sql/#connecting-to-a-custom-database">
- docs.
- </ExternalLink>
- </DialogDescription>
- </DialogHeader>
- <AddDatabaseForm onSubmit={() => onClose()} />
- </DialogContent>
- );
-};
diff --git a/frontend/src/components/storage/components.tsx b/frontend/src/components/storage/components.tsx
index a8576ae156..b37d0018d9 100644
--- a/frontend/src/components/storage/components.tsx
+++ b/frontend/src/components/storage/components.tsx
@@ -19,8 +19,10 @@ import {
ImageIcon,
} from "lucide-react";
import GoogleCloudIcon from "@/components/databases/icons/google-cloud-storage.svg?inline";
+import GoogleDriveIcon from "@/components/databases/icons/google-drive.svg?inline";
import type { KnownStorageProtocol } from "@/core/storage/types";
import { useTheme } from "@/theme/useTheme";
+import { cn } from "@/utils/cn";
export function renderFileIcon(name: string): React.ReactNode {
const ext = name.split(".").pop()?.toLowerCase();
@@ -67,12 +69,14 @@ const PROTOCOL_ICONS: Record<KnownStorageProtocol, IconEntry> = {
http: GlobeIcon,
file: HardDriveIcon,
"in-memory": DatabaseZapIcon,
+ gdrive: { src: GoogleDriveIcon },
github: GithubIcon,
};
export const ProtocolIcon: React.FC<{
protocol: KnownStorageProtocol | (string & {});
-}> = ({ protocol }) => {
+ className?: string;
+}> = ({ protocol, className }) => {
const { theme } = useTheme();
const entry =
PROTOCOL_ICONS[protocol.toLowerCase() as KnownStorageProtocol] ??
@@ -80,9 +84,11 @@ export const ProtocolIcon: React.FC<{
if ("src" in entry) {
const src = theme === "dark" && entry.dark ? entry.dark : entry.src;
- return <img src={src} alt={protocol} className="h-3.5 w-3.5" />;
+ return (
+ <img src={src} alt={protocol} className={cn("h-3.5 w-3.5", className)} />
+ );
}
const Icon = entry;
- return <Icon className="h-3.5 w-3.5" />;
+ return <Icon className={cn("h-3.5 w-3.5", className)} />;
};
diff --git a/frontend/src/components/storage/storage-inspector.tsx b/frontend/src/components/storage/storage-inspector.tsx
index a4ba152a84..f0b497ea4c 100644
--- a/frontend/src/components/storage/storage-inspector.tsx
+++ b/frontend/src/components/storage/storage-inspector.tsx
@@ -10,6 +10,7 @@ import {
HelpCircleIcon,
LoaderCircle,
MoreVerticalIcon,
+ PlusIcon,
RefreshCwIcon,
ViewIcon,
XIcon,
@@ -18,6 +19,7 @@ import React, { useCallback, useState } from "react";
import { useLocale } from "react-aria";
import { EngineVariable } from "@/components/databases/engine-variable";
import { PanelEmptyState } from "@/components/editor/chrome/panels/empty-state";
+import { AddConnectionDialog } from "@/components/editor/connections/add-connection-dialog";
import { Command, CommandInput, CommandItem } from "@/components/ui/command";
import {
DropdownMenu,
@@ -550,6 +552,14 @@ export const StorageInspector: React.FC = () => {
.
</span>
}
+ action={
+ <AddConnectionDialog defaultTab="storage">
+ <Button variant="outline" size="sm">
+ Add remote storage
+ <PlusIcon className="h-4 w-4 ml-2" />
+ </Button>
+ </AddConnectionDialog>
+ }
icon={<HardDriveIcon className="h-8 w-8" />}
/>
);
@@ -595,8 +605,17 @@ export const StorageInspector: React.FC = () => {
content="Filters loaded entries only. Expand directories to include their contents in the search."
delayDuration={200}
>
- <HelpCircleIcon className="h-3.5 w-3.5 mr-2 shrink-0 cursor-help text-muted-foreground hover:text-foreground" />
+ <HelpCircleIcon className="h-3.5 w-3.5 shrink-0 cursor-help text-muted-foreground hover:text-foreground mr-2" />
</Tooltip>
+ <AddConnectionDialog defaultTab="storage">
+ <Button
+ variant="ghost"
+ size="sm"
+ className="px-2 border-0 border-l border-muted-background rounded-none focus-visible:ring-0 focus-visible:ring-offset-0"
+ >
+ <PlusIcon className="h-4 w-4" />
+ </Button>
+ </AddConnectionDialog>
</div>
<CommandList className="flex flex-col">
{namespaces.map((ns) => (
diff --git a/frontend/src/core/storage/types.ts b/frontend/src/core/storage/types.ts
index c1c8230588..f8514c947a 100644
--- a/frontend/src/core/storage/types.ts
+++ b/frontend/src/core/storage/types.ts
@@ -54,5 +54,6 @@ export type KnownStorageProtocol =
| "cloudflare"
| "http"
| "file"
+ | "gdrive"
| "in-memory"
| "github";