Skip to main content

Accessing GoogleDrive as if it is your local drive

Project description

free_storage

Motivation

GoogleDrive provides up to 15GB of free storage (as of the date of writing). The offical Python API (pydrive) is a bit tricky to use when you have a nested directory structure. The goal here is to be able to manipulate files GoogleDrive as if you are on your local drive using os. If you are using GoogleCloud, S3 or other paid storage services, cloud-storage-client will be a better library. As the name suggests, this is only useful if you want to stick to the free stuff :)

Installation

pip install free_storage

To use the library for the first time, you need to follow this tutorial to generate gdrive_credentials.json. Also you need to define an extra gdrive_settings.yaml file.

# gdrive_credentials.json
{"access_token": XXXX, "client_id": XXXX, "client_secret": XXXX, ...}
# gdrive_settings.yaml
client_config_backend: settings
client_config:
  client_id: XXXX
  client_secret: XXXX

save_credentials: True
save_credentials_backend: file
save_credentials_file: gdrive_credentials.json

get_refresh_token: True

oauth_scope:
  - https://www.googleapis.com/auth/drive
  - https://www.googleapis.com/auth/drive.metadata

Below is an example of how the interface is used

from free_storage import GoogleDriveStorage

drive = GoogleDriveStorage(
    setting_file_name="path/to/gdrive_settings.yaml",
    credential_file_name="path/to/gdrive_credentials.json"
)

# Create a folder under root
drive.create_file("directory_name")

# Upload an existing file locally to a remote path
drive.create_file(
    remote_path="directory_name/test.zip",
    local_path="test.zip",
)

# Upload content in memory to a file in remote path
drive.create_file(
    remote_path="directory_name/test.txt",
    content="some string",
)

# Download file
drive.download_file(
    remote_path="directory_name/test.txt",
    local_path="test.txt"
)

# Delete file
drive.delete_file("directory_name/test.txt")

TODO

  • For create_file method under GoogleDriveStorage, allow creating nested levels of directories, instead of just one level down
  • Stream reading large files without downloading the whole file to local

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

free_storage-0.1.0.tar.gz (8.0 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page