Skip to main content

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.

Metadata

Release files for PyDrive 1.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distributions (sdists)

Source distribution for PyDrive 1.2.1
File Size Uploaded Provenance Actions
PyDrive-1.2.1.zip 1.6 MB Without provenance Details for PyDrive-1.2.1.zip
PyDrive-1.2.1.tar.gz 1.5 MB Without provenance Details for PyDrive-1.2.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for PyDrive 1.2.1
File Interpreter ABI Platform Actions
PyDrive-1.2.1-py2.py3-none-any.whl Python 3, Python 2 none any Details for PyDrive-1.2.1-py2.py3-none-any.whl
PyDrive-1.2.1-py2.7.egg Legacy Egg format - - Details for PyDrive-1.2.1-py2.7.egg

Total release size: 3.2 MB

Release files / PyDrive-1.2.1.zip

Download URL PyDrive-1.2.1.zip
Size 1.6 MB
Tags Source
SHA-256 checksum
How to use checksums
ea1786e1329d9f1c7cd3fc8683d6c03290b4015884da41785f19df4c0388d6fd
BLAKE2b-256 checksum
How to use checksums
33c4b89f208bd33f79b13782bc4cc462d488b43646d6b328b7d2171710f83c2a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / PyDrive-1.2.1.tar.gz

Download URL PyDrive-1.2.1.tar.gz
Size 1.5 MB
Tags Source
SHA-256 checksum
How to use checksums
0606628aa88e50f427070f184b1f8007a36ce316e11648dda70bd213870205aa
BLAKE2b-256 checksum
How to use checksums
13f5eda572b01aa89d383dd84020437cfcf8502a96e58aee05698e24ce80e1a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / PyDrive-1.2.1-py2.py3-none-any.whl

Download URL PyDrive-1.2.1-py2.py3-none-any.whl
Size 23.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
49af56998e3cc02486ca1ff36265cf8146356a9b2581056ce8c674636dcdbd12
BLAKE2b-256 checksum
How to use checksums
d33176c751b90192afe443f0cf5f058af170b3bcb5f245bf1255dbac3c715a23
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / PyDrive-1.2.1-py2.7.egg

Download URL PyDrive-1.2.1-py2.7.egg
Size 54.3 kB
Tags Egg
SHA-256 checksum
How to use checksums
b4f1bb1b2f85510f83a0dc3996b92e8bc9626326b9f078d58a26790dca2b0ad3
BLAKE2b-256 checksum
How to use checksums
fe62f159ce331714c62faa0f11b659598883fd31d8390f156a6eff6911bf5741
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for PyDrive 1.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page