Skip to main content

Google Drive API made easy.

Project description

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

To install the current development version from GitHub, use:

$  pip install git+https://github.com/googledrive/PyDrive.git#egg=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']))

Concurrent access made easy

All calls made are thread-safe. The underlying implementation in the google-api-client library is not thread-safe, which means that every request has to re-authenticate an http object. You can avoid this overhead by creating your own http object for each thread and re-use it for every call.

This can be done as follows:

# Create httplib.Http() object.
http = drive.auth.Get_Http_Object()

# Create file object to upload.
file_obj = drive.CreateFile()
file_obj['title'] = "file name"

# Upload the file and pass the http object into the call to Upload.
file_obj.Upload(param={"http": http})

You can specify the http-object in every access method which takes a param parameter.

Project details


Download files

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

Source Distributions

PyDrive-1.2.1.zip (1.6 MB view details)

Uploaded Source

PyDrive-1.2.1.tar.gz (1.5 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

PyDrive-1.2.1-py2.py3-none-any.whl (23.6 kB view details)

Uploaded Python 2Python 3

PyDrive-1.2.1-py2.7.egg (54.3 kB view details)

Uploaded Egg

File details

Details for the file PyDrive-1.2.1.zip.

File metadata

  • Download URL: PyDrive-1.2.1.zip
  • Upload date:
  • Size: 1.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for PyDrive-1.2.1.zip
Algorithm Hash digest
SHA256 ea1786e1329d9f1c7cd3fc8683d6c03290b4015884da41785f19df4c0388d6fd
MD5 3dd06369c7e5961d8989c6f109ac0380
BLAKE2b-256 33c4b89f208bd33f79b13782bc4cc462d488b43646d6b328b7d2171710f83c2a

See more details on using hashes here.

File details

Details for the file PyDrive-1.2.1.tar.gz.

File metadata

  • Download URL: PyDrive-1.2.1.tar.gz
  • Upload date:
  • Size: 1.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for PyDrive-1.2.1.tar.gz
Algorithm Hash digest
SHA256 0606628aa88e50f427070f184b1f8007a36ce316e11648dda70bd213870205aa
MD5 ea5e53d78fbfdc62e42208df325519df
BLAKE2b-256 13f5eda572b01aa89d383dd84020437cfcf8502a96e58aee05698e24ce80e1a7

See more details on using hashes here.

File details

Details for the file PyDrive-1.2.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for PyDrive-1.2.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 49af56998e3cc02486ca1ff36265cf8146356a9b2581056ce8c674636dcdbd12
MD5 2213ab65108c4e84e72a1d56fd1119a2
BLAKE2b-256 d33176c751b90192afe443f0cf5f058af170b3bcb5f245bf1255dbac3c715a23

See more details on using hashes here.

File details

Details for the file PyDrive-1.2.1-py2.7.egg.

File metadata

  • Download URL: PyDrive-1.2.1-py2.7.egg
  • Upload date:
  • Size: 54.3 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for PyDrive-1.2.1-py2.7.egg
Algorithm Hash digest
SHA256 b4f1bb1b2f85510f83a0dc3996b92e8bc9626326b9f078d58a26790dca2b0ad3
MD5 f890acf9b697a9a8e6dc048858d5d23a
BLAKE2b-256 fe62f159ce331714c62faa0f11b659598883fd31d8390f156a6eff6911bf5741

See more details on using hashes here.

Supported by

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