cloudflare/notebook-examples
Python
Captured source
source ↗cloudflare/notebook-examples
Description: These examples demonstrate how to use the Cloudflare API within interactive Python notebooks.
Language: Python
License: MIT
Stars: 25
Forks: 3
Open issues: 9
Created: 2022-11-16T10:11:38Z
Pushed: 2026-06-03T09:21:55Z
Default branch: main
Fork: no
Archived: no
README: > Notebooks was an experiment in running interactive Python against the Cloudflare API, right from your browser. We're winding it down on August 1, 2026, after which notebooks.cloudflare.com will go offline. Thank you for playing along. > > The example notebooks will remain on GitHub. You can find us on Discord. 👋
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 3.8+
- Node.js for WASM builds
- Git
Python Packages
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
- Starts Marimo server on http://localhost:2718
Security Testing
make security-test
- Starts local server for PKCE security integration tests
- Tests OAuth authentication flow with security protections
- See [SECURITY-TEST.md](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](CONTRIBUTING.md) 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
- [Cloudflare API Docs](https://developers.cloudflare.com/api/): Complete API reference
- [Marimo Documentation](https://docs.marimo.io/): Notebook framework guide
- [Pyodide Documentation](https://pyodide.org/): Python in the browser
🐛 Troubleshooting
Common Issues
"Command not found: make"
- Install Make:
brew install make(macOS) orapt-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:
- Discord: Join our Discord server
- Twitter: @Cloudflare and @CloudflareDev
- GitHub: Cloudflare organization
- Blog: Cloudflare Blog
- Developer Hub: developers.cloudflare.com