Skip to main content

Google Drive fsspec implementation

This is an implementation of the fsspec interface for Google Drive.

This software is in beta stage and should not be relied upon in production settings.

Installation

You can install it with pip from pypi or directly from source:

pip install gdrive_fsspec
pip install git+https://github.com/fsspec/gdrive-fsspec

Usage

As gdrivefs implements the fsspec interface, most documentation can be found at https://filesystem-spec.readthedocs.io/en/latest/usage.html.

Authentication

There are several methods to authenticate gdrivefs against Google Drive.

1. Service account credentials

In this method, you provide a dict containing the service account credentials obtained in the GCP console. The dict content is the same as the JSON file downloaded from the GCP console. More details can be found here: https://cloud.google.com/iam/docs/service-account-creds#key-types. This credential can be useful when integrating with other GCP services, and when you don't want the user to be prompted to authenticate.

from gdrive_fsspec import GoogleDriveFileSystem
fs = GoogleDriveFileSystem(creds=service_account_credentials,
                           token="service_account")

2. OAuth with user credentials

A browser will be opened to complete the OAuth authentication flow. Afterwards, the access token will be stored locally, and you can reuse it in subsequent sessions.

# use this the first time you run
token = 'browser'
# use this on subsequent attempts
# token = 'cache'
fs = GoogleDriveFileSystem(token=token)

On headless or remote machines (SSH sessions, containers, CI, and similar environments), you may not be able to bind a local callback server or open a browser on the same host. In that case, pass use_local_webserver: False in auth_kwargs to request a token via the console.

fs = GoogleDriveFileSystem(
    token=token,
    auth_kwargs={'use_local_webserver': False},
)

3. Anonymous (read-only) access

If you want to interact with files that are shared publicly ("anyone with the link"), then you do not need to authenticate to Google Drive.

token = 'anon'
fs = GoogleDriveFileSystem(token=token)

See GoogleDriveFileSystem docstring for more details.

Development

Running tests

The tests require defining the following environment variables:

  • gdrive_fsspec_CREDENTIALS_PATH: location of a credentials.json or the json blob itself (starting with "{")
  • gdrive_fsspec_CREDENTIALS_TYPE: token type ("service_account" default)
  • gdrive_fsspec_DRIVE: shared drive to use.

As can be seen, the assumption is, that a service account will be operating on a shared drive. This requires the account to be have full shared access to the drive.

You could use your own personal gdrive too, either by creating a credentials JSON, or by using type "cache" following successful browser-based auth.

All tests take place in a directory "gdrive_fsspec_testdir".

pip install -e . pytest
pytest -v

Style

Please run pre-commit before submitting PRs. You can automate this by calling

$ pre-commit install

in the repo (once) before committing.

Other implementations

  • PyDrive2 also provides an fsspec-compatible Google Drive API.

Metadata

Release files for gdrive-fsspec 0.4.1

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

Source distribution (sdist)

Source distribution for gdrive-fsspec 0.4.1
File Size Uploaded
gdrive_fsspec-0.4.1.tar.gz 14.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gdrive-fsspec 0.4.1
File Interpreter ABI Platform
gdrive_fsspec-0.4.1-py3-none-any.whl Python 3 none any Details

Total release size: 26.2 kB

Release files / gdrive_fsspec-0.4.1.tar.gz

Download URL gdrive_fsspec-0.4.1.tar.gz
Size 14.3 kB
Tags Source
SHA-256 checksum
How to use checksums
78e1ffdbe3e51c35dbc11a9f073681f74c68908b3ba41c166b019e963148ce94
BLAKE2b-256 checksum
How to use checksums
315d4df87f94f8da6249233dffad2ff6f3e5288539cbf223de98e097aeeacb03
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.11

Release files / gdrive_fsspec-0.4.1-py3-none-any.whl

Download URL gdrive_fsspec-0.4.1-py3-none-any.whl
Size 11.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
506960fc71422e08afd8e9a926dc9960fc6f306b24d1c21b4b4b2bb51a5cfec3
BLAKE2b-256 checksum
How to use checksums
222369fdc00e2faeaa8baec3f6011eb8641a88c8db29b37c1c56d0a740a8c7eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.11

Release history Release notifications | RSS feed

This release

0.4.1 This release

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.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