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.4.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.4-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pathjoin-1.0.4.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.4.tar.gz
Algorithm Hash digest
SHA256 caf028a45100b314a6bd3331cb0dcaa89f168cb8511ceddf4977919dc7dab0b7
MD5 f0c2651cc2f9a6bfef64d11fced688c9
BLAKE2b-256 6fe4a02b74507d2eef1ffa243d7a1fe405494d420a30cea8c9227edf9f9bdc3c

See more details on using hashes here.

File details

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

File metadata

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

Hashes for pathjoin-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 1a52ff13d6f24be8c0ac84e5e1e68b759460c2cb0bde1376e256d39a050bc716
MD5 442d85f34fd97b171288d9daabb4bca8
BLAKE2b-256 3ff3ca2dcfd613d8645677ba85716fbc638f141c32fe8777a04578efdf601902

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