Google Cloud Storage Python client
Google Cloud Storage Python Client
- Apache 2.0 License
- Documentation: https://gcs-client.readthedocs.org.
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
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
To install all you need to do is run:
$ pip install --upgrade gcs-client
To use gcs-client in a project you will need to have Credentials to access intended Google Cloud Storage.
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 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.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:
- Go to project’s issue tracker on GitHub
- Search for existing issues using the search field at the top of the page
- File a new issue with information on the problem
- 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.
- Fix #1 - Media upload not working
- Fix requirements issue
- Add support for delimiter in listings using Prefix object
- Remove dependency from google-api-python-client
- Return descriptive error message on AttributeError
- No changes, version bump to reload in pypi
- 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.
- Fix seek method.
- Fix Pypi package.
- First release on PyPI.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size & hash SHA256 hash help||File type||Python version||Upload date|
|gcs_client-0.2.2-py2.py3-none-any.whl (37.4 kB) Copy SHA256 hash SHA256||Wheel||2.7|
|gcs-client-0.2.2.tar.gz (40.3 kB) Copy SHA256 hash SHA256||Source||None|