leaf_engine.io.gdrive.write =========================== .. py:module:: leaf_engine.io.gdrive.write Functions --------- .. autoapisummary:: leaf_engine.io.gdrive.write._setup_media leaf_engine.io.gdrive.write.create_folder leaf_engine.io.gdrive.write.create_folders leaf_engine.io.gdrive.write.to_drive Module Contents --------------- .. py:function:: _setup_media(df: pandas.DataFrame, path: str, **kwargs) -> googleapiclient.http.MediaIoBaseUpload Creates MediaIoBaseUpload object with appropriate mime type. .. py:function:: create_folder(name: str, parent_folder_id: Optional[str], drive_id: str, exist_ok: bool = True) -> Optional[str] If `exist_ok`, tries to find existing folder ID given name and parent_folder_id. If no such folder exists or not `exist_ok`, creates the folder in the given parent (note that Google Drive allows multiple folders with same name in same parent). :param name: Folder name. :type name: str :param parent_folder_id: Where to put the folder. Parent folder ID can be found in the parent folder URL. If None, creates folder in Drive root. :type parent_folder_id: Optional[str] :param exist_ok: Return existing folder ID, if available. Defaults to True. :type exist_ok: bool :returns: Google Drive ID of created folder. :rtype: str .. py:function:: create_folders(folders: List[str], drive_id: str, parent_folder_id: Optional[str] = None, exist_ok: bool = True) -> Optional[str] Creates folder tree from list of folder names in given parent folder. If no parent folder provided, creates folder tree in root folder. :param folders: List of folder names. :type folders: List[str] :param drive_id: Google Drive ID. :type drive_id: str :param parent_folder_id: Folder ID of parent folder. Defaults to None. :type parent_folder_id: str :param exist_ok: Existing folders can be re-used. Defaults to True. :type exist_ok: bool, optional :returns: Google Drive ID of last folder in list. :rtype: str .. py:function:: to_drive(df: pandas.DataFrame, path: str, overwrite: bool = False, **kwargs) -> str Write a DataFrame to a file on Google Drive, at the specified path. :param df: DataFrame to write. :type df: pd.DataFrame :param path: Path to write to. First part of path is the drive name. :type path: str :param overwrite: Overwrite existing file. Defaults to False. :type overwrite: bool, optional Examples: >>> df.pipe(gdrive.to_drive, "drive_name/folder1/folder2/file_name.csv") >>> df.pipe(gdrive.to_drive, "drive_name/folder1/folder2/file_name.xlsx") :raises LeafGoogleDriveException: Raised if `overwrite` is False and file exists. :raises LeafGoogleDriveException: Raised if path is invalid. :raises LeafGoogleDriveException: Raised if write response does not contain file ID. :returns: Google Drive file URL. :rtype: str