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.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
docs: publish to cloudflare workers (#4676)
Myles Scolnicke06e808d4208
diff --git a/docs/guides/exporting.md b/docs/guides/exporting.mdindex dabacb0fa5..019edbb0ae 100644--- a/docs/guides/exporting.md+++ b/docs/guides/exporting.md@@ -187,7 +187,7 @@ Options:cannot be opened directly from the filesystem (`file://`). Your server mustalso serve the assets in the `assets` directory, next to the HTML file. Fora simpler publishing experience, publish to [GitHub- Pages](publishing/github_pages.md), [Cloudflare Pages](publishing/cloudflare_pages.md) or use the [online+ Pages](publishing/github_pages.md), [Cloudflare](publishing/cloudflare.md) or use the [onlineplayground](publishing/playground.md).??? note "Deploying to Cloudflare"diff --git a/docs/guides/publishing/cloudflare.md b/docs/guides/publishing/cloudflare.mdnew file mode 100644index 0000000000..cb11ff7062--- /dev/null+++ b/docs/guides/publishing/cloudflare.md@@ -0,0 +1,95 @@+# Publish to Cloudflare++You can publish executable notebooks to [Cloudflare Workers](https://workers.cloudflare.com/)+for free, after exporting your notebook to a WebAssembly notebook.++## Export to WASM-powered HTML++Export your notebook to a self-contained HTML file that runs using [WebAssembly](../wasm.md) with the flag `--include-cloudflare`:++/// tab | Export as a readonly app++```bash+marimo export html-wasm notebook.py -o output_dir --mode run --include-cloudflare+```++///++/// tab | Export as an editable notebook++```bash+marimo export html-wasm notebook.py -o output_dir --mode edit --include-cloudflare+```++///++See our [exporting guide](../exporting.md#export-to-wasm-powered-html) for+the full documentation.++## Publish to a Cloudflare Worker++When you use the `--include-cloudflare` flag, marimo creates two additional files in the parent directory of your output directory:++- `index.js`: A simple Cloudflare Worker script that serves your static assets+- `wrangler.jsonc`: Configuration for Cloudflare's Wrangler CLI++To run locally, run:++```bash+npx wrangler dev+```++To deploy to Cloudflare, run:++```bash+npx wrangler deploy+```++/// admonition | Need authentication or custom endpoints?+ type: tip++You can modify the `index.js` to include authentication or custom endpoints. This allows you to:++- Add authentication logic to protect your notebook+- Create API endpoints that serve data from the same domain, avoiding CORS issues++## Publish to Cloudflare Pages using GitHub++As an alternative to Cloudflare Workers, you can publish to Cloudflare Pages. To get started, create a new GitHub repository by visiting [repo.new](https://repo.new/) . After creating a new repository, go to your newly created project directory to prepare and push your local application to GitHub by running the following commands in your terminal:++```bash+cd output_dir+git init+git remote add origin https://github.com/<your-gh-username>/<repository-name>+git add .+git commit -m "Initial commit"+git branch -M main+git push -u origin main++```++To deploy your site to Pages:++1. Log in to the Cloudflare [Dashboard](https://dash.cloudflare.com) and select your account.+2. In Account Home, select Workers & Pages > Create application > Pages > Connect to Git.+3. Select the new GitHub repository that you created and, in the Set up builds and deployments section, provide the following information:++```+Project name output-dir+Production branch main+Framework preset None+Build command (optional) exit 0+Build output directory /+```++4. Save and Deploy++## Publish to Cloudflare Pages Manually++To deploy your site to Pages:++1. Create zip of the folder "output_dir"+2. Log in to the Cloudflare [Dashboard](https://dash.cloudflare.com) and select your account.+3. In Account Home, select Workers & Pages > Create application > Pages > Upload asset.+4. Enter a project name then click Upload and select output_dir.zip .+5. Save and Deploydiff --git a/docs/guides/publishing/cloudflare_pages.md b/docs/guides/publishing/cloudflare_pages.mddeleted file mode 100644index 29afd19cc6..0000000000--- a/docs/guides/publishing/cloudflare_pages.md+++ /dev/null@@ -1,68 +0,0 @@-# Publish to Cloudflare Pages--You can publish executable notebooks to [Cloudflare Pages](https://pages.cloudflare.com/)-for free, after exporting your notebook to a WebAssembly notebook.--## Export to WASM-powered HTML--Export your notebook to a self-contained HTML file that runs using [WebAssembly](../wasm.md):--/// tab | Export as a readonly app--```bash-marimo export html-wasm notebook.py -o output_dir --mode run-```--///--/// tab | Export as an editable notebook--```bash-marimo export html-wasm notebook.py -o output_dir --mode edit-```--///--See our [exporting guide](../exporting.md#export-to-wasm-powered-html) for-the full documentation.--## Publish to Cloudflare Pages using GitHub--Create a new GitHub repository by visiting [repo.new](https://repo.new/) . After creating a new repository, go to your newly created project directory to prepare and push your local application to GitHub by running the following commands in your terminal:--```-cd output_dir-git init-git remote add origin https://github.com/<your-gh-username>/<repository-name>-git add .-git commit -m "Initial commit"-git branch -M main-git push -u origin main--```--To deploy your site to Pages:--1. Log in to the Cloudflare [Dashboard](https://dash.cloudflare.com) and select your account.-2. In Account Home, select Workers & Pages > Create application > Pages > Connect to Git.-3. Select the new GitHub repository that you created and, in the Set up builds and deployments section, provide the following information:--```-Project name output-dir-Production branch main-Framework preset None-Build command (optional) exit 0-Build output directory /-```--4. Save and Deploy--## Publish Manually--To deploy your site to Pages:--1. Create zip of the folder "output_dir"-2. Log in to the Cloudflare [Dashboard](https://dash.cloudflare.com) and select your account.-3. In Account Home, select Workers & Pages > Create application > Pages > Upload asset.-4. Enter a project name then click Upload and select output_dir.zip .-5. Save and Deploy\ No newline at end of filediff --git a/docs/guides/publishing/index.md b/docs/guides/publishing/index.mdindex ad39638d68..6ff802e8d9 100644--- a/docs/guides/publishing/index.md+++ b/docs/guides/publishing/index.md@@ -16,7 +16,7 @@ This guide provides an overview of the various ways to publish marimo notebooks.| [From GitHub](from_github.md) | Share links to executable notebooks hosted on GitHub || [From code snippets](from_code_snippets.md) | Convert code snippets in Markdown or HTML to interactive notebooks || [GitHub Pages](github_pages.md) | Publish interactive notebooks on GitHub Pages |-| [Cloudflare Pages](cloudflare_pages.md) | Publish interactive notebooks on Cloudflare Pages |+| [Cloudflare](cloudflare.md) | Publish interactive notebooks on Cloudflare || [Online playground](playground.md) | Share links to notebooks using our online playground || [Community Cloud](community_cloud/index.md) | Save notebooks to our free Community Cloud || [Self-host WebAssembly notebooks](self_host_wasm.md) | Self-hosting interactive WebAssembly (HTML export) notebooks |diff --git a/mkdocs.yml b/mkdocs.ymlindex 32e51ff1bb..cec2c6b5e9 100644--- a/mkdocs.yml+++ b/mkdocs.yml@@ -126,7 +126,7 @@ nav:- From code snippets: guides/publishing/from_code_snippets.md- From GitHub: guides/publishing/from_github.md- GitHub Pages: guides/publishing/github_pages.md- - Cloudflare Pages: guides/publishing/cloudflare_pages.md+ - Cloudflare: guides/publishing/cloudflare.md- Online playground: guides/publishing/playground.md- Community Cloud: guides/publishing/community_cloud/index.md- Self-host WASM: guides/publishing/self_host_wasm.md