Skip to content

Latest commit

History

8 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Google Cloud Storage API v1

A lightweight Python package to simplify Google Cloud Storage operations.

Installation

pip install git+https://github.com/DataSolveProblems/gcstorage.git

Basic Usage

  1. Create a Google Cloud Service Account

  2. Enable Google Cloud Storage API

  3. Start using gcstorage

Examples

1. List buckets

importosfromgoogle.cloudimportstoragefromgcstorageimportGCStorage, STORAGE_CLASSESos.environ["GOOGLE_APPLICATION_CREDENTIALS"] ="service_acct.json"client=storage.Client()
gcs=GCStorage(client)
gcs.list_buckets()

2. Create a bucket

my_bucket=gcs.create_bucket('<my bucket name>', storage_class=STORAGE_CLASSES[2], location='us')

3. Return bucket metadata

my_bucket=gcs.get_bucket('my_bucket_y22')
bucket_metadata=gcs.get_bucket_metadata(my_bucket)

4. Add bucket labels

my_bucket=gcs.get_bucket('my_bucket_y22')
gcs.add_bucket_labels(my_bucket, {'bucket_type': 'general', 'department': 'it'})

5. Delete bucket labels

my_bucket=gcs.get_bucket('my_bucket_y22')
gcs.delete_bucket_labels(my_bucket)

6. List blobs in a bucket

blobs=gcs.list_blobs(my_bucket.id)
forblobinblobs:
print(blob.name)

7. Return a blob's metadata

my_blob=my_bucket.get_blob(blob.name)
gcs.get_blob_metadata(my_blob)

8. Upload a file

gcs.upload_file(my_bucket, 'object_destination', file_path)

9. Download a file

gcs.download_file_by_blob(my_blob, '<file destination>')

10. Download files by a bucket

gcs.download_files_by_bucket(my_bucket, '<file destination>')

11. Download file by byte range

gcs.download_file_by_blob_by_byte_range(my_bucket, my_blob, '<file destination>', start_byte, end_byte)

About

A lightweight Python package to manage your Google Cloud Storage operations

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages