pysepal.scripts.drive_interface.GDriveInterface#

class pysepal.scripts.drive_interface.GDriveInterface(sepal_headers=None)[source]#

Google Drive interface with SEPAL credential integration.

This class provides methods to interact with Google Drive using SEPAL credentials or file-based credentials. It supports automatic token refresh and various file operations.

Initialize the Google Drive interface.

Parameters:

sepal_headers (dict | None) – Optional SEPAL headers dictionary for authentication. If not provided, falls back to file-based credentials.

Raises:

ValueError – If credentials file not found or no access token available.

Attributes

service

Lazy property that ensures valid credentials and service.

Methods

__init__

Initialize the Google Drive interface.

delete_file

Delete a file from Google Drive.

download_file

Download a file from Google Drive.

download_from_task_file

Download csv file result from GDrive.

get_id

Get the Google Drive file ID for a given filename.

get_items

Get a list of CSV files from Google Drive.

get_task

Get the current state of the task.

print_file_list

Print a list of files from Google Drive to the console.

refresh_credentials

Refresh credentials synchronously by calling SEPAL API or re-reading file.

GDriveInterface.__init__(sepal_headers=None)[source]#

Initialize the Google Drive interface.

Parameters:

sepal_headers (dict | None) – Optional SEPAL headers dictionary for authentication. If not provided, falls back to file-based credentials.

Raises:

ValueError – If credentials file not found or no access token available.

GDriveInterface.delete_file(filename)[source]#

Delete a file from Google Drive.

Parameters:

filename (str) – Name of the file to delete.

GDriveInterface.download_file(filename, output_file, sepal_client=None)[source]#

Download a file from Google Drive.

Parameters:
  • filename (str) – Name of the file to download.

  • output_file (str or Path) – Path where the file should be saved.

  • sepal_client – Optional SEPAL client for remote file operations.

GDriveInterface.download_from_task_file(task_id, tasks_file, task_filename, sepal_client=None)[source]#

Download csv file result from GDrive.

Parameters:
  • task_id (str) – id of the task tasked in GEE.

  • tasks_file (Path) – path file containing all task_id, task_name

  • task_filename (str) – name of the task file to be downloaded.

GDriveInterface.get_id(filename)[source]#

Get the Google Drive file ID for a given filename.

Parameters:

filename (str) – Name of the file to search for.

Returns:

(success_flag, file_id_or_error_message)

Return type:

tuple

GDriveInterface.get_items()[source]#

Get a list of CSV files from Google Drive.

Returns:

List of CSV files with their metadata.

Return type:

list

GDriveInterface.get_task(task_id)[source]#

Get the current state of the task.

GDriveInterface.print_file_list()[source]#

Print a list of files from Google Drive to the console.

GDriveInterface.refresh_credentials()[source]#

Refresh credentials synchronously by calling SEPAL API or re-reading file.

Return type:

None