Creating Python boilerplate
The user needs boilerplate for a Python data science project using Jupyter and Poetry. I should provide a clear structure including a pyproject.toml skeleton and some instructions. It's crucial to balance thoroughness without being overly verbose.
I'll suggest a directory tree, a minimal pyproject.toml with essential dependencies like JupyterLab, pandas, and others, and I'll clarify how to use Poetry groups for organizing dependencies. Now, I need to think about how to best convey this information without overwhelming them.Designing Python project boilerplate
The user wants boilerplate for a Python data science project using Jupyter and Poetry, which means I need to create a clear, cookiecutter-style directory structure along with instructions.
My plan is to outline the folder layout, including essential files like pyproject.toml, README.md, and tests. I should also provide minimal .gitignore and README content and clearly lay out the steps for setting up the project with Poetry, adding a Jupyter kernel, and listing relevant dependencies in the pyproject.toml. Simplicity is key, but I want to ensure all critical aspects are covered.Finalizing project instructions
I need to mention how to run the project, specifically with commands like poetry install and poetry run jupyter lab. To keep things simple, I'll aim for minimal dependencies. I'll also touch on using environment variables with a .env file and python-dotenv, but I'll avoid overwhelming details.
It’s important to provide a direct answer without emojis. I'll present this as a minimal boilerplate that the user can easily copy-paste, with clear step-by-step commands and structured code blocks for files needed, such as pyproject.toml, .gitignore, and others. This will keep the explanation concise and focused on essentials. Below is a minimal, opinionated boilerplate for a Python data science project using Poetry and Jupyter.
1. Project layout
my_ds_project/
├─ pyproject.toml
├─ README.md
├─ .gitignore
├─ notebooks/
│ └─ 01_exploration.ipynb
├─ data/
│ ├─ raw/
│ ├─ interim/
│ └─ processed/
├─ models/
├─ reports/
│ └─ figures/
├─ src/
│ └─ my_ds_project/
│ ├─ __init__.py
│ └─ features.py
└─ tests/
└─ test_features.py
You can adjust names as you like; this is just a common convention.
2. pyproject.toml (Poetry + Jupyter + common DS stack)
[tool.poetry]
name = "my-ds-project"
version = "0.1.0"
description = "Data science project boilerplate with Poetry and Jupyter"
authors = ["Your Name <you@example.com>"]
readme = "README.md"
packages = [{ include = "my_ds_project", from = "src" }]
[tool.poetry.dependencies]
python = "^3.11"
# Core data science stack
pandas = "^2.2"
numpy = "^2.0"
scikit-learn = "^1.5"
matplotlib = "^3.9"
seaborn = "^0.13"
# Jupyter in main deps so `poetry run jupyter` just works
jupyterlab = "^4.2"
ipykernel = "^6.29"
# (Optional) configuration, environment helpers
python-dotenv = "^1.0"
[tool.poetry.group.dev.dependencies]
pytest = "^8.0"
black = "^24.0"
isort = "^5.13"
flake8 = "^7.0"
mypy = "^1.11"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
[tool.black]
line-length = 88
target-version = ["py311"]
include = '\.pyi?$'
[tool.isort]
profile = "black"
[tool.flake8]
max-line-length = 88
extend-ignore = "E203"
[tool.pytest.ini_options]
testpaths = ["tests"]
pythonpath = ["src"]
If you don’t want Jupyter as a main dependency, you can move jupyterlab and ipykernel into [tool.poetry.group.dev.dependencies].
3. .gitignore (minimal useful defaults)
# Byte-compiled / cache
__pycache__/
*.py[cod]
*.pyo
# Virtualenvs
.venv/
# Jupyter
.ipynb_checkpoints/
*.ipynb~
# Data (adjust to your policy)
data/raw/
data/interim/
data/processed/
# Models
models/
# OS / editor
.DS_Store
.idea/
.vscode/
# Python tooling
.mypy_cache/
.pytest_cache/
.coverage
If you want data or models under version control, remove those lines.
4. Example source module
src/my_ds_project/__init__.py:
"""Top-level package for my_ds_project."""
src/my_ds_project/features.py:
from __future__ import annotations
import pandas as pd
def add_basic_features(df: pd.DataFrame) -> pd.DataFrame:
"""
Example transformation: adds a 'row_sum' feature if numeric columns exist.
"""
numeric_cols = df.select_dtypes(include="number").columns
if len(numeric_cols) == 0:
return df.copy()
df = df.copy()
df["row_sum"] = df[numeric_cols].sum(axis=1)
return df
5. Example test
tests/test_features.py:
import pandas as pd
from my_ds_project.features import add_basic_features
def test_add_basic_features_adds_row_sum():
df = pd.DataFrame({"a": [1, 2], "b": [3, 4]})
out = add_basic_features(df)
assert "row_sum" in out.columns
assert list(out["row_sum"]) == [4, 6]
Run tests:
poetry run pytest
6. Setting up the environment
From the project root:
# Install dependencies
poetry install
If Poetry isn’t configured yet:
poetry config virtualenvs.in-project true # optional: keep .venv inside project
7. Using Jupyter with Poetry
Option A: Run Jupyter Lab from Poetry
poetry run jupyter lab
This opens Jupyter using the Poetry-managed virtual environment.
Option B: Create a named kernel (nice for VS Code, etc.)
# From inside the Poetry environment
poetry run python -m ipykernel install --user \
--name my-ds-project \
--display-name "Python (my-ds-project)"
Then select the Python (my-ds-project) kernel in Jupyter / VS Code.
8. Minimal README.md
# my-ds-project
Data science project boilerplate using Poetry and Jupyter.
## Setup
```bash
poetry install
Running Jupyter
poetry run jupyter lab
Tests
poetry run pytest
---
If you tell me your preferred stack (e.g., PyTorch vs TensorFlow, extra tools like Hydra/MLflow), I can tailor the dependencies and structure further.