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/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")
  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

The tests require defining the following environment variables:

  • gdrive_fsspec_CREDENTIALS_PATH: location of a credentials.json
  • 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.

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.3.0.tar.gz (13.6 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.3.0-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for gdrive_fsspec-0.3.0.tar.gz
Algorithm Hash digest
SHA256 db295c656d94480782dc86a4fdf45d5ae79b6826007813c0ae87863f4d9d6f7b
MD5 7e5d34a803121242a11719bd012758dc
BLAKE2b-256 4d08672784a16e7f5a927245c556ece48cd3577890975a4ef9c3c32f6404562f

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for gdrive_fsspec-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 da8d8eaf92b6ded12a386e6c7281549d8bfe34d63fe54750aa32d18311100d9e
MD5 f0e12d82f90f4c9438864a848137af86
BLAKE2b-256 04ccb93d13f66a934f78fd51def1627f1a66ed0ebf9ce1656409708dc06646d5

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