Framing the Objective
I'm now zeroing in on the core of the problem: crafting a Python project structure geared towards data science, incorporating Jupyter Notebooks and Poetry. My current focus is dissecting the user's needs, specifically how to best leverage these tools for maximum efficiency and clarity within the project.
Mapping the Architecture
My architectural blueprints are taking shape. I'm focusing on the integration of data handling, model storage, and a robust testing framework within the proposed structure. The key is to optimize the interaction between data, code, and analysis notebooks, creating a streamlined, reproducible workflow.
Developing the Blueprint
My focus has shifted to the practical implementation of the project structure. I'm prioritizing the creation of a clear, step-by-step guide. This includes detailing the poetry commands, directory layouts, and essential configuration file contents. I'm now exploring the best practices for structuring a pyproject.toml file to efficiently manage dependencies and development tools.
Outlining the Execution
My current focus is on building the guide content. I'm actively crafting sections detailing dependency setup with Poetry, the necessary folder structures, and configuring the Jupyter kernel within the Poetry environment. I'm considering using a Markdown-based approach for the guide, ensuring it's both clear and easily reproducible.
Synthesizing the Structure
I'm now integrating the step-by-step implementation guide with a draft of the example pyproject.toml and .gitignore files. I am refining the setup commands for the Jupyter kernel to ensure smooth integration with the Poetry environment. I'm also including clear instructions for launching Jupyter within the virtual environment.
Detailing the Implementation
I'm presently focusing on the nuts and bolts. Specifically, I'm crafting the setup script and detailed explanations of core files like pyproject.toml and .gitignore. I am now making sure the guide emphasizes clarity and provides a practical "copy and paste" experience to lower the barrier to entry.
This boilerplate follows the "Cookiecutter Data Science" philosophy but is adapted specifically for modern Poetry workflows and the source layout (src/) pattern.
Here is the complete breakdown.
1. The Project Structure
This file tree separates data, exploration (Jupyter), source code, and configuration.
my-ds-project/
├── data/
│ ├── raw/ # Immutable, original data
│ └── processed/ # Cleaned data used for modeling
├── models/ # Serialized models (pkl, joblib, onnx)
├── notebooks/ # Jupyter notebooks for exploration
│ └── expl_data_analysis.ipynb
├── src/ # Source code (the "production" code)
│ └── my_package/
│ ├── __init__.py
│ ├── data_loader.py
│ └── preprocessing.py
├── tests/ # Unit tests
├── .gitignore # Crucial for ignoring data and venvs
├── Makefile # Shortcuts for terminal commands
├── pyproject.toml # Dependencies and config
├── poetry.lock # Specific versions of dependencies
└── README.md
2. Quick Setup Script (Bash)
If you have poetry installed, you can copy-paste this into your terminal to generate the entire project skeleton with standard data science libraries installed.
# 1. Create project directory and standard folders
mkdir my-ds-project
cd my-ds-project
mkdir -p data/{raw,processed} models notebooks src/my_package tests
# 2. Initialize Poetry
poetry init --name="my-ds-project" --python=">=3.9" --no-interaction
# 3. Add Main Dependencies
poetry add pandas numpy scikit-learn matplotlib seaborn
# 4. Add Dev Dependencies (Jupyter, Testing, Linting)
poetry add -G dev jupyterlab ipykernel pytest black isort flake8
# 5. Create empty __init__.py to make src importable
touch src/my_package/__init__.py
# 6. Configure the project package in pyproject.toml
# We need to tell Poetry where the source code lives
sed -i '' '/\[tool.poetry\]/a \
packages = [{include = "my_package", from = "src"}]' pyproject.toml 2>/dev/null || \
sed -i '/\[tool.poetry\]/a \
packages = [{include = "my_package", from = "src"}]' pyproject.toml
# 7. Install the project
poetry install
echo "Setup complete!"
3. Configuration Files
pyproject.toml
Ensure your configuration includes the packages line so that you can import my_package inside your Jupyter notebooks.
[tool.poetry]
name = "my-ds-project"
version = "0.1.0"
description = "Data Science Project Boilerplate"
authors = ["Your Name <you@example.com>"]
# This allows you to do `import my_package` in notebooks
packages = [{include = "my_package", from = "src"}]
[tool.poetry.dependencies]
python = ">=3.9,<3.12"
pandas = "^2.1"
numpy = "^1.26"
scikit-learn = "^1.3"
matplotlib = "^3.8"
seaborn = "^0.13"
[tool.poetry.group.dev.dependencies]
jupyterlab = "^4.0"
ipykernel = "^6.25"
pytest = "^7.4"
black = "^23.9"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
.gitignore
Crucial: Never commit raw data, local environments, or notebooks with huge output metadata.
# Python
__pycache__/
*.py[cod]
.pytest_cache/
# Poetry
.venv/
poetry.lock
# Jupyter
.ipynb_checkpoints/
# Data Science (IMPORTANT)
data/
models/
*.csv
*.parquet
*.pkl
# Exceptions (optional)
!data/.gitkeep
4. How to connect Jupyter to Poetry
A common issue is Jupyter not seeing the Poetry virtual environment.
Option A: The simple way (Run from poetry)
poetry run jupyter lab
Option B: The register kernel way (Better for VS Code / IDEs)
If you want to select your kernel from a dropdown in VS Code:
# Activate the shell
poetry shell
# Register the kernel
python -m ipykernel install --user --name=my-ds-project
# Start Jupyter
jupyter lab
5. Workflow Best Practices
Importing custom code in Notebooks
Because we used the src layout and configured packages in pyproject.toml, you can do this in notebooks/analysis.ipynb without sys-path hacking:
# In your notebook
import pandas as pd
# Import directly from your src folder!
from my_package.data_loader import load_raw_data
df = load_raw_data()
Managing Dependencies
- Adding a library:
poetry add xgboost
- Adding a dev tool:
poetry add -G dev missingno
- Updating:
poetry update
The Makefile (Optional but recommended)
Create a Makefile in the root to save typing.
install:
poetry install
setup:
poetry install
poetry run python -m ipykernel install --user --name=my-ds-project
format:
poetry run black src notebooks
test:
poetry run pytest
jupyter:
poetry run jupyter lab
Use it like: make jupyter