Skip to main content

File system on GDrive

Project description

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/gdrivefs

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)
  1. 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)
  1. 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

Unit tests

pip install -e . pytest
pytest -v

Integration tests

To run integration tests, you need to have user credentials cached locally that can be used to interact with your real Google Drive account. You can do this by running the following:

import gdrive_fsspec
fs = gdrive_fsspec.GoogleDriveFileSystem(token='browser')

Alternatively, you can save user credentials in a file and set the environment variable GDRIVEFS_USER_CREDENTIALS_PATH to the path of the file.

Then you can run the integration tests:

pytest -v -m integration

Other implementations

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

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

gdrive_fsspec-0.2.0.tar.gz (12.9 kB view details)

Uploaded Source

Built Distribution

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

gdrive_fsspec-0.2.0-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file gdrive_fsspec-0.2.0.tar.gz.

File metadata

  • Download URL: gdrive_fsspec-0.2.0.tar.gz
  • Upload date:
  • Size: 12.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for gdrive_fsspec-0.2.0.tar.gz
Algorithm Hash digest
SHA256 16ebc8af6162dd05939bc8e01c6c760e1210f1332bafd3399e6bdfb90541565c
MD5 0cfa2032f0e3c31879b14483e94189a7
BLAKE2b-256 cab1561cbe537b5a06d144e497772cd935e2306c01a312eed832b83d786c8d10

See more details on using hashes here.

File details

Details for the file gdrive_fsspec-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: gdrive_fsspec-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 10.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for gdrive_fsspec-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 85433942363dc7a4db06ce01c9ceaf44e5ff6b1eedabf0231f9cb1c05923e0e3
MD5 d574bf51c86ff59b34f6bab880484779
BLAKE2b-256 1d15fc9db292ffdd8795eceadc1a07dae79b4ba3e72ee74c77292b5ab357f734

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