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             # append (default)
pathreg add --index 0 /some/directory   # insert at position 0
pathreg prepend /some/directory         # insert at front
pathreg remove /some/directory
pathreg move /some/directory 0          # move existing entry to position 0
pathreg set /a /b /c                    # replace PATH with given directories
pathreg list
pathreg count                           # prints number of PATH entries
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, prepend_path, remove_path, move_path, set_path, list_paths, path_len, in_path, find_executable, clean_path

add_path("/some/directory")          # append (default); idempotent
add_path("/some/directory", index=0) # insert at position 0; idempotent
prepend_path("/some/directory")      # insert at front; idempotent
remove_path("/some/directory")       # no-op if not found
move_path("/some/directory", 0)      # move existing entry to position 0; no-op if absent
set_path(["/a", "/b", "/c"])         # replace PATH entirely
list_paths()                         # returns list[Path] of current PATH entries
path_len()                           # returns number of PATH entries (faster than len(list_paths()))
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, remove_path, move_path, and set_path modify the shell profile and the current process's PATH immediately (move_path only updates the current process).

Behavior

  • Paths are normalized: trailing separators stripped, slashes converted per platform.
  • add_path is idempotent, does nothing if the entry already exists. The optional index parameter controls insertion position (default None = append to end); supports negative indices.
  • move_path moves an existing entry to the given index in the current process PATH only; no-op if absent.
  • 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.6.tar.gz (17.5 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.6-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pathreg-1.0.6.tar.gz
  • Upload date:
  • Size: 17.5 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.6.tar.gz
Algorithm Hash digest
SHA256 c5d4041d1b1ab751216e3b73fb826ad6760c333b913625c1b32e69d6297cf34d
MD5 8b341d2570287c6b208ce60865f9e7ca
BLAKE2b-256 012d293e9455d7806a6e6ab91fa88c1bd050ff3853ba36c912e52b02a13dbb97

See more details on using hashes here.

Provenance

The following attestation bundles were made for pathreg-1.0.6.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.6-py3-none-any.whl.

File metadata

  • Download URL: pathreg-1.0.6-py3-none-any.whl
  • Upload date:
  • Size: 10.1 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.6-py3-none-any.whl
Algorithm Hash digest
SHA256 49b1148b348a0b04ed67e78ce4979be0526c155d9e864b53c006235a283752d0
MD5 156d492702a6c8b0b24ebeaf8618aa05
BLAKE2b-256 940f88d935ffb9fd5fba7d84e46e58f1672ab4d17424adb13fafcbc04a332e82

See more details on using hashes here.

Provenance

The following attestation bundles were made for pathreg-1.0.6-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