Skip to main content

GHA Tests Conda-forge PyPI

PyDrive2

PyDrive2 is a wrapper library of google-api-python-client that simplifies many common Google Drive API V2 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 V2 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.

  • Provides fsspec filesystem implementation.

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']))

Fsspec filesystem

PyDrive2 provides easy way to work with your files through fsspec compatible GDriveFileSystem.

Install PyDrive2 with the required dependencies

$ pip install PyDrive2[fsspec]
from pydrive2.fs import GDriveFileSystem

# replace `root` with ID of a drive or directory and give service account access to it
fs = GDriveFileSystem("root", client_id=my_id, client_secret=my_secret)

for root, dnames, fnames in fs.walk("root"):
    ...

Concurrent access made easy

All API functions made to be thread-safe.

Contributors

Thanks to all our contributors!

https://contrib.rocks/image?repo=iterative/PyDrive2

Release files for PyDrive2 1.21.3

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

Source distribution (sdist)

Source distribution for PyDrive2 1.21.3
File Size Uploaded
pydrive2-1.21.3.tar.gz 63.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for PyDrive2 1.21.3
File Interpreter ABI Platform
PyDrive2-1.21.3-py3-none-any.whl Python 3 none any Details

Total release size:111.3 kB

Release files / pydrive2-1.21.3.tar.gz

Download URL pydrive2-1.21.3.tar.gz
Size 63.3 kB
Tags Source
SHA-256 checksum
How to use checksums
649b84d60c637bc7146485039535aa8f1254ad156423739f07e5d32507447c13
BLAKE2b-256 checksum
How to use checksums
3fdc92b0beba58f09441219bb6720bebdb895317632db4778cfe1d21532d27e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2024.

Transparency log

Release files / PyDrive2-1.21.3-py3-none-any.whl

Download URL PyDrive2-1.21.3-py3-none-any.whl
Size 48.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
843a304f500e71508162807001f5e19487f272e8ff5648f43582bd24c6250200
BLAKE2b-256 checksum
How to use checksums
8cdeeef2e2661371b02d4231c5cacbb758a52ea9ea98cb5f52d69298641e2631
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2024.

Transparency log

Release history Release notifications | RSS feed

This release

1.21.3 This release

2 release files

1.21.2

2 release files

1.20.0

2 release files

1.18.1

2 release files

1.17.0

2 release files

1.16.2

2 release files

1.16.0

2 release files

1.15.4

2 release files

1.15.2

2 release files

1.15.1

2 release files

1.15.0

2 release files

1.14.0

2 release files

1.13.0

2 release files

1.12.1

2 release files

1.12.0

2 release files

1.11.2

2 release files

1.11.1

2 release files

1.11.0

2 release files

1.10.2

2 release files

1.10.1

2 release files

1.10.0

2 release files

1.9.4

2 release files

1.9.3

2 release files

1.9.2

2 release files

1.9.1

2 release files

1.9.0

2 release files

1.8.3

2 release files

1.8.2

2 release files

1.8.1

2 release files

1.8.0

2 release files

1.7.3

2 release files

1.7.2

2 release files

1.7.0

2 release files

1.6.3

2 release files

1.6.2

2 release files

1.6.1

2 release files

1.6.0

2 release files

1.4.14

2 release files

1.4.10

2 release files

1.4.9

2 release files

1.4.8

2 release files

1.4.7

2 release files

1.4.6

2 release files

1.4.5

2 release files

1.4.4

2 release files

1.4.2

2 release files

1.4.1

2 release files

1.4.0

2 release files

0.14.0

2 release files

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