Skip to content

About

This copier project template provides you with a boilerplate for small to medium-size (scientific) data projects, e.g. a thesis, a group project, or similar.

Topics

Resources

Stars

5 stars

Watchers

2 watching

Forks

Latest commit

Β 

History

286 Commits

Folders and files

Repository files navigation

Py(thon)-Project Template

Copier build License MIT

Important

This template has moved from Cookiecutter to Copier. The repository keeps its name, but projects are now generated with copier copy (see πŸš€ Get started) and updated with copier update instead of cruft update (why?).

Already have a project generated with the old cookiecutter/cruft version? scripts/migrate_cookiecutter_to_copier.py bootstraps the .copier-answers.yml for you β€” see Migrating an existing cookiecutter/cruft project (or the rendered version of the docs).

πŸ‘‰ If you're tired of setting up the same directory and file structure for your new Python projects again and again, then this might be for you ;-)

This repository provides a "template" of a directory structure for small to medium-sized (scientific) projects, making use of copier, a templating engine for project structures. Check out the links at the bottom of the page to create your own template or use this one to start your project. Also, feel free to fork the repository and adjust it to your own needs.


Table of contents


Copier as your productivity booster

By running copier with this repository, a new directory will be created with a pre-defined structure and some default files, making you all set to start a new Python project. No need to manually create the same files and directory structure over and over again. This includes

  • code that is importable from every place in your environment
  • automatically resolved paths to the project's root and the directories for data, plots, logs, etc.
  • commands to run automated unit tests, create documentation of your code, etc.
  • creating a nice HTML representation of your project's documentation, including Jupyter notebooks, docstrings, etc.
  • and so on... πŸš€

Usage

βœ… Requirements

  • uv

  • git

    For first time use If you use git it for the first time on your machine, make sure to set your global configuration:
    $ git config --global user.name "John Doe"
    $ git config --global user.email johndoe@example.com
    
  • just β€” the task runner the generated project uses. Install it with the toolchain you already have: uv tool install rust-just.

    Strictly optional

    Every recipe in the generated justfile is a thin wrapper around a uv command, so you can run those directly instead. The generated project's README lists the equivalents for the common tasks.

  • GitHub account (optional)

πŸš€ Get started

The easiest way to get started is using uv. Make sure you have uv installed, and then run the following command to create a new project from this template:

$ uvx --with jinja2-time copier copy --trust gh:markusritschel/cookiecutter-pyproject my-project

This creates the project in a new my-project/ directory (replace my-project with the path you want).

Important

--trust is not optional. The template uses the jinja2-time Jinja extension (for the copyright year in LICENSE and CITATION.cff) and a post-generation task (git init + first commit, uv sync --dev, pre-commit installation). copier considers both unsafe and aborts with Template uses potentially unsafe features: jinja_extensions, tasks if the flag is missing β€” without creating anything. copier update needs it for the same reason.

Alternatively, without uv

install copier and the jinja2-time extension via pip or conda, and then run the following command to create a new project from this template:

$ pip install copier jinja2-time
$ copier copy --trust gh:markusritschel/cookiecutter-pyproject my-project

Once you have answered the questions, your directory structure will be created and you're set, ready to start working on your new project πŸš€.

Tip

For further information, see also the README of your new project. You may also want to check out the justfile targets (simply type just in your terminal to get a command overview). Also see the next section

Features

This is a boilerplate for Python projects – both for package development and (scientific) data projects. It comes with a set of tools supportingyou r development workflow. It also provides an optional structure for research projects (see corresponding section below and the documentation for details).

πŸ”§ Tools

Purpose Tool Comment
Dependency management uv A modern and blazingly fast dependency manager for Python
Version control Git A popular version control system (VCS), automatically initialized
Documentation Sphinx A popular and versatile docs generator for Python
Code quality Ruff A fast linter and code formatter for Python
Testing Pytest A powerful testing framework for Python
Git hooks pre-commit Automatically enforces checks (e.g. lockfile sync) before commits
Task automation Just A modern taskrunner, simplifying your workflow
Test Github Actions Act A tool to run GitHub Actions locally

πŸš€ Just run(s) your tasks

just is a modern taskrunner alternative to Make. It can help you keep your workflow clean, simple, memorable, and reproducable. You can add complex commands such as

python scripts/raw_data_processing.py -i data/input_data.csv --clean-data --pre-process-data -o data/output.csv

to your justfile

# Process raw data
process-raw-data:
  python scripts/raw_data_processing.py -i data/input_data.csv --clean-data --pre-process-data -o data/output.csv

and then simply run just process-raw-data to execute the command.

For more available commands, simply execute just in your terminal in your newly created project.

πŸ‘‰ Check out the corresponding page in the documentation.

πŸ““ Documentation

The template ships with a Sphinx-powered documentation setup. Write your documentation in Markdown, paired with the flexibility and customizability of Sphinx. For example, use reference to literature, parse your docstrings, cross-link your own and third-party API, even from within your docstrings.

πŸ‘‰ Check out the corresponding page in the documentation.

πŸ“‚ Directory structure

The project follows a src layout, which means that the package's source code resides in a subdirectory of src. This follows the Good Integration Practices from pytest.org and is a common and recommended layout for Python project; it helps avoid issues with imports and ensures that the installed version of the package is always used during development and testing.

πŸ‘‰ Check out the corresponding page in the documentation.

directory structure
  β”œβ”€β”€ assets             <- A place for assets like shapefiles or config files
  β”‚
  β”œβ”€β”€ data               <- Contains all data used for the analyses in this project.
  β”‚   β”‚                     The sub-directories can be links to the actual location of your data.
  β”‚   β”‚                     However, they should never be under version control! (-> .gitignore)
  β”‚   β”œβ”€β”€ interim        <- Intermediate data that have been transformed from the raw data
  β”‚   β”œβ”€β”€ processed      <- The final, processed data used for the actual analyses
  β”‚   └── raw            <- The original, immutable(!) data
  β”‚
  β”œβ”€β”€ docs               <- The technical documentation (default engine: Sphinx; but feel free to 
  β”‚                         use MkDocs, Jupyter-Book or anything similar).
  β”‚                         This should contain only documentation of the code and the assets.
  β”‚                         A report of the actual project should be placed in `reports/book`.
  β”‚
  β”œβ”€β”€ logs               <- Storage location for the log files being generated by scripts
  β”‚
  β”œβ”€β”€ notebooks          <- Jupyter Notebooks. Follow a naming convention, such as a number (for ordering),
  β”‚   β”‚                     and a short `-` or `_` delimited description, e.g. `01-initial-analyses`
  β”‚   β”œβ”€β”€ _paired        <- Optional location for your paired Jupyter Notebook files
  β”‚   β”œβ”€β”€ exploratory    <- Notebooks for exploratory tasks
  β”‚   └── reports        <- Notebooks generating reports and figures
  β”‚
  β”œβ”€β”€ references         <- Data descriptions, manuals, and all other explanatory materials
  β”‚
  β”œβ”€β”€ reports            <- Generated reports (e.g. HTML, PDF, LaTeX, etc.)
  β”‚   β”œβ”€β”€ figures        <- Generated graphics and figures to be used in reporting
  β”‚   └── README.md      <- More information about Jupyter-Book and MyST-MD
  β”‚
  β”œβ”€β”€ scripts            <- High-level scripts that use (low-level) source code from `src/`
  β”œβ”€β”€ src                <- Source code (and only source code!) for use in this project
  β”‚   └── <package_name>
  β”‚       β”œβ”€β”€ core       <- Provides some core functionalities
  β”‚       β”œβ”€β”€ cli.py     <- Command-line entry point
  β”‚       └── __init__.py  <- Provides the global path variables and utility functions
  β”‚
  β”œβ”€β”€ tests              <- Contains the tests for the code in `src/`
  β”‚
  β”œβ”€β”€ .env               <- In this file, specify all your custom environment variables
  β”‚                         Keep this out of version control! (i.e. have it in your .gitignore)
  β”œβ”€β”€ .gitignore         <- Here, list all the files and folders (patterns allowed) that you want to
  β”‚                         keep out of git version control.    
  β”œβ”€β”€ CHANGELOG.md       <- All major changes should go in there
  β”œβ”€β”€ CITATION.cff       <- The citation information for this project (update your ORCID ID!)
  β”œβ”€β”€ justfile           <- Task runner recipes; run `just` to list them
  β”œβ”€β”€ LICENSE            <- The license used for this project
  β”œβ”€β”€ pyproject.toml     <- Configuration file for the project (manages all dependencies)
  β”œβ”€β”€ README.md          <- The top-level README of this project
  β”œβ”€β”€ ruff.toml          <- Linter and formatter configuration
  └── uv.lock            <- Lock file for reproducible dependency resolution (managed by uv)

Further reading:

Sources of inspiration

Some great sources of inspiration and orientation when I created this template:

Maintainer & Contribution

markusritschel maintains this project.
Issues & pull-requests accepted.


Β© Markus Ritschel 2021–2026

About

This copier project template provides you with a boilerplate for small to medium-size (scientific) data projects, e.g. a thesis, a group project, or similar.

Topics

Resources

Stars

5 stars

Watchers

2 watching

Forks

Releases

Used by

Contributors

Languages