A utility to help with python paths on linux and windows
Project description
PathMonkey
PathMonkey is a lightweight, cross-platform Python utility that simplifies path manipulation. It supports advanced path construction and deconstruction for both Linux and Windows, making it easier to handle paths reliably across different operating systems.
Features
- Construct paths from a list of components (e.g.,
['~', 'projects', 'example']). - Deconstruct paths into individual components, with support for:
- Home directory (
~) - Windows drive letters (
C:) - Absolute and relative paths
- Home directory (
- Handles edge cases like trailing slashes, mixed separators, and empty paths.
- Built on Python's modern
pathlibfor robust path handling.
Installation
Install PathMonkey from PyPI using pip:
pip install pathmonkey
Usage
Here's how to use PathMonkey in your Python project:
Import the Module
from pathmonkey.pathmonkey import PathMonkey
from pathlib import Path
Constructing Paths
# Construct a path relative to the home directory
path = PathMonkey.construct_path(['~', 'projects', 'example'])
print(path) # Output: /home/user/projects/example (on Linux)
# Construct an absolute path
path = PathMonkey.construct_path(['/', 'usr', 'bin'])
print(path) # Output: /usr/bin
# Construct a Windows path
path = PathMonkey.construct_path(['C:', 'Users', 'example'])
print(path) # Output: C:\Users\example
Deconstructing Paths
# Deconstruct a path relative to the home directory
components = PathMonkey.deconstruct_path(Path.home().joinpath('projects', 'example'))
print(components) # Output: ['~', 'projects', 'example']
# Deconstruct an absolute path
components = PathMonkey.deconstruct_path(Path('/usr/bin'))
print(components) # Output: ['', 'usr', 'bin']
# Deconstruct a Windows path
components = PathMonkey.deconstruct_path(Path('C:\\Users\\example'))
print(components) # Output: ['C:', 'Users', 'example']
Examples
Path Construction
examples = [
(['~', 'projects', 'example'], "Home directory relative"),
(['/', 'usr', 'bin'], "Root directory"),
(['', 'usr', 'bin'], "Absolute path from root"),
(['C:', 'Users', 'example'], "Windows drive letter"),
(['..', 'another_folder'], "Relative path"),
(['usr', 'bin'], "Additional relative path"),
]
for elements, description in examples:
path = PathMonkey.construct_path(elements)
print(f"{description}: {path}")
Path Deconstruction
paths = [
(Path.home().joinpath('projects', 'example'), "Home directory relative"),
(Path('/usr/bin'), "Root directory"),
(Path('usr/bin'), "Relative path"),
(Path('C:\\Users\\example'), "Windows drive letter"),
]
for path, description in paths:
components = PathMonkey.deconstruct_path(path)
print(f"{description}: {components}")
Contributing
Contributions are welcome! To contribute:
- Fork the repository on GitHub.
- Create a feature branch (
git checkout -b feature-name). - Commit your changes (
git commit -m 'Add new feature'). - Push to the branch (
git push origin feature-name). - Open a pull request.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Links
- Source Code: GitHub Repository
- Bug Tracker: Report Issues
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pathmonkey-0.0.1.tar.gz.
File metadata
- Download URL: pathmonkey-0.0.1.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e4766fea4cde4819a2a170229295869181143aea2140ca0f6449248f8a014571
|
|
| MD5 |
bffb5e147965ff19d145221b0c09feb4
|
|
| BLAKE2b-256 |
6194cc2a58ba08ca3b309be19a5b96ac004e09ed9a4d8cca5a100ba1e0f62a40
|
File details
Details for the file pathmonkey-0.0.1-py3-none-any.whl.
File metadata
- Download URL: pathmonkey-0.0.1-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
17f419c6282d73d535d78cf9bd6aa797cd7b51bb684ef8cfcdbeeac9e65b64c0
|
|
| MD5 |
31a8841c4a5a53bcad0816f8f6c9e3a7
|
|
| BLAKE2b-256 |
ab0489ca8c08600f29ce06fa819ad8daec7d943d05bae69dca7f7fa0c083a8e3
|