Skip to main content

Google Cloud Storage Python client

Project description

GCS-Client

https://img.shields.io/travis/Akrog/gcs-client.svg https://img.shields.io/pypi/v/gcs-client.svg https://img.shields.io/coveralls/Akrog/gcs-client/master.svg Documentation Status https://img.shields.io/pypi/pyversions/gcs-client.svg https://img.shields.io/:license-apache-blue.svg

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

Installation

To install all you need to do is run:

$ pip install --upgrade gcs-client

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 not objects:
    print 'There are no objects, creating one'
    filename = '/tmp/my_file.txt'
    with bucket.open(filename, 'w') as f:
        f.write('this is a test file\n' * 100)
    objects = [gcs_client.Object(bucket.name, filename, credentials=credentials)]

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.

Reporting an issue

If you’ve found an issue with gcs-client here’s how you can report the problem:

  • Preferred method is filing a bug on GitHub:

    1. Go to project’s issue tracker on GitHub

    2. Search for existing issues using the search field at the top of the page

    3. File a new issue with information on the problem

    4. Thanks for helping make gcs-client better

  • If you don’t have a GitHub account and don’t wish to create one you can just drop me an email.

History

0.2.1 (2016-03-26)

  • Fix requirements issue

0.2.0 (2015-11-25)

  • Add support for delimiter in listings using Prefix object

  • Remove dependency from google-api-python-client

  • Return descriptive error message on AttributeError

0.1.4 (2015-11-16)

  • No changes, version bump to reload in pypi

0.1.3 (2015-11-16)

  • Reading an object will return data as bytes, not a bytearray.

  • Read specific versions of an object.

  • Can specify chunksize on Bucket’s open and Object init.

  • Add exists to buckets and project.

  • Fix opening files with names that needed encoding.

0.1.2 (2015-11-10)

  • Fix seek method.

0.1.1 (2015-11-09)

  • Fix Pypi package.

0.1.0 (2015-11-09)

  • 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.2.1.tar.gz (35.4 kB view details)

Uploaded Source

Built Distribution

gcs_client-0.2.1-py2.py3-none-any.whl (31.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file gcs-client-0.2.1.tar.gz.

File metadata

  • Download URL: gcs-client-0.2.1.tar.gz
  • Upload date:
  • Size: 35.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for gcs-client-0.2.1.tar.gz
Algorithm Hash digest
SHA256 8afc91befd18b7e6c2c74467b06861b59f805467efc37bd1569f1d5e8adc1649
MD5 f9682f3b35401a275e817bc59b4e6113
BLAKE2b-256 b98f84f5cb0bed50bfb5036f567ce1b6325724b3397d88518b1ae80cceef82c3

See more details on using hashes here.

Provenance

File details

Details for the file gcs_client-0.2.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for gcs_client-0.2.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 4ae8b8f3a4453e4509ad52cdc89d04267ddbdbdd5c09913c54ac9840fea96775
MD5 dc26a17b8e0e2a5d37c183353b0e5fb5
BLAKE2b-256 1037b3c6f291df52bab87912329a3273beb0d8d9bf4215805a4cea112faa06c3

See more details on using hashes here.

Provenance

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