Skip to content

Data science project template

uv Ruff pre-commit security: bandit Checked with mypy pages-build-deployment CI codecov


A modern template for data science projects with all the necessary tools for experiment, development, testing, and deployment. From notebooks to production.

โœจ๐Ÿ“šโœจ Documentation: https://joserzapata.github.io/data-science-project-template/

Source Code: https://github.com/JoseRZapata/data-science-project-template


Features


๐Ÿ“ Creating a New Project

๐Ÿ‘ Recommendations

It is highly recommended to use managers for the python versions, dependencies and virtual environments.

This project uses UV, a extremely fast tool to replace pip, pip-tools, Pipx, Poetry, Pyenv, twine, virtualenv, and more.

๐ŸŒŸ Check how to setup your environment: https://joserzapata.github.io/data-science-project-template/local_setup/

install cruft
# Install cruft in a isolated environment using uv

uv tool install cruft 

# Or Install with pip

pip install --user cruft # Install `cruft` on your path for easy access
create project
cruft create https://github.com/JoseRZapata/data-science-project-template

๐Ÿช Via Cookiecutter

install cookiecutter
uv tool install cookiecutter # Install cruft in a isolated environment

# Or Install with pip

pip install --user cookiecutter # Install `cookiecutter` on your path for easy access
create project
cookiecutter gh:JoseRZapata/data-science-project-template

Note: Cookiecutter uses gh: as short-hand for https://github.com/

๐Ÿ”— Linking an Existing Project

If the project was originally installed via Cookiecutter, you must first use Cruft to link the project with the original template:

cruft link https://github.com/JoseRZapata/data-science-project-template

Then/else:

cruft update

๐Ÿ—ƒ๏ธ Project structure

Folder structure for data science projects why?

.
โ”œโ”€โ”€ .code_quality
โ”‚ย ย  โ”œโ”€โ”€ mypy.ini                        # mypy configuration
โ”‚ย ย  โ””โ”€โ”€ ruff.toml                       # ruff configuration
โ”œโ”€โ”€ .github                             # github configuration
โ”‚ย ย  โ”œโ”€โ”€ actions
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ python-poetry-env
โ”‚ย ย  โ”‚ย ย      โ””โ”€โ”€ action.yml              # github action to setup python environment
โ”‚ย ย  โ”œโ”€โ”€ dependabot.md                   # github action to update dependencies
โ”‚ย ย  โ”œโ”€โ”€ pull_request_template.md        # template for pull requests
โ”‚ย ย  โ””โ”€โ”€ workflows                       # github actions workflows
โ”‚ย ย      โ”œโ”€โ”€ ci.yml                      # run continuous integration (tests, pre-commit, etc.)
โ”‚ย ย      โ”œโ”€โ”€ dependency_review.yml       # review dependencies
โ”‚ย ย      โ”œโ”€โ”€ docs.yml                    # build documentation (mkdocs)
โ”‚ย ย      โ””โ”€โ”€ pre-commit_autoupdate.yml   # update pre-commit hooks
โ”œโ”€โ”€ .vscode                             # vscode configuration
|   โ”œโ”€โ”€ extensions.json                 # list of recommended extensions
|   โ”œโ”€โ”€ launch.json                     # vscode launch configuration
|   โ””โ”€โ”€ settings.json                   # vscode settings
โ”œโ”€โ”€ conf                                # folder configuration files
โ”‚ย ย  โ””โ”€โ”€ config.yaml                     # main configuration file
โ”œโ”€โ”€ data
โ”‚ย ย  โ”œโ”€โ”€ 01_raw                          # raw immutable data
โ”‚ย ย  โ”œโ”€โ”€ 02_intermediate                 # typed data
โ”‚ย ย  โ”œโ”€โ”€ 03_primary                      # domain model data
โ”‚ย ย  โ”œโ”€โ”€ 04_feature                      # model features
โ”‚ย ย  โ”œโ”€โ”€ 05_model_input                  # often called 'master tables'
โ”‚ย ย  โ”œโ”€โ”€ 06_models                       # serialized models
โ”‚ย ย  โ”œโ”€โ”€ 07_model_output                 # data generated by model runs
โ”‚ย ย  โ”œโ”€โ”€ 08_reporting                    # reports, results, etc
โ”‚ย ย  โ””โ”€โ”€ README.md                       # description of the data structure
โ”œโ”€โ”€ docs                                # documentation for your project
โ”‚ย ย  โ”œโ”€โ”€ index.md                        # documentation homepage
โ”œโ”€โ”€ models                              # store final models
โ”œโ”€โ”€ notebooks
โ”‚ย ย  โ”œโ”€โ”€ 1-data                          # data extraction and cleaning
โ”‚ย ย  โ”œโ”€โ”€ 2-exploration                   # exploratory data analysis (EDA)
โ”‚ย ย  โ”œโ”€โ”€ 3-analysis                      # Statistical analysis, hypothesis testing.
โ”‚ย ย  โ”œโ”€โ”€ 4-feat_eng                      # feature engineering (creation, selection, and transformation.)
โ”‚ย ย  โ”œโ”€โ”€ 5-models                        # model training, evaluation and hyperparameter tuning.
โ”‚ย ย  โ”œโ”€โ”€ 6-interpretation                # model interpretation
โ”‚ย ย  โ”œโ”€โ”€ 7-deploy                        # model packaging, deployment strategies.
โ”‚ย ย  โ”œโ”€โ”€ 8-reports                       # story telling, summaries and analysis conclusions.
โ”‚ย ย  โ”œโ”€โ”€ notebook_template.ipynb         # template for notebooks
โ”‚ย ย  โ””โ”€โ”€ README.md                       # information about the notebooks
โ”œโ”€โ”€ src                                 # source code for use in this project
โ”‚   โ”œโ”€โ”€ README.md                       # description of src structure
โ”‚   โ”œโ”€โ”€ tmp_mock.py                     # example python file
โ”‚   โ”œโ”€โ”€ data                            # data extraction, validation, processing, transformation
โ”‚   โ”œโ”€โ”€ model                           # model training, evaluation, validation, export
โ”‚   โ”œโ”€โ”€ inference                       # model prediction, serving, monitoring
โ”‚   โ””โ”€โ”€ pipelines                       # orchestration of pipelines
โ”‚       โ”œโ”€โ”€ feature_pipeline            # transforms raw data into features and labels
โ”‚       โ”œโ”€โ”€ training_pipeline           # transforms features and labels into a model
โ”‚       โ””โ”€โ”€ inference_pipeline          # takes features and a trained model for predictions
โ”œโ”€โ”€ tests                               # test code for your project
โ”‚   โ”œโ”€โ”€ test_mock.py                    # example test file
โ”‚   โ”œโ”€โ”€ data                            # tests for data module
โ”‚   โ”œโ”€โ”€ model                           # tests for model module
โ”‚   โ”œโ”€โ”€ inference                       # tests for inference module
โ”‚   โ””โ”€โ”€ pipelines                       # tests for pipelines module
โ”œโ”€โ”€ .editorconfig                       # editor configuration
โ”œโ”€โ”€ .gitignore                          # files to ignore in git
โ”œโ”€โ”€ .pre-commit-config.yaml             # configuration for pre-commit hooks
โ”œโ”€โ”€ codecov.yml                         # configuration for codecov
โ”œโ”€โ”€ Makefile                            # useful commands to setup environment, run tests, etc.
โ”œโ”€โ”€ mkdocs.yml                          # configuration for mkdocs documentation
โ”œโ”€โ”€ pyproject.toml                      # dependencies and configuration project file
โ”œโ”€โ”€ uv.lock                             # locked dependencies
โ””โ”€โ”€ README.md                           # description of your project    

โœจ Features and Tools

๐Ÿš€ Project Standardization and Automation

๐Ÿ”จ Developer Workflow Automation

๐ŸŒฑ Conditionally Rendered Python Package or Project Boilerplate

๐Ÿ”ง Maintainability

๐Ÿท๏ธ Type Checking and Data Validation

  • Static type-checking with Mypy

โœ… ๐Ÿงช Testing/Coverage

๐Ÿšจ Linting

๐Ÿ” Code quality
๐ŸŽจ Code formatting

๐Ÿ‘ท CI/CD

Automatic Dependency updates
Dependency Review in PR
  • Dependency Review with dependency-review-action, This action scans your pull requests for dependency changes, and will raise an error if any vulnerabilities or invalid licenses are being introduced.
Pre-commit automatic updates
  • Automatic updates with GitHub Actions workflow .github/workflows/pre-commit_autoupdate.yml

๐Ÿ”’ Security

๐Ÿ” Static Application Security Testing (SAST)

โŒจ๏ธ Accessibility

๐Ÿ”จ Automation tool (Makefile)

Makefile to automate the setup of your environment, the installation of dependencies, the execution of tests, etc. in terminal type make to see the available commands

Target                Description
-------------------   ----------------------------------------------------
check                 Run code quality tools with pre-commit hooks.
docs_test             Test if documentation can be built without warnings or errors
docs_view             Build and serve the documentation
init_env              Install dependencies with uv and activate env
init_git              Initialize git repository
install_data_libs     Install pandas, scikit-learn, Jupyter, seaborn
pre-commit_update     Update pre-commit hooks
test                  Test the code with pytest and coverage

๐Ÿ“ Project Documentation

๐Ÿ—ƒ๏ธ Templates

Good practices


References