paths#

This module contains methods for different path extraction. Simplest method just provides specific parent of given path and more complex provide ways to extract paths from dictionaries.

get_parent_path#

pocketwelt.paths.get_parent_path(path: str, level: int = 1, absolute: bool = True) str#

Find parent of a given path.

Parameters:
  • path (str) – Path to get parent of.

  • level (int, optional) – How distant parent to look for. Defaults to 1.

  • absolute (str) – Return the absolute path to the parent. Defaults to True.

Returns:

Parent path of the given path.

Return type:

str

list_all_paths#

pocketwelt.paths.list_all_paths(directory: str) List[str]#

List all paths from the given directory.

Parameters:

directory (str) – Path to the directory.

Returns:

List of all paths in the directory.

Return type:

List[str]

build_all_paths#

pocketwelt.paths.build_all_paths(structure: Dict[str, Any], current_path: list | None = None, result: dict | None = None) Dict[str, Any]#

Recursively build a dictionary of all paths from a nested dictionary.

Parameters:
  • structure (Dict[str, Any]) – The nested dictionary structure to process.

  • current_path (Optional[list], optional) – The current path being processed. Defaults to None.

  • result (Optional[dict], optional) – The dictionary to store the results. Defaults to None.

Returns:

A dictionary containing all paths from the nested dictionary.

Return type:

Dict[str, Any]

build_top_paths#

pocketwelt.paths.build_top_paths(structure: Dict[str, Any], current_path: str | None = None) List[str]#

Recursively build a list of all possible paths for a given nested dictionary.

Parameters:
  • structure (Dict[str, Any]) – The nested dictionary structure to process.

  • current_path (Optional[str], optional) – The current path being processed. Defaults to None.

Returns:

A list of all possible paths from the nested dictionary.

Return type:

List[str]

get_all_attributes#

pocketwelt.paths.get_all_attributes(structure: Dict[str, Any], attrs: List[str] | None = None) List[str]#

Recursively retrieve all names that exist in the nested dictionary.

Parameters:
  • structure (Dict[str, Any]) – The nested dictionary structure to process.

  • attrs (Optional[List[str]], optional) – The list to store the attribute names. Defaults to None.

Returns:

A list of all unique attribute names in the nested dictionary.

Return type:

List[str]