Skip to main content

Google Drive API made easy.

Project description

Fork

This is simply a fork of the PyDrive repo. The code here comes directly from github. This was created back when PyDrive wasnt python3 compatible. But now it is, so this package is useless now. You should use the official one from google

PyDrive

PyDrive is a wrapper library of google-api-python-client that simplifies many common Google Drive API tasks.

Project Info

Features of PyDrive

  • Simplifies OAuth2.0 into just few lines with flexible settings.

  • Wraps Google Drive API into classes of each resource to make your program more object-oriented.

  • Helps common operations else than API calls, such as content fetching and pagination control.

How to install

You can install PyDrive with regular pip command.

$ pip install PyDrive

OAuth made easy

Download client_secrets.json from Google API Console and OAuth2.0 is done in two lines. You can customize behavior of OAuth2 in one settings file settings.yaml.

from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive

gauth = GoogleAuth()
gauth.LocalWebserverAuth()

drive = GoogleDrive(gauth)

File management made easy

Upload/update the file with one method. PyDrive will do it in the most efficient way.

file1 = drive.CreateFile({'title': 'Hello.txt'})
file1.SetContentString('Hello')
file1.Upload() # Files.insert()

file1['title'] = 'HelloWorld.txt'  # Change title of the file
file1.Upload() # Files.patch()

content = file1.GetContentString()  # 'Hello'
file1.SetContentString(content+' World!')  # 'Hello World!'
file1.Upload() # Files.update()

file2 = drive.CreateFile()
file2.SetContentFile('hello.png')
file2.Upload()
print('Created file %s with mimeType %s' % (file2['title'], file2['mimeType']))
# Created file hello.png with mimeType image/png

file3 = drive.CreateFile({'id': file2['id']})
print('Downloading file %s from Google Drive' % file3['title']) # 'hello.png'
file3.GetContentFile('world.png')  # Save Drive file as a local file

# or download Google Docs files in an export format provided.
# downloading a docs document as an html file:
docsfile.GetContentFile('test.html', mimetype='text/html')

File listing pagination made easy

PyDrive handles file listing pagination for you.

# Auto-iterate through all files that matches this query
file_list = drive.ListFile({'q': "'root' in parents"}).GetList()
for file1 in file_list:
  print('title: %s, id: %s' % (file1['title'], file1['id']))

# Paginate file lists by specifying number of max results
for file_list in drive.ListFile({'maxResults': 10}):
  print 'Received %s files from Files.list()' % len(file_list) # <= 10
  for file1 in file_list:
    print('title: %s, id: %s' % (file1['title'], file1['id']))

Project details


Download files

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

Source Distribution

PyDrive3-1.0.0.tar.gz (157.7 kB view details)

Uploaded Source

File details

Details for the file PyDrive3-1.0.0.tar.gz.

File metadata

  • Download URL: PyDrive3-1.0.0.tar.gz
  • Upload date:
  • Size: 157.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for PyDrive3-1.0.0.tar.gz
Algorithm Hash digest
SHA256 1d19e5ca52f49b29c506f999b40fd27623abfecf356f30031fa180683a5b122c
MD5 d522180430f58b6a0493660c3e5e401f
BLAKE2b-256 58605d67343ea4d482eaba9a891a0ffb51186c50a11059697f7e9198020f4b80

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page