jetraw.path module

class jetraw.path.Path(first_path_segment='/', *other_path_segments, client=None)

Bases: object

A path-like object for Jetraw filesystem operations.

Represents a path to a file, directory, or space in the Jetraw filesystem. Supports both absolute paths (/space/folder/file) and UUIDs.

Examples

>>> # Create path from string
>>> path = Path("/my-space/folder/image.tiff")
>>>
>>> # Create path from UUID
>>> path = Path("deq93878-32a5-4g4a-bf6d-ec73d60585e7")
>>>
>>> # Create path from Jetraw URL
>>> path = Path("jetraw://host/fs/deq93878-32a5-4g4a-bf6d-ec73d60585e7")
>>>
>>> # Create path from FileInfo
>>> path = Path(file_info)
>>>
>>> # Join paths
>>> base = Path("/my-space")
>>> file_path = base / "folder" / "image.tiff"
absolute()

Get the absolute path (alias for resolve()).

Return type:

Path

as_posix()

Return the path as a POSIX-style string.

as_uri(short=False)

Get the URI representation of the path.

Parameters:

short (bool) – If True, use UUID ID instead of full path

Returns:

Jetraw URI (e.g., “jetraw://host/fs/path” or “jetraw://host/fs/uuid”)

Return type:

str

Example

>>> path = Path("/my-space/file.tiff")
>>> print(path.as_uri())  # "jetraw://host/fs/my-space/file.tiff"
>>> print(path.as_uri(short=True))  # "jetraw://host/fs/deq93878-32a5-4g4a-bf6d-ec73d60585e7"
property client: Client

Get the Jetraw client associated with this path.

copy_to(destination)

Copy this path to a destination.

Parameters:

destination (PathLike) – Target path for the copy operation

Returns:

The destination path

Return type:

Path

Example

>>> source = Path("/my-space/image.tiff")
>>> copy = source.copy_to("/my-space/backup.tiff")
exists()

Check if the path exists in the filesystem.

Returns:

True if the path exists

Return type:

bool

Example

>>> path = Path("/my-space/file.tiff")
>>> if path.exists():
...     print("File exists")
property file_id: str | None

Get the file ID (None for directories and spaces).

Returns:

File ID or None

Return type:

Optional[str]

file_info()

Get file/directory information as a dictionary.

Returns:

Dictionary with file/directory information including path

Return type:

dict

get_items(extension=None, file_type=None, return_paths=False)

Get a list of directory contents with optional filtering.

Special case: get_items() on root path (/) returns all spaces. Note: Loads all contents from server and filters client-side.

Parameters:
  • extension (Optional[str]) – Filter by extension (e.g., “.tiff”, “*.tiff”, “tiff”)

  • file_type (Optional[str]) – Filter by type (“file”, “folder/directory”, “image”)

  • return_paths (bool) – If True, return Path objects; if False, return strings

Returns:

List of filtered items

Return type:

Union[List[str], List[Path]]

Example

>>> # Get all TIFF files as a list
>>> tiff_files = Path("/my-space/folder").get_items(extension=".tiff")
property host

Get the host of the Jetraw client.

property id: str

Get the unique identifier of the file, directory, or space.

Returns:

The unique UUID identifier

Return type:

str

Example

>>> path = Path("/my-space/file.tiff")
>>> print(path.id)  # "deq93878-32a5-4g4a-bf6d-ec73d60585e7"
is_absolute()

Check if the path is absolute (starts with /).

Return type:

bool

is_block_device()

Check if the path is a block device (always False for Jetraw paths).

is_char_device()

Check if the path is a character device (always False for Jetraw paths).

is_dir()

Check if the path is a directory or space.

Returns:

True if the path is a directory or space

Return type:

bool

Example

>>> path = Path("/my-space/folder")
>>> print(path.is_dir())  # True
is_fifo()

Check if the path is a FIFO (always False for Jetraw paths).

is_file()

Check if the path is a file.

Returns:

True if the path is a file

Return type:

bool

Example

>>> path = Path("/my-space/image.tiff")
>>> print(path.is_file())  # True
is_junction()

Check if the path is a junction (always False for Jetraw paths).

property is_loaded: bool

Check if the path has been loaded from the server.

is_mount()

Check if the path is a mount point (always False for Jetraw paths).

is_reserved()

Check if the path is reserved (always False for Jetraw paths).

Return type:

bool

is_socket()

Check if the path is a socket (always False for Jetraw paths).

is_space()

Check if the path references a space directly.

Returns:

True if the path is a space

Return type:

bool

Check if the path is a symbolic link (always False for Jetraw paths).

iterdir(extension=None, file_type=None, return_paths=True)

Iterate over directory contents with optional filtering.

Special case: iterdir() on root path (/) iterates over all spaces.

Parameters:
  • extension (Optional[str]) – Filter by extension (e.g., “.tiff”, “*.tiff”, “tiff”)

  • file_type (Optional[str]) – Filter by type (“file”, “folder/directory”, “image”)

  • return_paths (bool) – If True, return Path objects; if False, return strings

Yields:

Union[str, Path] – Filtered items

Return type:

Iterator[Union[str, Path]]

Example

>>> # List all TIFF files in a directory
>>> for item in Path("/my-space/folder").iterdir(extension=".tiff"):
...     print(item)
joinpath(*path_segments)

Join this path with additional segments.

Parameters:

*path_segments – Path segments to join

Returns:

New path with joined segments

Return type:

Path

Example

>>> base = Path("/my-space")
>>> new_path = base.joinpath("folder", "file.tiff")
mkdir(exist_ok=False)

Create a directory.

Parameters:

exist_ok (bool) – If True, don’t raise error if directory exists

Returns:

The created directory path

Return type:

Path

Example

>>> path = Path("/my-space/new-folder")
>>> path.mkdir()
move_to(destination)

Move this path to a destination.

Parameters:

destination (PathLike) – Target path for the move operation

Returns:

The destination path

Return type:

Path

Example

>>> source = Path("/my-space/old-name.tiff")
>>> dest = source.move_to("/my-space/new-name.tiff")
property name

Get the name of the file, directory, or space.

Returns:

The name of the entry

Return type:

str

Example

>>> path = Path("/my-space/folder/image.tiff")
>>> print(path.name)  # "image.tiff"
property parent: Path

Get the parent directory path.

Returns:

Parent directory path

Return type:

Path

Example

>>> path = Path("/my-space/folder/file.tiff")
>>> print(path.parent)  # Path("/my-space/folder")
property parent_id: str | None

Get the ID of the parent directory.

Returns:

Parent directory ID or None for spaces

Return type:

Optional[str]

remove(*args, **kwargs)
Return type:

None

rename(target)

Rename this path to a target path.

Parameters:

target (Path) – The new path name

Returns:

The renamed path

Return type:

Path

resolve()

Resolve the path to an absolute path.

Returns:

Absolute path

Return type:

Path

Example

>>> path = Path("folder/file.tiff")
>>> abs_path = path.resolve()  # Path("/my-space/folder/file.tiff")
property root
samefile(other_path)

Check if two paths reference the same file.

Parameters:

other_path (Path) – Another Path object to compare

Returns:

True if both paths reference the same file

Return type:

bool

property space_id: str

Get the ID of the space containing this path.

Returns:

The space ID

Return type:

str

stat(force_refresh=False)

Get file information.

Parameters:

force_refresh (bool) – If True, fetch fresh data from server

Returns:

File information with the following properties:
  • id (str): Unique identifier

  • name (str): File name

  • size (int): File size in bytes

  • size_on_disk (int): Actual size on disk

  • type (FileType): File type (FILE, FOLDER, IMAGE)

  • space_id (str): ID of the containing space

  • parent_id (str, optional): ID of parent directory

  • file_id (str, optional): File ID (None for directories)

  • file_count (int): Number of files in directory

  • mod_time (datetime): Last modification time

  • last_calculated_at (datetime): When statistics were last calculated

  • ready (bool): Whether file is ready for access

  • has_outdated_statistics (bool): Whether statistics need refresh

  • checksums (dict, optional): File checksums

  • locations (list, optional): Storage locations

  • format (str, optional): File format

  • user_id (str): ID of user who created/modified

  • transaction_id (str): Associated transaction ID

Return type:

FileInfo

Example

>>> path = Path("/my-space/file.tiff")
>>> info = path.stat()
>>> print(f"Name: {info.name}, Size: {info.size} bytes")
>>> print(f"Type: {info.type}, Ready: {info.ready}")
>>> print(f"Modified: {info.mod_time}")
property stem

Get the filename without the last extension.

Returns:

The stem (e.g., “image” from “image.tiff”)

Return type:

str

Example

>>> path = Path("/my-space/image.tiff")
>>> print(path.stem)  # "image"
property suffix

Get the file extension including the leading dot.

Returns:

The suffix (e.g., “.tiff”, “.png”) or empty string

Return type:

str

Example

>>> path = Path("/my-space/image.tiff")
>>> print(path.suffix)  # ".tiff"
property suffixes

Get all file extensions as a list.

Returns:

List of suffixes with leading dots (e.g., [“.tar”, “.gz”])

Return type:

List[str]

Example

>>> path = Path("/my-space/archive.tar.gz")
>>> print(path.suffixes)  # [".tar", ".gz"]

Remove a file or directory.

Parameters:

missing_ok (bool) – If True, don’t raise error if path doesn’t exist

Return type:

None

Example

>>> path = Path("/my-space/file.tiff")
>>> path.unlink()
with_segments(*path_segments)

Construct a new path object inheriting the current client.

Parameters:

*path_segments – Path segments to construct the new path

Returns:

New Path object with the given segments

Return type:

Path

Example

>>> base = Path("/my-space")
>>> new_path = base.with_segments("folder", "file.tiff")