Skip to main content

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 name
  • basename(path) - Get base name
  • splitext(path) - Split path and extension
  • exists(path) - Check if path exists
  • isfile(path) - Check if path is a file
  • isdir(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

pathjoin-1.0.6.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

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

pathjoin-1.0.6-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pathjoin-1.0.6.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

Hashes for pathjoin-1.0.6.tar.gz
Algorithm Hash digest
SHA256 59c37ad6935fe309ad0195a5c70440815eca406d50631ffbddeda5be979f750e
MD5 d73de0ea4b39755c5ca712dcefd7e50a
BLAKE2b-256 d7819b278cf6ea4866252d8b780c208632744134d99cf6e1a76a17a3d6533b18

See more details on using hashes here.

File details

Details for the file pathjoin-1.0.6-py3-none-any.whl.

File metadata

  • Download URL: pathjoin-1.0.6-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for pathjoin-1.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 0e755de3a445bd74f5eab72a324ae61437072cbc7401fdc170c4e241b297d6ac
MD5 ce741adc0c25e8f92da6f08ccae12b10
BLAKE2b-256 3a47f34a29ef544c5fd62b57dafe31bf71799b492499f4e92ca6c04c8b846131

See more details on using hashes here.

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