Skip to content

These examples demonstrate how to use the Cloudflare API within interactive Python notebooks.

License

Notifications You must be signed in to change notification settings

cloudflare/notebook-examples

Notebook Examples

Interactive Python notebooks demonstrating Cloudflare services, APIs, and workflows. These examples cover tasks from analyzing logs to writing billing reports, storing files in R2, querying D1 databases, and more!

πŸ› οΈ Development

Prerequisites

Python Packages

  • marimo notebook server
  • moutils OAuth login and other utilities
  • uv for uv builds

Running Notebooks

notebooks.cloudflare.com

Visit notebooks.cloudflare.com to run notebooks directly in your browser using WASM.

This deployment is automatic whenever changes are merged to the main branch

Python Development Mode

make edit

Security Testing

make security-test
  • Starts local server for PKCE security integration tests
  • Tests OAuth authentication flow with security protections
  • See SECURITY-TEST.md for details
  • Full Python environment with all packages
  • Best for development and testing

WASM Preview Mode

make export
make preview
  • Builds notebooks for web deployment
  • Runs locally to preview WASM version
  • Matches production environment

Single Notebook Mode

# Using Python venv
make edit-notebook notebook=_start.py

# Using uv (faster setup)
make edit-uv-notebook notebook=_start.py

Available Commands

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
πŸ›   Running: help
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Main workflow:
edit                 [PYTHON][WORKSPACE][*] Launch marimo edit in workspace mode
export               [WASM BUILD][*] Build HTML/WASM and show preview instructions
preview              [WASM SERVE][*] Serve the exported notebooks locally

Other commands:
clean-deep           Deep clean including removal of the Python virtual environment
clean                Remove temporary files, caches, and build artifacts
deploy               Run lint, build HTML/WASM, and deploy via npm
edit-notebook        [PYTHON][NOTEBOOK] Launch marimo edit for a specific notebook (default: _start.py)
edit-uv-notebook     [PYTHON][NOTEBOOK] Launch marimo with uv for a specific notebook (default: _start.py)
edit-uv-workspace    [PYTHON][WORKSPACE] Launch marimo with uv in workspace mode
lint                 Run Python and JavaScript linters
venv                 Alias to set up Python virtual environment

🀝 Contributing

We welcome contributions! Please see our Contributing Guidelines for details on how to submit pull requests, report issues, and contribute to this project.

πŸ“ Adding New Notebooks

  1. Create your notebook in the notebooks/ directory
  2. Add to configuration in notebooks.yaml:
    - title: "My New Notebook"
      description: "Description of what it does"
      file: "my_notebook.py"
  3. Test python locally: make edit
  4. Test WASM locally: make export && make preview
  5. Submit a PR with your changes. See

πŸ”§ Technical Details

Architecture

  • Local Development: Python virtual environment with Marimo
  • Web Deployment: WASM compilation using Pyodide
  • Hosting: Cloudflare Workers at notebooks.cloudflare.com

Package Management

  • Local: Standard pip/requirements.txt
  • WASM: Pre-installed packages in Pyodide (see package list)

πŸ“– Documentation

πŸ› Troubleshooting

Common Issues

"Command not found: make"

  • Install Make: brew install make (macOS) or apt-get install make (Ubuntu)

Port 2718 already in use

  • Kill existing process: lsof -ti:2718 | xargs kill
  • Or use different port: make edit (edit Makefile to change port)

WASM build fails

  • Clean and rebuild: make clean && make export
  • Check package compatibility with Pyodide (see package list)

Virtual environment issues

  • Recreate environment: make clean-deep && make venv

πŸ“ž Community

Connect with Cloudflare and the community:

About

These examples demonstrate how to use the Cloudflare API within interactive Python notebooks.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Contributors 4

  •  
  •  
  •  
  •