platypush.plugins.google.drive

class platypush.plugins.google.drive.GoogleDrivePlugin(*args, **kwargs)[source]

Google Drive plugin.

__init__(*args, **kwargs)[source]

Initialized the Google plugin with the required scopes.

Parameters:scopes (list) – List of required scopes
copy(file_id: str) → platypush.message.response.google.drive.GoogleDriveFile[source]

Create a copy of a file. :param file_id: File ID.

create(name: str, description: Optional[str] = None, mime_type: Optional[str] = None, parents: Optional[List[str]] = None, starred: bool = False) → platypush.message.response.google.drive.GoogleDriveFile[source]

Create a file.

Parameters:
  • name – File name.
  • description – File description.
  • mime_type – File MIME type.
  • parents – List of folder IDs that will contain the file (default: drive root).
  • starred – If True then the file will be marked as starred.
delete(file_id: str)[source]

Delete a file from Google Drive. :param file_id: File ID.

download(file_id: str, path: str) → str[source]

Download a Google Drive file locally.

Parameters:
  • file_id – Path of the file to upload.
  • path – Path of the file to upload.
Returns:

The local file path.

empty_trash()[source]

Empty the Drive bin.

files(filter: Optional[str] = None, folder_id: Optional[str] = None, limit: Optional[int] = 100, drive_id: Optional[str] = None, spaces: Union[str, List[str], None] = None, order_by: Union[str, List[str], None] = None) → Union[platypush.message.response.google.drive.GoogleDriveFile, List[platypush.message.response.google.drive.GoogleDriveFile]][source]

Get the list of files.

Parameters:
  • filter – Optional filter (default: None). See Google Drive API docs for the supported syntax.
  • folder_id – Drive folder ID to search (default: get all files).
  • limit – Maximum number of entries to be retrieves (default: 100).
  • drive_id – Shared drive ID to search (default: None).
  • spaces

    Drive spaces to search. Supported values:

    • drive
    • appDataFolder
    • photos
  • order_by

    Order the results by a specific attribute or list of attributes (default: None). Supported attributes:

    • createdTime
    • folder
    • modifiedByMeTime
    • modifiedTime
    • name
    • name_natural
    • quotaBytesUsed
    • recency
    • sharedWithMeTime
    • starred
    • viewedByMeTime

    Attributes will be sorted in ascending order by default. You can change that by by appending “desc” separated by a space to the attribute you want in descending order - e.g. ["folder", "createdTime desc", "modifiedTime desc"].

get(file_id: str)[source]

Get the information of a file on the Drive by file ID. :param file_id: File ID.

update(file_id: str, name: Optional[str] = None, description: Optional[str] = None, add_parents: Optional[List[str]] = None, remove_parents: Optional[List[str]] = None, mime_type: Optional[str] = None, starred: bool = None, trashed: bool = None) → platypush.message.response.google.drive.GoogleDriveFile[source]

Update the metadata or the content of a file.

Parameters:
  • file_id – File ID.
  • name – Set the file name.
  • description – Set the file description.
  • add_parents – Add the file to these parent folder IDs.
  • remove_parents – Remove the file from these parent folder IDs.
  • mime_type – Set the file MIME type.
  • starred – Change the starred flag.
  • trashed – Move/remove from trash.
upload(path: str, mime_type: Optional[str] = None, name: Optional[str] = None, description: Optional[str] = None, parents: Optional[List[str]] = None, starred: bool = False, target_mime_type: Optional[str] = None) → platypush.message.response.google.drive.GoogleDriveFile[source]

Upload a file to Google Drive.

Parameters:
  • path – Path of the file to upload.
  • mime_type – MIME type of the source file (e.g. “image/jpeg”).
  • name – Name of the target file. Default: same name as the source file.
  • description – File description.
  • parents – List of folder IDs that will contain the file (default: drive root).
  • starred – If True, then the uploaded file will be marked as starred by the user.
  • target_mime_type – Target MIME type. Useful if you want to e.g. import a CSV file as a Google Sheet (use “application/vnd.google-apps.spreadsheet), or an ODT file to a Google Doc (use “application/vnd.google-apps.document). See the official documentation for a complete list of supported types.