Skip to main content

Google Drive API made easy. Maintained fork of PyDrive.

Project description

Travis

PyDrive2

PyDrive2 is a wrapper library of google-api-python-client that simplifies many common Google Drive API tasks. It is an actively maintained fork of https://pypi.python.org/pypi/PyDrive. By the authors and maintainers of the Git for Data - DVC project.

Project Info

Features of PyDrive2

  • 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 PyDrive2 with regular pip command.

$ pip install PyDrive2

To install the current development version from GitHub, use:

$  pip install git+https://github.com/iterative/PyDrive2.git#egg=PyDrive2

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 pydrive2.auth import GoogleAuth
from pydrive2.drive import GoogleDrive

gauth = GoogleAuth()
gauth.LocalWebserverAuth()

drive = GoogleDrive(gauth)

File management made easy

Upload/update the file with one method. PyDrive2 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

PyDrive2 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: {}, id: {}'.format(file1['title'], file1['id']))

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

Concurrent access made easy

All API functions made to be thread-safe.

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

PyDrive2-1.6.3.tar.gz (989.2 kB view details)

Uploaded Source

Built Distribution

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

PyDrive2-1.6.3-py2.py3-none-any.whl (31.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file PyDrive2-1.6.3.tar.gz.

File metadata

  • Download URL: PyDrive2-1.6.3.tar.gz
  • Upload date:
  • Size: 989.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.7.1

File hashes

Hashes for PyDrive2-1.6.3.tar.gz
Algorithm Hash digest
SHA256 e5d564693e77979504ea4ca34b066e3832c887b5bbc0856e15b86972a093d13a
MD5 5daffd2724b3e0023231c491a1b8be47
BLAKE2b-256 d420cdc02610ebe9b7574ba6e5d4f1c29f21944001e825dff351a916af06e7f7

See more details on using hashes here.

File details

Details for the file PyDrive2-1.6.3-py2.py3-none-any.whl.

File metadata

  • Download URL: PyDrive2-1.6.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 31.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.7.1

File hashes

Hashes for PyDrive2-1.6.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ca6dc1e92dd3b9cd265a46be207620150909a4b7da0e1d6a59ac4b30a5e41d0a
MD5 426b7a2f06df5fff5c7fda55343c09dd
BLAKE2b-256 509578c69685d28da2254055f8b4f8f63cbe92b120a07ee805cbe9c3a9823b71

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