pyprojroot is a Python library that facilitates project-oriented workflows by helping to find the project's root directory and construct paths relative to it. Inspired by R's `rprojroot` and `here` packages, it uses common project markers like `.git`, `setup.py`, or `requirements.txt` to locate the root. The current version is 0.3.0, and it's maintained with releases addressing improvements and compatibility.
pip install pyprojrootVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `here()` to find the project root and then construct paths to files or directories relative to it. It assumes a project structure with a root marker (like `.git`) and uses `pathlib.Path` objects for robust path manipulation. The example creates temporary files to be runnable.
Ensure your project's root directory contains at least one of the default root indicators (e.g., initialize a Git repository with `.git`, or add a `requirements.txt` file). For custom markers, use `pyprojroot.find_root` with a `pyprojroot.criterion`.
Understand that `pyprojroot` complements `pathlib` by providing a reliable starting point for relative paths within a project, regardless of the current working directory. `pathlib` then provides the elegant API for path manipulation.
Ensure a project root indicator exists in a parent directory. If running a script, make sure the current working directory or one of its parents contains a recognized marker. Double-check the path passed to `here()` is correct relative to your actual project root.
Install the library using `pip install pyprojroot`. Verify the import statement: `from pyprojroot.here import here` is for the common `here` function, while `import pyprojroot` is for the top-level module.
No dependency data recorded yet.