API Reference
This page provides a detailed API reference for the gdrive-suite library,
automatically generated from the source code doc-strings.
Main Client
The primary interface for interacting with Google Drive and Sheets.
gdrive_suite.GDriveClient
Provides functionality to: - Download files from Google Drive with or without conversion - Upload files to Google Drive - Retrieve Google Sheets data
Source code in src/gdrive_suite/drive/gdrive_client.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | |
__init__(drive_config_manager)
Initializes the GdriveService :param drive_config_manager: A ConfigManager that provides Outh2 credentials.
Source code in src/gdrive_suite/drive/gdrive_client.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
download_file(target)
Download a file from Google Drive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
DownloadTarget
|
A |
required |
Raises: APIError: If the download fails due to a Google API error. IOError: For local file system errors.
Source code in src/gdrive_suite/drive/gdrive_client.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
find_folder_id_by_path(start_folder_id, path_segments)
Find a folder's ID by navigating a path of folder names. Args: start_folder_id: The ID of the folder to start from. path_segments: A list of folder names to navigate. Return: The ID of the folder.
Source code in src/gdrive_suite/drive/gdrive_client.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | |
list_files(query, **list_params)
Helper function to list files in Google Drive Args: query: A query for filtering results. See "Search for files" guide for support syntax. list_params: Additional parameters for listing files. Return: List of searches files.
Raises: APIError: If the list files fails due to Google API error.
Source code in src/gdrive_suite/drive/gdrive_client.py
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | |
retrieve_file_content(file_id)
Retrieve a file from Google Drive as BytesIO object Args file_id: Google ID of the file to get retrieve_file_content.
Return: BytesIO object containing the file content
Raises: APIError: If the retrieve fails due to Google API error. IOError: For local file system errors.
Source code in src/gdrive_suite/drive/gdrive_client.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
retrieve_sheet_data(spreadsheet_id, sheet_range)
Read data from a Google sheet Args: spreadsheet_id: ID for the Google sheet sheet_range: Range of cells to read (e.j., A1: Z90)
Returns:
| Type | Description |
|---|---|
List[List[Any]]
|
List of rows containing cell values |
Raises:
| Type | Description |
|---|---|
APIError
|
If retrieving data fails due to a Google API error. |
Source code in src/gdrive_suite/drive/gdrive_client.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | |
upload_file(file_path, folder_id, **metadata)
Upload file to Google Drive
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path
|
Path to the file to the upload |
required |
folder_id
|
str
|
ID of the folder to upload to |
required |
metadata
|
Any
|
Additional metadata to add the file |
{}
|
Raises:
| Type | Description |
|---|---|
APIError
|
If upload fails due to Google API error. |
IOError
|
For local file system errors. |
Source code in src/gdrive_suite/drive/gdrive_client.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
Configuration
Classes responsible for managing authentication and configuration.
gdrive_suite.GDriveClientConfig
Handles credential management including retrieving, refreshing, and storing oauth2 credentials for Google Drive API access, both local file based and default application credentials found in a server environment.
Source code in src/gdrive_suite/drive/gdrive_client_config.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | |
__init__(scopes, gdrive_settings)
Constructor for the GoogleDriveClientConfig
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scopes
|
List[str]
|
A list of OAuth2 scopers required for the application. |
required |
gdrive_settings
|
GDriveSettings
|
The configuration parameters for the Google Drive client. |
required |
Raises: ConfigDirectoryError: If config_dir_path is not a valid directory.
Source code in src/gdrive_suite/drive/gdrive_client_config.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |
get_credentials()
Retrieves valid Google API credetials using a prioritized strategy.
Returns:
| Type | Description |
|---|---|
Optional[Credentials]
|
A valid 'google.oauth2.credentials.Credentials' object. |
Raises:
| Type | Description |
|---|---|
CredentialsNotFoundError
|
If no credentials can be found or generated through any of the available methods. |
Source code in src/gdrive_suite/drive/gdrive_client_config.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |
gdrive_suite.GDriveSettings
dataclass
Configuration parameters for Google Drive client.
Attributes:
| Name | Type | Description |
|---|---|---|
config_dir_path |
Path
|
Path to the configuration directory where the token and credentials files are stored. |
token_file_name |
str
|
The filename for the stored user token. |
credentials_file_name |
str
|
The filename for the client secret file. |
Source code in src/gdrive_suite/context/models.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 | |
gdrive_suite.DownloadTarget
dataclass
Specifies the parameters for a file download operation
Attributes:
| Name | Type | Description |
|---|---|---|
file_id |
str
|
The unique ID of the file on Google Drive. |
destination_path |
Path
|
The full local path(including filename) wjere file will be saved. |
mime_type |
Optional[str]
|
An optional MIME type to convert a Google Workspace to a different format upon download (e.g., 'application/pdf'). |
Source code in src/gdrive_suite/context/models.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
Exceptions
Custom exceptions raised by the library.
gdrive_suite.GDriveSuiteError
Bases: Exception
Base Exception for all errors rised by the gdrive-suite library.
Source code in src/gdrive_suite/gdrive_exceptions.py
9 10 11 12 | |
gdrive_suite.GDriveAuthError
Bases: Exception
Base exception for authentication errors in this module.
Source code in src/gdrive_suite/gdrive_exceptions.py
15 16 17 18 | |
gdrive_suite.CredentialsNotFoundError
Bases: GDriveAuthError
Raised when no valid credentials can be found or generated.
Source code in src/gdrive_suite/gdrive_exceptions.py
21 22 23 24 | |
gdrive_suite.APIError
Bases: GDriveSuiteError
Raised when an API call to a Google service fails.
This exception abstracts away the underlying 'googleapiclient.http.HttpError' providing a consisteng error type for all API interactions within the suite.
Source code in src/gdrive_suite/gdrive_exceptions.py
27 28 29 30 31 32 33 34 | |