From 946797bc7540927b1b4ac5aa3aa74aa136fcf086 Mon Sep 17 00:00:00 2001 From: Ivan Shcheklein Date: Thu, 26 Nov 2026 15:37:48 -0800 Subject: [PATCH 1/5] Refresh README badges, installation guidance, and fsspec examples --- README.rst | 222 ++++++++++++++++++++++++++--------------------------- 1 file changed, 108 insertions(+), 114 deletions(-) diff --git a/README.rst b/README.rst index 0cdc5f44..fce4dcbd 100644 --- a/README.rst +++ b/README.rst @@ -1,164 +1,142 @@ -|CI| |Conda| |PyPI| - -.. |CI| image:: - https://github.com/iterative/PyDrive2/workflows/Tests/badge.svg?branch=main - :target: https://github.com/iterative/PyDrive2/actions - :alt: GHA Tests - -.. |Conda| image:: - https://img.shields.io/conda/v/conda-forge/PyDrive2.svg?label=conda&logo=conda-forge - :target: https://anaconda.org/conda-forge/PyDrive2 - :alt: Conda-forge - -.. |PyPI| image:: - https://img.shields.io/pypi/v/PyDrive2.svg?label=pip&logo=PyPI&logoColor=white - :target: https://pypi.org/project/PyDrive2 - :alt: PyPI - PyDrive2 --------- - -*PyDrive2* is a wrapper library of `google-api-python-client`_ that simplifies -many common Google Drive API v3 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 ------------- - -- Package: https://pypi.python.org/pypi/PyDrive2 -- Documentation: https://docs.iterative.ai/PyDrive2 -- Source: https://github.com/iterative/PyDrive2 -- Changelog: https://github.com/iterative/PyDrive2/releases -- `Running tests `_ +|CI| |Conda| |PyPI| -Features of PyDrive2 --------------------- +PyDrive2 is a Python client for the `Google Drive API v3`_ and an +`fsspec`_-compatible filesystem for Google Drive. Use it to upload, download, +and list files, or open them by URL with ``fsspec.open()``. PyDrive2 wraps +`google-api-python-client`_ and is a fork of `PyDrive`_ maintained by the +`DVC`_ team. -- Simplifies OAuth2.0 into just few lines with flexible settings. -- Wraps `Google Drive API v3`_ 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. +Installation +------------ -How to install --------------- +Install the published release from PyPI. Include the optional filesystem +dependencies if you use fsspec. -PyDrive2 requires Python 3.11 or newer. Install it with ``pip``. +.. code:: sh -:: + python -m pip install PyDrive2 + # With fsspec support: + python -m pip install 'PyDrive2[fsspec]' - $ pip install PyDrive2 +The examples below use the development version on ``main``, which requires +Python 3.11 or newer and registers the ``gdrive://`` protocol with fsspec. +To run them, install this branch with its filesystem dependencies. -To install the current development version from GitHub, use: +.. code:: sh -:: + python -m pip install 'PyDrive2[fsspec] @ git+https://github.com/iterative/PyDrive2.git@main' - $ pip install git+https://github.com/iterative/PyDrive2.git#egg=PyDrive2 +If you use PyDrive2 1.x, follow the `1.x examples`_ for Drive API v2. -OAuth made easy ---------------- +Authentication +-------------- -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*. +Enable the Google Drive API in your Google Cloud project and create an +OAuth client for a desktop app. Save the downloaded JSON as +``client_secrets.json`` in your working directory. Run the following code +and sign in when the browser opens. .. code:: python - from pydrive2.auth import GoogleAuth from pydrive2.drive import GoogleDrive gauth = GoogleAuth() gauth.LocalWebserverAuth() - drive = GoogleDrive(gauth) -File management made easy -------------------------- +You can configure authentication in ``settings.yaml``. The +`authentication guide`_ also covers service accounts. -Upload/update the file with one method. PyDrive2 will do it in the most -efficient way. +Create, update, and download files +---------------------------------- -.. code:: python +The first ``Upload()`` creates the file. Call it again on the same object +to save changes to its name or contents. - file1 = drive.CreateFile({'name': 'Hello.txt'}) - file1.SetContentString('Hello') - file1.Upload() # Files.create() +.. code:: python - file1['name'] = 'HelloWorld.txt' # Change name of the file - file1.Upload() # Files.update() + note = drive.CreateFile({"name": "Hello.txt"}) + note.SetContentString("Hello") + note.Upload() - content = file1.GetContentString() # 'Hello' - file1.SetContentString(content+' World!') # 'Hello World!' - file1.Upload() # Files.update() + note["name"] = "HelloWorld.txt" + note.SetContentString(note.GetContentString() + " World!") + note.Upload() - file2 = drive.CreateFile() - file2.SetContentFile('hello.png') - file2.Upload() - print('Created file %s with mimeType %s' % (file2['name'], - file2['mimeType'])) - # Created file hello.png with mimeType image/png +To upload a local file, pass its path to ``SetContentFile()``. Use the Drive +ID to download it again. - file3 = drive.CreateFile({'id': file2['id']}) - print('Downloading file %s from Google Drive' % file3['name']) - # 'hello.png' - file3.GetContentFile('world.png') # Save Drive file as a local file +.. code:: python - # 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') + photo = drive.CreateFile() + photo.SetContentFile("hello.png") + photo.Upload() -File listing pagination made easy ---------------------------------- + download = drive.CreateFile({"id": photo["id"]}) + download.GetContentFile("downloaded.png") -*PyDrive2* handles file listing pagination for you. +To export an existing Google Doc, replace ``DOCUMENT_ID`` with its Drive ID +and specify the export format. .. code:: python - # Auto-iterate through all files that matches this query - file_list = drive.ListFile({'q': "'root' in parents"}).GetList() - for file1 in file_list: - print('name: {}, id: {}'.format(file1['name'], file1['id'])) + document = drive.CreateFile({"id": "DOCUMENT_ID"}) + document.GetContentFile("document.pdf", mimetype="application/pdf") - # Paginate file lists by specifying number of max results - for file_list in drive.ListFile({'pageSize': 10}): - print( - 'Received {} files from Files.list()'.format(len(file_list)) - ) # <= 10 - for file1 in file_list: - print('name: {}, id: {}'.format(file1['name'], file1['id'])) +List files +---------- -Fsspec filesystem ------------------ +To collect all matching entries in My Drive's root folder, call +``GetList()`` without a page size. To process the same results a page at a +time, iterate over ``ListFile()`` directly. -*PyDrive2* provides easy way to work with your files through `fsspec`_ -compatible `GDriveFileSystem`_. +.. code:: python + + query = "'root' in parents and trashed=false" + entries = drive.ListFile({"q": query}).GetList() + for entry in entries: + print(entry["name"], entry["id"]) -Install PyDrive2 with the required dependencies + for page in drive.ListFile({"q": query, "pageSize": 10}): + for entry in page: + print(entry["name"], entry["id"]) -:: +Use Google Drive with fsspec +---------------------------- - $ pip install PyDrive2[fsspec] +Reuse the authenticated ``gauth`` object to read the note created above by +ID. You can also open a named path such as ``gdrive://root/HelloWorld.txt`` +or list a folder through the `GDriveFileSystem`_ interface. .. code:: python - from pydrive2.fs import GDriveFileSystem + import fsspec + + with fsspec.open(f"gdrive://{note['id']}", "rt", google_auth=gauth) as stream: + print(stream.read()) # Hello World! - # 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) + fs = fsspec.filesystem("gdrive", google_auth=gauth) + print(fs.ls("root")) - for root, dnames, fnames in fs.walk("root"): - ... +Concurrent access +----------------- -.. _`GDriveFileSystem`: https://docs.iterative.ai/PyDrive2/fsspec/ +PyDrive2 uses a separate HTTP transport for each thread. When using the Drive +client concurrently, create a separate file object or listing iterator in +each worker. -Concurrent access made easy ---------------------------- +Project links +------------- -All API functions made to be thread-safe. +- `Documentation `_ +- `PyPI `_ +- `Source `_ +- `Releases `_ +- `Running tests `_ Contributors ------------ @@ -167,9 +145,25 @@ Thanks to all our contributors! .. image:: https://contrib.rocks/image?repo=iterative/PyDrive2 :target: https://github.com/iterative/PyDrive2/graphs/contributors + :alt: PyDrive2 contributors + +.. |CI| image:: https://github.com/iterative/PyDrive2/actions/workflows/test.yml/badge.svg?branch=main + :target: https://github.com/iterative/PyDrive2/actions/workflows/test.yml?query=branch%3Amain + :alt: Tests on main + +.. |Conda| image:: https://anaconda.org/conda-forge/pydrive2/badges/version.svg + :target: https://anaconda.org/conda-forge/pydrive2 + :alt: conda-forge version -.. _`fsspec`: https://filesystem-spec.readthedocs.io/en/latest/ +.. |PyPI| image:: https://img.shields.io/pypi/v/pydrive2 + :target: https://pypi.org/project/PyDrive2/ + :alt: PyPI version -.. _google-api-python-client: - https://github.com/google/google-api-python-client .. _Google Drive API v3: https://developers.google.com/workspace/drive/api/guides/about-sdk +.. _fsspec: https://filesystem-spec.readthedocs.io/en/latest/ +.. _google-api-python-client: https://github.com/google/google-api-python-client +.. _PyDrive: https://pypi.org/project/PyDrive/ +.. _DVC: https://dvc.org/ +.. _1.x examples: https://pypi.org/project/PyDrive2/1.21.3/ +.. _authentication guide: https://docs.iterative.ai/PyDrive2/oauth/ +.. _GDriveFileSystem: https://docs.iterative.ai/PyDrive2/fsspec/ From 2634c556a6535f5fd752889879a702fe9d54c20b Mon Sep 17 00:00:00 2001 From: Ivan Shcheklein Date: Thu, 26 Nov 2026 15:39:44 -0800 Subject: [PATCH 2/5] Link directly to package registries to avoid image proxy failures --- README.rst | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/README.rst b/README.rst index fce4dcbd..a7c91a53 100644 --- a/README.rst +++ b/README.rst @@ -1,7 +1,7 @@ PyDrive2 ======== -|CI| |Conda| |PyPI| +|CI| · PyPI_ · conda-forge_ PyDrive2 is a Python client for the `Google Drive API v3`_ and an `fsspec`_-compatible filesystem for Google Drive. Use it to upload, download, @@ -133,7 +133,6 @@ Project links ------------- - `Documentation `_ -- `PyPI `_ - `Source `_ - `Releases `_ - `Running tests `_ @@ -151,14 +150,8 @@ Thanks to all our contributors! :target: https://github.com/iterative/PyDrive2/actions/workflows/test.yml?query=branch%3Amain :alt: Tests on main -.. |Conda| image:: https://anaconda.org/conda-forge/pydrive2/badges/version.svg - :target: https://anaconda.org/conda-forge/pydrive2 - :alt: conda-forge version - -.. |PyPI| image:: https://img.shields.io/pypi/v/pydrive2 - :target: https://pypi.org/project/PyDrive2/ - :alt: PyPI version - +.. _PyPI: https://pypi.org/project/PyDrive2/ +.. _conda-forge: https://anaconda.org/conda-forge/pydrive2 .. _Google Drive API v3: https://developers.google.com/workspace/drive/api/guides/about-sdk .. _fsspec: https://filesystem-spec.readthedocs.io/en/latest/ .. _google-api-python-client: https://github.com/google/google-api-python-client From 8cd64a7d4aee41ea099184f2878db0e9aa012822 Mon Sep 17 00:00:00 2001 From: Ivan Shcheklein Date: Thu, 26 Nov 2026 15:45:08 -0800 Subject: [PATCH 3/5] Restore live package version badges using PNG endpoints --- README.rst | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index a7c91a53..d62eadbb 100644 --- a/README.rst +++ b/README.rst @@ -1,7 +1,7 @@ PyDrive2 ======== -|CI| · PyPI_ · conda-forge_ +|CI| |PyPI| |conda-forge| PyDrive2 is a Python client for the `Google Drive API v3`_ and an `fsspec`_-compatible filesystem for Google Drive. Use it to upload, download, @@ -150,8 +150,14 @@ Thanks to all our contributors! :target: https://github.com/iterative/PyDrive2/actions/workflows/test.yml?query=branch%3Amain :alt: Tests on main -.. _PyPI: https://pypi.org/project/PyDrive2/ -.. _conda-forge: https://anaconda.org/conda-forge/pydrive2 +.. |PyPI| image:: https://raster.shields.io/pypi/v/pydrive2.png + :target: https://pypi.org/project/PyDrive2/ + :alt: PyPI version + +.. |conda-forge| image:: https://raster.shields.io/conda/vn/conda-forge/pydrive2.png + :target: https://anaconda.org/conda-forge/pydrive2 + :alt: conda-forge version + .. _Google Drive API v3: https://developers.google.com/workspace/drive/api/guides/about-sdk .. _fsspec: https://filesystem-spec.readthedocs.io/en/latest/ .. _google-api-python-client: https://github.com/google/google-api-python-client From 40f577e2fabfbed0ea6072845ba7a6d14030100e Mon Sep 17 00:00:00 2001 From: Ivan Shcheklein Date: Thu, 26 Nov 2026 15:46:54 -0800 Subject: [PATCH 4/5] Credit the DataChain team as the PyDrive2 maintainer --- README.rst | 4 ++-- pyproject.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index d62eadbb..13b24a8e 100644 --- a/README.rst +++ b/README.rst @@ -7,7 +7,7 @@ PyDrive2 is a Python client for the `Google Drive API v3`_ and an `fsspec`_-compatible filesystem for Google Drive. Use it to upload, download, and list files, or open them by URL with ``fsspec.open()``. PyDrive2 wraps `google-api-python-client`_ and is a fork of `PyDrive`_ maintained by the -`DVC`_ team. +`DataChain`_ team. Installation ------------ @@ -162,7 +162,7 @@ Thanks to all our contributors! .. _fsspec: https://filesystem-spec.readthedocs.io/en/latest/ .. _google-api-python-client: https://github.com/google/google-api-python-client .. _PyDrive: https://pypi.org/project/PyDrive/ -.. _DVC: https://dvc.org/ +.. _DataChain: https://datachain.ai/ .. _1.x examples: https://pypi.org/project/PyDrive2/1.21.3/ .. _authentication guide: https://docs.iterative.ai/PyDrive2/oauth/ .. _GDriveFileSystem: https://docs.iterative.ai/PyDrive2/fsspec/ diff --git a/pyproject.toml b/pyproject.toml index 046cc47a..469d9deb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,7 +10,7 @@ authors = [ {name = "JunYoung Gwak", email = "jgwak@dreamylab.com"}, ] maintainers = [ - {name = "DVC team", email = "support@dvc.org"}, + {name = "DataChain team", email = "support@datachain.ai"}, ] classifiers = [ "Development Status :: 4 - Beta", From cdd29a9a6705fa04d79e53136f9e405e3bb63c39 Mon Sep 17 00:00:00 2001 From: Ivan Shcheklein Date: Thu, 26 Nov 2026 15:47:51 -0800 Subject: [PATCH 5/5] Document standard installation for PyDrive2 2.0 --- README.rst | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/README.rst b/README.rst index 13b24a8e..14cfa710 100644 --- a/README.rst +++ b/README.rst @@ -12,24 +12,17 @@ and list files, or open them by URL with ``fsspec.open()``. PyDrive2 wraps Installation ------------ -Install the published release from PyPI. Include the optional filesystem -dependencies if you use fsspec. +PyDrive2 2.0 requires Python 3.11 or newer. .. code:: sh python -m pip install PyDrive2 - # With fsspec support: - python -m pip install 'PyDrive2[fsspec]' -The examples below use the development version on ``main``, which requires -Python 3.11 or newer and registers the ``gdrive://`` protocol with fsspec. -To run them, install this branch with its filesystem dependencies. +To open ``gdrive://`` URLs with fsspec, install the filesystem extra. .. code:: sh - python -m pip install 'PyDrive2[fsspec] @ git+https://github.com/iterative/PyDrive2.git@main' - -If you use PyDrive2 1.x, follow the `1.x examples`_ for Drive API v2. + python -m pip install 'PyDrive2[fsspec]' Authentication -------------- @@ -163,6 +156,5 @@ Thanks to all our contributors! .. _google-api-python-client: https://github.com/google/google-api-python-client .. _PyDrive: https://pypi.org/project/PyDrive/ .. _DataChain: https://datachain.ai/ -.. _1.x examples: https://pypi.org/project/PyDrive2/1.21.3/ .. _authentication guide: https://docs.iterative.ai/PyDrive2/oauth/ .. _GDriveFileSystem: https://docs.iterative.ai/PyDrive2/fsspec/