Skip to content

codegallivant/gdrive-python-wrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

gdrive-interact

Easily allows users to upload/download files to/from their Google Drive via Google Drive API.

Requirements

  • Python
  • pip modules
    • pydrive
  • Google Drive API credentials file

Usage

import gdrive_interact

# Specify path to credentials file of Google Drive API
gdrive_interact.set_client_config_path("client_secrets.json")

# Authenticate 
client = gdrive_interact.authenticate_client("creds.txt") # Saves access token credentials. If file does not exist, one-time manual sign-in is done via browser and the file is auto-generated.

# Get id of file/folder
folder_id = gdrive_interact.get_id(client, "<drive_folder_name>/<drive_folder_name>/.../<folder_or_file_name>")

# Get list of files in a folder
file_list = gdrive_interact.list_files(client, folder_id)

# Upload a file
gdrive_interact.upload_file(client, '<drive_folder_name>/<drive_folder_name>/.../<drive_file_name>', "C:/.../<system_directory_name>", "<system_file_name>")

# Download a file
gdrive_interact.download_file(client, "<drive_folder_name>/<drive_folder_name>/.../<drive_file_name>", "C:/.../<system_directory_name>")

# Download a folder
gdrive_interact.download_folder(client, "<drive_folder_name>/<drive_folder_name>/.../<drive_folder_name>", "C:/.../<system_directory_name>", files_only=False) # Set files_only = True if you only want the files within, and not the folder itself

How to create a credentials file

In order to contact and successfully authenticate with your Drive account, you must have a credentials file. In the above example, it is client_secrets.json. To create one, see Google's API Console. Create a project and enable Google Drive API. Download the credentials file.

About

upload/download google drive content in one line of code

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages