Skip to main content

Introduction

This package standardizes the handling of paths in a Python project by allowing all paths to be relative to the project repo root. The package discovers the project root based on the location of a special (empty) .py-repo-root file. The project root indicator can be overriden with a custom one, if desired.

This package was heavily inspired by pyprojroot. This package allows custom root file indicators, avoids recursive "/" is parent of "/" issue and can use the current file location to start walking the directory tree.

Setup

Installation:

pip install py-repo-root

Usage

Get project root, using the default list of project root indicators

from pyreporoot import project_root

project_root_dir = project_root(__file__)

Specify a custom project root indicator (not included in the list above)

project_root_dir = project_root(__file__, root_files='.my-root-indicator')

Another common usage pattern may be to add the project_root to PYTHONPATH for the purposes of running some scripts.

import sys
from pyreporoot import project_root

sys.path.insert(0, project_root(__file__))

Getting a relative path from the project root for a file:

from pathlib import Path
from projectroot import project_root

project_root_dir = project_root(__file__)
path_rel_to_project_root = Path(project_root_dir).joinpath('/path/to/file.txt')

Metadata

Release files for py-repo-root 2.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py-repo-root 2.0.1
File Size Uploaded Provenance Actions
py-repo-root-2.0.1.tar.gz 3.7 kB Without provenance Details for py-repo-root-2.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for py-repo-root 2.0.1
File Interpreter ABI Platform Actions
py_repo_root-2.0.1-py3-none-any.whl Python 3 none any Details for py_repo_root-2.0.1-py3-none-any.whl

Total release size: 7.4 kB

Release files / py-repo-root-2.0.1.tar.gz

Download URL py-repo-root-2.0.1.tar.gz
Size 3.7 kB
Tags Source
SHA-256 checksum
How to use checksums
1216a5ddea54e1fea25a5e108fe7056ff09356e294813008d8e89db6d558f418
BLAKE2b-256 checksum
How to use checksums
edce1e74b7517ea17aa00cffe62b139dbc904494fd56a4f5e4b8cfbde11847a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.6

Release files / py_repo_root-2.0.1-py3-none-any.whl

Download URL py_repo_root-2.0.1-py3-none-any.whl
Size 3.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ebdb8f5dc6b45bb890d493c9f14c63d79c029b31cb97ada989fcfcef3acc06fe
BLAKE2b-256 checksum
How to use checksums
ee08813653d0ee306dc564ac4ba0f0fab6171f8769e0aedaf63c6da64e21a67e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.6

Security for py-repo-root 2.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page