Skip to main content

A lightweight Python library to persistently add or remove directories from PATH.

Project description

pathreg

Persistently add or remove directories from PATH on Windows, Linux, and macOS.

Installation

pip install pathreg

CLI Usage

pathreg add /some/directory
pathreg remove /some/directory
pathreg set /a /b /c            # replace PATH with given directories
pathreg list
pathreg check /some/directory   # prints "yes" or "no"
pathreg find python             # prints full path or "not found"
pathreg clean                   # removes duplicates and non-existent entries

Python API

from pathreg import add_path, remove_path, list_paths, in_path, find_executable, clean_path

add_path("/some/directory")       # idempotent, skips if already present
remove_path("/some/directory")    # no-op if not found
set_path(["/a", "/b", "/c"])      # replace PATH entirely with given list
list_paths()                      # returns list[Path] of current PATH entries
in_path("/some/directory")        # returns True if directory is in PATH
find_executable("python")         # returns Path to first match, or None
clean_path()                      # removes duplicates and non-existent dirs, returns cleaned list[Path]

add_path and remove_path modify the shell profile and the current process's PATH immediately.

Behavior

  • Paths are normalized: trailing separators stripped, slashes converted per platform.
  • add_path is idempotent, does nothing if the entry already exists.
  • remove_path is a no-op if the entry is absent or the profile file does not exist.
  • list_paths reflects the current process PATH; it does not read the profile file.
  • in_path normalizes trailing separators before comparing, matching add_path behaviour.
  • find_executable walks PATH entries in order and returns the first regular file that is executable, or None.
  • clean_path removes non-existent directories and duplicates (resolved via symlinks) from the current process PATH in-place, and returns the cleaned list.

Platform support

Platform Persistence target
Windows HKCU\Environment via winreg; broadcasts WM_SETTINGCHANGE to notify the shell
bash ~/.bash_profile (falls back to ~/.profile if it exists)
zsh ~/.zshenv
sh ~/.profile

The active shell is detected from the SHELL environment variable.

No third-party dependencies required.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pathreg-1.0.5.tar.gz (15.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pathreg-1.0.5-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file pathreg-1.0.5.tar.gz.

File metadata

  • Download URL: pathreg-1.0.5.tar.gz
  • Upload date:
  • Size: 15.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pathreg-1.0.5.tar.gz
Algorithm Hash digest
SHA256 1e1abd17be4de86d4c6d9455f6e5ec703800c1f22609c20dad9d3ec36c4b2ea2
MD5 ce611422d13b729c51f656824cfd5db7
BLAKE2b-256 d69f5644f63f7c3be4a21b851ed723e137b2f4357b79a332f332dfe1f00f14d5

See more details on using hashes here.

Provenance

The following attestation bundles were made for pathreg-1.0.5.tar.gz:

Publisher: publish.yml on tn3w/pathreg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pathreg-1.0.5-py3-none-any.whl.

File metadata

  • Download URL: pathreg-1.0.5-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pathreg-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 29d136b553c246636d2164b909418ff90cff25f1bd5150cea9a76be44db8fe6a
MD5 d767f14f4208dc23b6f64f0a27710ede
BLAKE2b-256 676dabfa67abdcc370dd90d2b4521b9634fdb8e4bf068d3f6a3ad691b4e00b4d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pathreg-1.0.5-py3-none-any.whl:

Publisher: publish.yml on tn3w/pathreg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page