|
1 | | -# python-notebook-boilerplate |
| 1 | +# python-notebook-boilerplate |
| 2 | + |
| 3 | +Made with ♥ by Wonderland (https://defi.sucks) |
| 4 | + |
| 5 | +Data exploration boilerplate using Marimo notebooks, Polars, and Altair. |
| 6 | + |
| 7 | +## Features |
| 8 | + |
| 9 | +- **[Marimo](https://marimo.io/)** - Reactive Python notebooks as pure `.py` files |
| 10 | +- **[Polars](https://pola.rs/)** - Fast DataFrame library (Rust-powered) |
| 11 | +- **[Altair](https://altair-viz.github.io/)** - Declarative statistical visualization |
| 12 | +- **[uv](https://docs.astral.sh/uv/)** - Fast Python package manager |
| 13 | +- **Ruff** - Linting and formatting |
| 14 | +- **Pre-commit hooks** - Code quality checks |
| 15 | +- **[Commitizen](https://commitizen-tools.github.io/commitizen/)** - Conventional commits enforcement |
| 16 | +- **GitHub Actions CI** - Automated linting and commit validation |
| 17 | + |
| 18 | +## Quick Start |
| 19 | + |
| 20 | +### Prerequisites |
| 21 | + |
| 22 | +- Python 3.12+ |
| 23 | +- [uv](https://docs.astral.sh/uv/getting-started/installation/): |
| 24 | + |
| 25 | +```bash |
| 26 | +curl -LsSf https://astral.sh/uv/install.sh | sh |
| 27 | +``` |
| 28 | + |
| 29 | +### Setup |
| 30 | + |
| 31 | +```bash |
| 32 | +# Clone the repo |
| 33 | +git clone https://github.com/defi-wonderland/python-notebook-boilerplate.git |
| 34 | +cd python-notebook-boilerplate |
| 35 | + |
| 36 | +# Install dependencies |
| 37 | +uv sync |
| 38 | + |
| 39 | +# Setup environment variables |
| 40 | +cp .env.example .env |
| 41 | + |
| 42 | +# Install pre-commit hooks (including commit message linting) |
| 43 | +uv run pre-commit install --hook-type pre-commit --hook-type commit-msg |
| 44 | + |
| 45 | +# Start exploring! |
| 46 | +uv run marimo edit notebooks/example.py |
| 47 | +``` |
| 48 | + |
| 49 | +## Usage |
| 50 | + |
| 51 | +### Editing Notebooks |
| 52 | + |
| 53 | +Open a notebook in the interactive editor: |
| 54 | + |
| 55 | +```bash |
| 56 | +uv run marimo edit notebooks/example.py |
| 57 | +``` |
| 58 | + |
| 59 | +### Sharing as Web App |
| 60 | + |
| 61 | +Serve a notebook as an interactive web application: |
| 62 | + |
| 63 | +```bash |
| 64 | +uv run marimo run notebooks/example.py |
| 65 | +``` |
| 66 | + |
| 67 | +Others can interact with it in their browser without needing Python installed. |
| 68 | + |
| 69 | +### Export Options |
| 70 | + |
| 71 | +```bash |
| 72 | +# Export to static HTML |
| 73 | +uv run marimo export html notebooks/example.py -o output.html |
| 74 | + |
| 75 | +# Export to WASM (runs entirely in browser) |
| 76 | +uv run marimo export html-wasm notebooks/example.py -o output/ |
| 77 | +``` |
| 78 | + |
| 79 | +## Project Structure |
| 80 | + |
| 81 | +``` |
| 82 | +python-notebook-boilerplate/ |
| 83 | +├── .github/ |
| 84 | +│ └── workflows/ |
| 85 | +│ └── ci.yml # Format + lint checks |
| 86 | +├── notebooks/ |
| 87 | +│ └── example.py # Sample marimo notebook |
| 88 | +├── src/ |
| 89 | +│ └── helpers/ # Shared utility functions |
| 90 | +│ └── __init__.py |
| 91 | +├── data/ # Local data (gitignored) |
| 92 | +│ └── .gitkeep |
| 93 | +├── .env.example # Environment template |
| 94 | +├── .pre-commit-config.yaml # Pre-commit hooks |
| 95 | +├── pyproject.toml # Dependencies + tool config |
| 96 | +└── README.md |
| 97 | +``` |
| 98 | + |
| 99 | +## Development |
| 100 | + |
| 101 | +### Code Quality |
| 102 | + |
| 103 | +```bash |
| 104 | +# Format code |
| 105 | +uv run ruff format . |
| 106 | + |
| 107 | +# Lint code |
| 108 | +uv run ruff check . |
| 109 | + |
| 110 | +# Lint and auto-fix |
| 111 | +uv run ruff check . --fix |
| 112 | + |
| 113 | +# Run all pre-commit checks |
| 114 | +uv run pre-commit run --all-files |
| 115 | +``` |
| 116 | + |
| 117 | +### Commits |
| 118 | + |
| 119 | +This project uses [Conventional Commits](https://www.conventionalcommits.org/). Commit messages are validated locally via pre-commit hooks and in CI. |
| 120 | + |
| 121 | +```bash |
| 122 | +# Interactive commit (recommended) |
| 123 | +uv run cz commit |
| 124 | + |
| 125 | +# Or write manually following the format: |
| 126 | +# <type>(<scope>): <subject> |
| 127 | +# |
| 128 | +# Examples: |
| 129 | +# feat: add new data loader |
| 130 | +# fix(charts): resolve axis scaling issue |
| 131 | +# docs: update README with examples |
| 132 | +``` |
| 133 | + |
| 134 | +**Allowed types:** `feat`, `fix`, `docs`, `style`, `refactor`, `perf`, `test`, `build`, `ci`, `chore`, `revert` |
| 135 | + |
| 136 | +### Adding Dependencies |
| 137 | + |
| 138 | +```bash |
| 139 | +# Add a production dependency |
| 140 | +uv add pandas |
| 141 | + |
| 142 | +# Add a dev dependency |
| 143 | +uv add --dev pytest |
| 144 | +``` |
| 145 | + |
| 146 | +## CI |
| 147 | + |
| 148 | +This repo includes GitHub Actions CI that runs on every push and PR: |
| 149 | + |
| 150 | +- **Commit lint** - Validates commit messages follow Conventional Commits (PRs only) |
| 151 | +- **Format check** - Ensures code is formatted with Ruff |
| 152 | +- **Lint** - Static analysis with Ruff |
| 153 | + |
| 154 | +## Creating New Notebooks |
| 155 | + |
| 156 | +```bash |
| 157 | +# Create a new notebook |
| 158 | +uv run marimo edit notebooks/my-analysis.py |
| 159 | +``` |
| 160 | + |
| 161 | +Marimo notebooks are pure Python files, so they: |
| 162 | +- Work with git (no JSON merge conflicts) |
| 163 | +- Can be imported as modules |
| 164 | +- Can be run as scripts |
| 165 | + |
| 166 | +## License |
| 167 | + |
| 168 | +MIT - See [LICENSE](LICENSE) |
| 169 | + |
0 commit comments