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 details)

Uploaded Source

File details

Details for the file free_storage-0.1.0.tar.gz.

File metadata

  • Download URL: free_storage-0.1.0.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.4

File hashes

Hashes for free_storage-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9c1d5489d6c3d813f2a23daa07feed98ff473857ece6365a89e2ae15e76a1872
MD5 46d34fc752a40da7ecd69920bd403b86
BLAKE2b-256 220896cf1bf65809b2f4caaa0dafe0422fefd8bb648daa9997773d3f968f7e56

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