Skip to main content

Google Cloud Storage Python client

Project description

https://img.shields.io/travis/Akrog/gcs-client.svg https://img.shields.io/pypi/v/gcs-client.svg https://coveralls.io/repos/Akrog/gcs-client/badge.svg Documentation Status

Google Cloud Storage Python Client

The idea is to create a client with similar functionality to Google’s appengine-gcs-client but intended for applications running from outside Google’s AppEngine.

Cloud Storage documentation can be found at Google

Features

For now only basic functionality is available:

  • Creating buckets

  • Deleting buckets

  • Listing buckets in a project

  • Getting default bucket for a project

  • Getting bucket attributes

  • Listing objects in a bucket

  • Getting objects attributes

  • Deleting objects

  • Reading object contents

  • Writing an object

  • Configurable retries with Truncated Exponential Backoff

Usage Example

To use gcs-client in a project you will need to have Credentials to access intended Google Cloud Storage.

Credentials are generated in Google Developers Console in the Credentials section of the API Manager of the project. Recommended credentials file is JSON.

Once you have the credentials you can start using gcs_client to access your project:

import gcs_client

credentials = gcs_client.Credentials('private_key.json')
project = gcs_client.Project('project_name', credentials)

# Print buckets in the project
buckets = project.list()
print 'Buckets:\n\t- ','\n\t- '.join(map(str, buckets))

# Print some information from first bucket
bucket = buckets[0]
print 'Bucket %s is located in %s with storage class %s' % (bucket, bucket.location, bucket.storageClass)

# List the objects in the bucket
objects = bucket.list()
if objects:
    print '\t','\n\t'.join(map(lambda o: o.name + ' has %s bytes' % o.size, objects))
    # Read the contents from the first file
    with objects[0].open() as obj:
        print 'Contents of file %s are:\n' % obj.name, obj.read()
else:
    print 'There are no objects, nothing to do'

More examples can be found in the documentation, in the Usage section.

History

0.0.1 (2015-10-10)

  • First release on PyPI.

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

gcs-client-0.1.1.tar.gz (25.0 kB view hashes)

Uploaded Source

Built Distribution

gcs_client-0.1.1-py2.py3-none-any.whl (20.5 kB view hashes)

Uploaded Python 2 Python 3

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