Google Drive API made easy. Maintained fork of PyDrive.
Project description
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
Documentation: https://docs.iterative.ai/PyDrive2
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!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pydrive2-1.21.1.tar.gz
.
File metadata
- Download URL: pydrive2-1.21.1.tar.gz
- Upload date:
- Size: 63.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 70da0244a29a6922e28620a32e251ac6ab018449f1bb0485e9a39114a069dde0 |
|
MD5 | 8e35eded745286482f1cf39fa29dabaf |
|
BLAKE2b-256 | a72c34370cc28e031214afca20de117745a6c0f66f132805d42b11ac02b346f1 |
Provenance
The following attestation bundles were made for pydrive2-1.21.1.tar.gz
:
Publisher:
publish.yml
on iterative/PyDrive2
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
pydrive2-1.21.1.tar.gz
- Subject digest:
70da0244a29a6922e28620a32e251ac6ab018449f1bb0485e9a39114a069dde0
- Sigstore transparency entry: 146140144
- Sigstore integration time:
- Predicate type:
File details
Details for the file PyDrive2-1.21.1-py3-none-any.whl
.
File metadata
- Download URL: PyDrive2-1.21.1-py3-none-any.whl
- Upload date:
- Size: 47.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d24b3334bc5c242e5ec58ad6ee7efbd2216aa92098c3eed353ce644f27a7e97b |
|
MD5 | 039610356d81e5be0de64760a895395e |
|
BLAKE2b-256 | 52bef49b3941347b21bb2b1d0847d75e0605247182d88b3819b06e0973d92a88 |
Provenance
The following attestation bundles were made for PyDrive2-1.21.1-py3-none-any.whl
:
Publisher:
publish.yml
on iterative/PyDrive2
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
pydrive2-1.21.1-py3-none-any.whl
- Subject digest:
d24b3334bc5c242e5ec58ad6ee7efbd2216aa92098c3eed353ce644f27a7e97b
- Sigstore transparency entry: 146140145
- Sigstore integration time:
- Predicate type: