A Node.js inspired path joining module for Python
This project has been quarantined.
PyPI Admins need to review this project before it can be restored. While in quarantine, the project is not installable by clients, and cannot be being modified by its maintainers.
Read more in the project in quarantine help article.
Project description
PathJoin
A Node.js inspired path joining module for Python. Intelligently join path segments, normalize paths, and resolve absolute paths.
Features
- Simple API: Similar to Node.js
path.join() - Cross-platform: Works on Windows, macOS, and Linux
- No dependencies: Pure Python implementation using standard library
- Type hints: Compatible with type checking
- Well-tested: Comprehensive test suite included
Installation
From PyPI
pip install pathjoin
From source
git clone https://github.com/yourusername/pathjoin.git
cd pathjoin
pip install .
Usage
Basic Path Joining
from pathjoin import join
# Join path segments
result = join('dir', 'subdir', 'file.txt')
print(result) # Output: dir/subdir/file.txt
# Join absolute paths
result = join('/usr', 'local', 'bin')
print(result) # Output: /usr/local/bin
# Handle .. and .
result = join('path', '..', 'file.txt')
print(result) # Output: file.txt
Resolve Absolute Paths
from pathjoin import resolve
# Resolve to absolute path from current working directory
result = resolve('dir', 'subdir')
print(result) # Output: /current/working/dir/subdir
# Resolve single path
result = resolve('.')
print(result) # Output: /current/working/directory
Normalize Paths
from pathjoin import normalize
# Remove redundant separators and resolve . and ..
result = normalize('path//to///file.txt')
print(result) # Output: path/to/file.txt
result = normalize('path/../file.txt')
print(result) # Output: file.txt
Additional Utilities
from pathjoin import dirname, basename, splitext, exists, isfile, isdir
# Get directory name
dirname('path/to/file.txt') # Output: path/to
# Get base name
basename('path/to/file.txt') # Output: file.txt
# Split extension
splitext('file.txt') # Output: ('file', '.txt')
# Check if path exists
exists('path/to/file.txt') # Output: True or False
# Check if path is file
isfile('path/to/file.txt') # Output: True or False
# Check if path is directory
isdir('path/to') # Output: True or False
API Reference
join(*paths)
Join path segments intelligently. Empty segments are ignored.
Parameters:
*paths: Variable length path segments
Returns:
str: Joined and normalized path
resolve(*paths)
Resolve path segments to an absolute path.
Parameters:
*paths: Variable length path segments
Returns:
str: Absolute resolved path
normalize(path)
Normalize a path (resolve . and .. segments, handle redundant separators).
Parameters:
path: Path to normalize
Returns:
str: Normalized path
Additional utilities
dirname(path)- Get directory namebasename(path)- Get base namesplitext(path)- Split path and extensionexists(path)- Check if path existsisfile(path)- Check if path is a fileisdir(path)- Check if path is a directory
Examples
from pathjoin import join, resolve
# Joining paths
config_path = join('config', 'app.json')
print(config_path) # config/app.json
# Multiple segments
full_path = join('home', 'user', 'documents', 'report.pdf')
print(full_path) # home/user/documents/report.pdf
# With parent directory references
base = join('projects', 'myapp', '..', 'utils')
print(base) # projects/utils
# Resolving absolute paths
abs_path = resolve('src', 'main.py')
print(abs_path) # /current/working/directory/src/main.py
Testing
Run the test suite:
python -m pytest tests/
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Support
If you have any issues or questions, please open an issue on the GitHub repository.
Changelog
Version 1.0.0
- Initial release
- Core path joining, resolving, and normalization functions
- Cross-platform support
- Comprehensive test suite
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
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 pathjoin-1.0.5.tar.gz.
File metadata
- Download URL: pathjoin-1.0.5.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4714625d3356b691eb1304676020944837e54c5993c597324d42c33d144a57c1
|
|
| MD5 |
32dba2b7251ef725cd3b749b5aae0fcc
|
|
| BLAKE2b-256 |
08ec195034e56cf42101ad38118d746588af0759790979b862ca05892a45c6e9
|
File details
Details for the file pathjoin-1.0.5-py3-none-any.whl.
File metadata
- Download URL: pathjoin-1.0.5-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
20317288a53cd70660dcfaaefb70be817e48022be4f7b38e0e4686d683cfb2b5
|
|
| MD5 |
73cf27f40866f53c0ab16bacfcba7519
|
|
| BLAKE2b-256 |
ac95c86e28d74b6936e24da104094103eba0fea3def1b5ba61b5206090ca5294
|