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

Uploaded Python 3

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

Hashes for pathjoin-1.0.5.tar.gz
Algorithm Hash digest
SHA256 4714625d3356b691eb1304676020944837e54c5993c597324d42c33d144a57c1
MD5 32dba2b7251ef725cd3b749b5aae0fcc
BLAKE2b-256 08ec195034e56cf42101ad38118d746588af0759790979b862ca05892a45c6e9

See more details on using hashes here.

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

Hashes for pathjoin-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 20317288a53cd70660dcfaaefb70be817e48022be4f7b38e0e4686d683cfb2b5
MD5 73cf27f40866f53c0ab16bacfcba7519
BLAKE2b-256 ac95c86e28d74b6936e24da104094103eba0fea3def1b5ba61b5206090ca5294

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