pysepal.scripts.sepal_client.SepalClient#

class pysepal.scripts.sepal_client.SepalClient(session_id, module_name, sepal_host=None, create_base_dir=True)[source]#

Initialize the Sepal HTTP client.

Parameters:
  • session_id (str) – The SEPAL session ID for authentication

  • module_name (str) – The name of the module using the client, it creates the module results directory if create_base_dir is True.

  • sepal_host (str | None) – Optional SEPAL host, if None uses SEPAL_HOST environment variable

  • create_base_dir (bool) – If True, creates the base results directory for the module

Methods

__init__

Initialize the Sepal HTTP client.

create_base_dir

Create the base results directory and return the PurePosixPath object.

get_file

Download a file from the specified folder.

get_remote_dir

Create a remote directory and return its sanitized path.

list_files

List files in a specified folder with optional extension filtering.

rest_call

Make HTTP requests and handle JSON/binary responses.

sanitize_path

Sanitize a file path to be relative to the base remote path.

set_file

Upload any content (text or binary) via multipart/form-data.

SepalClient.__init__(session_id, module_name, sepal_host=None, create_base_dir=True)[source]#

Initialize the Sepal HTTP client.

Parameters:
  • session_id (str) – The SEPAL session ID for authentication

  • module_name (str) – The name of the module using the client, it creates the module results directory if create_base_dir is True.

  • sepal_host (str | None) – Optional SEPAL host, if None uses SEPAL_HOST environment variable

  • create_base_dir (bool) – If True, creates the base results directory for the module

SepalClient.create_base_dir()[source]#

Create the base results directory and return the PurePosixPath object.

Return type:

PurePosixPath

SepalClient.get_file(file_path, parse_json=False)[source]#

Download a file from the specified folder.

Parameters:
  • file_path (str) – The file path to download

  • parse_json – If True, parse the response as JSON; otherwise return raw bytes

Returns:

The file content as bytes

Return type:

bytes

SepalClient.get_remote_dir(folder, parents=False)[source]#

Create a remote directory and return its sanitized path.

Parameters:
  • folder (str | Path)

  • parents (bool)

Return type:

PurePosixPath

SepalClient.list_files(folder='/', extensions=None)[source]#

List files in a specified folder with optional extension filtering.

Parameters:
  • folder (str) – The folder path to list files from

  • extensions (List[str] | None) – Optional list of file extensions to filter by

Returns:

Dict containing the API response

Return type:

Dict[str, Any]

SepalClient.rest_call(method, endpoint, params=None, data=None, json=None, files=None, parse_json=True)[source]#

Make HTTP requests and handle JSON/binary responses.

Parameters:
  • method (Literal['GET', 'POST', 'PUT'])

  • endpoint (str)

  • params (Dict[str, Any] | None)

  • data (str | None)

  • json (Dict[str, Any] | None)

  • files (Dict[str, Any] | None)

  • parse_json (bool)

Return type:

Dict[str, Any] | bytes

SepalClient.sanitize_path(file_path)[source]#

Sanitize a file path to be relative to the base remote path.

Parameters:

file_path (str | Path)

Return type:

PurePosixPath

SepalClient.set_file(file_path, content, overwrite=False)[source]#

Upload any content (text or binary) via multipart/form-data.

Parameters:
  • file_path (str) – The path where the file will be saved on the server

  • content (str | bytes) – The content to upload, can be a string or bytes

  • overwrite (bool) – If True, allows overwriting existing files on the server

Return type:

Dict[str, Any]