Skip to content

System Path Utilities

Utilities for working with system paths.

Path Module

Path operation utilities.

This submodule provides utilities for path operations and queries using pathlib.

Examples

from rite.system.path import path_exists, path_join path_exists("/tmp") True path_join("/tmp", "file.txt") '/tmp/file.txt'

Modules

path_absolute

Path Absolute

Get absolute path.

Examples

from rite.system.path import path_absolute path_absolute(".") '/current/working/directory'

Functions

path_absolute(path: str | Path) -> str

Get absolute path as string.

Parameters:

Name Type Description Default
path str | Path

Relative or absolute path.

required

Returns:

Type Description
str

Absolute path string.

Examples:

>>> path_absolute(".")
'/current/working/directory'
>>> path_absolute("../parent")
'/parent/directory'
Notes

Resolves symlinks and relative paths.

path_exists

Path Exists

Check if path exists.

Examples

from rite.system.path import path_exists path_exists("/tmp") True

Functions

path_exists(path: str | Path) -> bool

Check if path exists.

Parameters:

Name Type Description Default
path str | Path

Path to check.

required

Returns:

Type Description
bool

True if exists, False otherwise.

Examples:

>>> path_exists("/tmp")
True
>>> path_exists("/nonexistent")
False
Notes

Works for files and directories.

path_is_dir

Path Is Directory

Check if path is a directory.

Examples

from rite.system.path import path_is_dir path_is_dir("/tmp") True

Functions

path_is_dir(path: str | Path) -> bool

Check if path is a directory.

Parameters:

Name Type Description Default
path str | Path

Path to check.

required

Returns:

Type Description
bool

True if directory, False otherwise.

Examples:

>>> path_is_dir("/tmp")
True
>>> path_is_dir("/etc/hosts")
False
Notes

Returns False if path doesn't exist.

path_is_file

Path Is File

Check if path is a file.

Examples

from rite.system.path import path_is_file path_is_file("/etc/hosts") True

Functions

path_is_file(path: str | Path) -> bool

Check if path is a file.

Parameters:

Name Type Description Default
path str | Path

Path to check.

required

Returns:

Type Description
bool

True if file, False otherwise.

Examples:

>>> path_is_file("/etc/hosts")
True
>>> path_is_file("/tmp")
False
Notes

Returns False if path doesn't exist.

path_join

Path Join

Join path components.

Examples

from rite.system.path import path_join path_join("/tmp", "file.txt") '/tmp/file.txt'

Functions

path_join(*parts: str) -> str

Join path components into single path.

Parameters:

Name Type Description Default
*parts str

Path components to join.

()

Returns:

Type Description
str

Joined path string.

Examples:

>>> path_join("/tmp", "dir", "file.txt")
'/tmp/dir/file.txt'
>>> path_join(".", "file.txt")
'./file.txt'
Notes

Uses platform-specific separator.

options: show_root_heading: true show_source: false heading_level: 2