Skip to main content

Google drive command-line tools

Project description


Build Status


What's new

  • 0.98
    • added, able to remove files and folder.


Google drive command-line tools

Tools to maintain files on Google Drive.



  • Check your system has Python installed
    • gdcmdtools are developed under Python 2.7.3, I would suggest users to run the tools with Python 2.7.3.(OK: 2.7.2)
  • PIP
    • For Mac OSX
      1. sudo easy_install pip
      2. sudo pip install google-api-python-client
      3. sudo pip install gdcmdtools
    • For Ubuntu Linux
      1. sudo apt-get install python-pip
      2. sudo pip install google-api-python-client
      3. sudo pip install gdcmdtools
    • After the installation, you will see gd*.py under /usr/local/bin.
  • Ubuntu Linux PPA
    1. sudo apt-add-repository ppa:ctf/gdcmdtools
    2. sudo apt-get update
    3. sudo apt-get install python-gdcmdtools

API Setup

  • Create a new project for this tool to access your Google drive

  • Enable the following Google APIs in "APIs & auth/APIs"

    • Drive API
    • Fusion Tables API
  • Make sure your application has an application name in "APIs & auth/Credentials/OAuthConsent screen"

    • Find "PRODUCT NAME" field. Make sure it's not blank.
  • Grant access to Google Drive for gdcmdtools in "APIs & auth/Credentials"

    1. Click "Create new Client ID", APPLICATION TYPE: Installed application, INSTALLED APPLICATION TYPE: Other
    2. Check the section "Client ID for native application", click at the "Download JSON".
    3. Execute in a terminal and give the downloaded secret file just downloaded as parameter: $ client_secrets.json
    4. You will see message like: INFO:gdcmdtools.base:Please visit the URL in your browser:
    5. Visit the URL with browser and allow the app accessing your Google Drive.
    6. Copy the code you see in your browser, then back to the terminal, paste the code and hit enter.
    7. Done, you won't be asked for the code again unless the credential expired.


Use the tool to pass the OAuth2 authentication


usage: [-h] [-r {local,oob}] secret_file

gdauth v0.0.1 - Google Drive OAuth2 authentication tool - gdcmdtools (Google Drive command line tools)

positional arguments:
  secret_file           the secret file in JSON format, ~/.gdcmdtools.secrets will be overwritten

optional arguments:
  -h, --help            show this help message and exit
  -r {local,oob}, --redirect_uri {local,oob}
                        specify the redirect URI for the oauth2 flow, could be:
                        local: means "http://localhost"
                        oob: (default) means "urn:ietf:wg:oauth:2.0:oob"

Examples for gdauth

% python ./ /tmp/client_secrets.json   # Use the /tmp/client_secrets.json as secret file


This tool can be used to upload files to Google drive as Spreadsheet,csv,fusion table,doc, etc.


usage: [-h] [-s SOURCE_TYPE] [-l TARGET_TITLE]
                [-d TARGET_DESCRIPTION] [--no_print_id] [-f FOLDER_ID]
                [--debug {debug,info,warning,error,critical}]
                [-p TYPE ROLE VALUE] [-t {raw,ft,pt,ss,doc,ocr,dr,gas}]
                [--ft_latlng_column FT_LATLNG_COLUMN]
                [--ft_location_column FT_LOCATION_COLUMN]
                [--csv_column_define define1_define2_defineN...]

gdput v0.91 - Tool to upload file to Google Drive - gdcmdtools (Google Drive command line tools)

positional arguments:
  source_file           The file you're going to upload to Google Drive

optional arguments:
  -h, --help            show this help message and exit
  -s SOURCE_TYPE, --source_type SOURCE_TYPE
                        define the source file type by MIME type,
                        ex: "text/csv", or "auto" to determine the file type by file name
  -l TARGET_TITLE, --target_title TARGET_TITLE
                        specify the title of the target file
                        specify the description of the target file
  --no_print_id         set if you like not to print the file id after file being uploaded
  -f FOLDER_ID, --folder_id FOLDER_ID
                        the target folder ID on the Google drive
  --debug {debug,info,warning,error,critical}
                        define the debug level
                        set the permission of the uploaded file, can be:
                        type: user, group, domain, anyone
                        role: owner, reader, writer
                        value: user or group e-mail address,
                        or 'me' to refer to the current authorized user
                        ex: -p anyone reader me # set the uploaded file public-read
  -t {raw,ft,pt,ss,doc,ocr,dr,gas}, --target_type {raw,ft,pt,ss,doc,ocr,dr,gas}
                        define the target file type on Google Drive, can be:
                        raw: (default) the source file will uploaded without touching
                        ft: Fusion Table (for .csv)
                        pt: Presentation (for .ppt, .pps, .pptx)
                        ss: Spreadsheet (for .xls, .xlsx, .ods, .csv, .tsv, .tab)
                        doc: Document (for .doc, .docx, .html, .htm, .txt, .rtf)
                        ocr: OCR (for .jpg, .git, .png, .pdf)
                        dr: Drawing (for .wmf)
                        gas: GAS project (for .json)

fusion table support (--target_type ft):
  --ft_latlng_column FT_LATLNG_COLUMN
                        specify the column header for latitude and longitude for the fusion table,
                        the column will be created automatically
  --ft_location_column FT_LOCATION_COLUMN
                        specify the location column header for the fusion table
  --csv_column_define define1_define2_defineN...
                        define the columns type for each column of the csv file,
                        can be "string", "number", "datetime", or "location".
                        ex: has 4 columns in the csv file: "name", "age", "birthday", "address".
                        you can set --csv_column_define string_number_datetime_location

Examples for gdput

% python ./ photo.jpg                    # upload photo.jpg to gd without changing the format
% python ./ -t ft samples/sample.csv     # upload a csv file to gd as fusion table
% python ./ -t ss samples/sample.csv     # upload a csv file to gd as spreadsheet
% python ./ -t ft --ft_location_column address  --ft_latlng_column latlng  samples/sample.csv 
                                          # upload a csv to gd as fusion table with geocoding the latitude longitude data according to the address rows
% python ./ -p anyone reader me samples/sample.csv     
                                          # upload a csv file as Spreadsheet and set the file public-read
% python ./ -t ft --csv_column_define string_string_location_string_string_number samples/sample.csv
                                          # upload a csv file as ft with specifed column type
% python ./ -t gas gas_project.json
                                          # update gas project with project file 'gas_project.json'


get files from google drive


usage: [-h] [-f FORMAT] [-s NEW_FILE_NAME]
                [--debug {debug,info,warning,error,critical}]

gdget v0.91 - Tool to download file from Google Drive - gdcmdtools (Google Drive command line tools)

positional arguments:
  file_id               The id for the file you're going to download

optional arguments:
  -h, --help            show this help message and exit
  -f FORMAT, --export_format FORMAT
                        specify the export format for downloading,
                        google_format: export_format
                        spreadsheet: pdf, ods, xlsx
                        drawing: png, pdf, jpeg, svg
                        document: pdf, docx, rtf, odt, html, txt
                        script+json: json
                        presentation: pdf, pptx, txt
                        save the downloaded file as 
  --debug {debug,info,warning,error,critical}
                        define the debug level

Examples for gdget

% python ./ FILE_ID --export_format pdf -s /tmp/myfile.pdf # export the file as pdf and save as /tmp/myfile.pdf
% python ./ FILE_ID -f json # down files associated with GAS project


This tool can be used to set up file's permission


usage: [-h]
                 [--list | --get PERMISSION_ID | --insert TYPE ROLE VALUE | --delete PERMISSION_ID]

gdperm v0.0.1 - Tool to change file's permission on Google Drive - gdcmdtools (Google Drive command line tools)

positional arguments:
  file_id               The id of file you're going to change permission

optional arguments:
  -h, --help            show this help message and exit
  --list                list the permission resource of the file
  --get PERMISSION_ID   get the permission resource by id
  --insert TYPE ROLE VALUE
                        insert the permission to the file by id
  --delete PERMISSION_ID
                        delete the permission of the file by id

Examples for gdperm

% python ./ 0B_XXXXXXXXXX --insert anyone reader me   # set the file as public-read
% python ./ 0B_XXXXXXXXXX --list                      # list the permissions by file id: 0B_XXXXXXXXXX
% python ./ 0B_XXXXXXXXXX --get 5566520               # get the permissions by permission id: 5566520
% python ./ 0B_XXXXXXXXXX --delete 5566520            # delete the permissions by permission id: 5566520



BSD 2-Clause License


Please report bugs via


Tien Fu Chen

Email: tienfu.c @

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for gdcmdtools3, version 1.7.1
Filename, size File type Python version Upload date Hashes
Filename, size gdcmdtools3-1.7.1-py3-none-any.whl (31.1 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size gdcmdtools3-1.7.1.tar.gz (21.0 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page