Giter Site home page Giter Site logo

codegallivant / gdrive-python-wrapper Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 10 KB

Importable python wrapper to enable easy upload/download of files to/from Google Drive via Google Drive API.

License: MIT License

Python 100.00%
google-drive google-drive-api python pydrive

gdrive-python-wrapper's Introduction

gdrive-interact

Python script to enable users to easily upload/download files/folders to/from their Google Drive via Google Drive API.

Requirements

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

Usage

import gdrive_pyinteract as gdi

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

# Authenticate 
client = gdi.authenticate_client("creds.txt") # Saves access token credentials to creds.txt. 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 = gdi.get_id(client, "<drive_folder_name>/<drive_folder_name>/.../<folder_or_file_name>")

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

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

# Upload a folder
gdi.upload_folder(client, '<drive_folder_name>/<drive_folder_name>/.../<drive_folder_name>',rf"C:/.../<system_folder_name>")

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

# Download a folder
gdi.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.

gdrive-python-wrapper's People

Contributors

codegallivant avatar

Stargazers

Emanuele Sabetta avatar

Watchers

 avatar

gdrive-python-wrapper's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.