leaf_engine.io.gdrive.read ========================== .. py:module:: leaf_engine.io.gdrive.read Functions --------- .. autoapisummary:: leaf_engine.io.gdrive.read._download_file leaf_engine.io.gdrive.read._parse_url leaf_engine.io.gdrive.read._read_drive leaf_engine.io.gdrive.read.read_drive Module Contents --------------- .. py:function:: _download_file(file_url: str) -> io.BytesIO Downloads file stored on Google Drive. NOTE: The file you want to download needs to be shared with the service account you are using to make the request. .. py:function:: _parse_url(url: str) -> Tuple[str, str] Parses a Google Drive spreadsheets or file URL to extract file ID. .. py:function:: _read_drive(url: Optional[str] = None, path: Optional[str] = None, **kwargs) -> pandas.DataFrame Wrapped by read_drive to allow disk caching. See read_drive for documentation. .. py:function:: read_drive(url: Optional[str] = None, path: Optional[str] = None, cache: bool = True, **kwargs) -> pandas.DataFrame Reads CSV, Excel, or Google Spreadsheet file from Google Drive either by url or path. :param url: File URL. Can be copied from browser navigation bar. Defaults to None. :type url: Optional[str], optional :param path: File path. First part needs to be drive name. Defaults to None. :type path: Optional[str], optional :param cache: Whether to cache the result to disk. Defaults to True. This makes subsequent calls to read_drive faster. :type cache: bool, optional :param \*\*kwargs: Keyword arguments passed to pandas.read_csv or pandas.read_excel. Examples: >>> df = read_drive(url="https://drive.google.com/file/d/XXYYZZ/view?usp=sharing") >>> df = read_drive(path="Data Science/folder1/folder2/file.csv") :raises LeafGoogleDriveException: If both url and path are None or both are not None. :raises LeafGoogleDriveException: If file is not found on Google Drive. :raises LeafGoogleDriveException: If unable to download file from Google Drive. :raises ValueError: If neither pd.read_csv nor pd.read_excel can read the file. :returns: DataFrame read from file. :rtype: pd.DataFrame