airflow.providers.google.suite.hooks.drive

用於 Google Drive 服務的 Hook。

GoogleDriveHook

用於 Google Drive API 的 Hook。

模組內容

class airflow.providers.google.suite.hooks.drive.GoogleDriveHook(api_version='v3', gcp_conn_id='google_cloud_default', impersonation_chain=None)[source]

基類:airflow.providers.google.common.hooks.base_google.GoogleBaseHook

用於 Google Drive API 的 Hook。

引數::
  • api_version (str) – 使用的 API 版本(例如 v3)。

  • gcp_conn_id (str) – 獲取連線資訊時使用的連線 ID。

  • impersonation_chain (str | collections.abc.Sequence[str] | None) – 可選的服務賬號,用於使用短期憑據進行模擬,或者透過一系列賬號鏈獲取列表中最後一個賬號的 access_token,並在請求中模擬該賬號。如果設定為字串,該賬號必須授予發起賬號 Service Account Token Creator IAM 角色。如果設定為序列,列表中的身份必須授予直接前置身份 Service Account Token Creator IAM 角色,列表中第一個賬號授予發起賬號該角色。

api_version = 'v3'[source]
get_conn()[source]

檢索 Google Drive 連線。

返回::

Google Drive 服務物件。

返回型別::

Any

get_media_request(file_id)[source]

返回對 Google Drive 物件的 get_media http 請求。

引數::

file_id (str) – Google Drive 檔案 ID

返回::

request

返回型別::

googleapiclient.http.HttpRequest

exists(folder_id, file_name, drive_id=None, *, include_trashed=True)[source]

檢查 Google Drive 資料夾中是否存在檔案。

引數::
  • folder_id (str) – 檔案所在的 Google Drive 資料夾的 ID

  • file_name (str) – Google Drive 中的檔名

  • drive_id (str | None) – 可選。檔案所在的共享 Google Drive 的 ID。

  • include_trashed (bool) – 是否包含回收站中的物件,預設為 True,與 Google API 一致。

返回::

如果檔案存在則為 True,否則為 False

返回型別::

bool

get_file_id(folder_id, file_name, drive_id=None, *, include_trashed=True)[source]

返回 Google Drive 檔案的檔案 ID。

引數::
  • folder_id (str) – 檔案所在的 Google Drive 資料夾的 ID

  • file_name (str) – Google Drive 中的檔名

  • drive_id (str | None) – 可選。檔案所在的共享 Google Drive 的 ID。

  • include_trashed (bool) – 是否包含回收站中的物件,預設為 True,與 Google API 一致。

返回::

如果檔案存在,則返回 Google Drive 檔案 ID,否則返回 None

返回型別::

dict

upload_file(local_location, remote_location, chunk_size=100 * 1024 * 1024, resumable=False, folder_id='root', show_full_target_path=True)[source]

將本地檔案上傳到 Google Drive 服務。

引數::
  • local_location (str) – 檔案的本地路徑。

  • remote_location (str) – 檔案將被髮送到的路徑

  • chunk_size (int) – 檔案將按此大小(位元組)分塊上傳。僅當 resumable=True 時使用。如果要將檔案作為一個整體上傳,請傳遞 -1。請注意,Google App Engine 對請求大小有限制(5MB),因此塊大小不應大於 5MB,也不應設定為 -1。

  • resumable (bool) – 如果這是可恢復上傳,則為 True。False 表示一次性上傳。

  • folder_id (str) – remote_location 的基礎/根資料夾 ID(資料夾 Drive URL 的一部分)。

  • show_full_target_path (bool) – 如果為 True,則在日誌中顯示完整的可用檔案路徑。

返回::

檔案 ID

返回型別::

str

download_file(file_id, file_handle, chunk_size=100 * 1024 * 1024)[source]

從 Google Drive 下載檔案。

引數::
  • file_id (str) – 檔案的 ID

  • file_handle (IO) – 用於寫入內容的 檔案控制代碼

  • chunk_size (int) – 檔案將按此大小(位元組)分塊下載。

此條目有用嗎?