|
| 1 | +Cloud Storage in 10 seconds |
| 2 | +=========================== |
| 3 | + |
| 4 | +Install the library |
| 5 | +------------------- |
| 6 | + |
| 7 | +The source code for the library |
| 8 | +(and demo code) |
| 9 | +lives on GitHub, |
| 10 | +You can install the library quickly with ``pip``:: |
| 11 | + |
| 12 | + $ pip install gcloud |
| 13 | + |
| 14 | +Run the |
| 15 | +`example script <https://github.com/jgeewax/gcloud/blob/master/gcloud/storage/demo.py>`_ |
| 16 | +included in the package:: |
| 17 | + |
| 18 | + $ python -m gcloud.storage.demo |
| 19 | + |
| 20 | +And that's it! |
| 21 | +You should be walking through |
| 22 | +a demonstration of using ``gcloud.storage`` |
| 23 | +to read and write data to Google Cloud Storage. |
| 24 | + |
| 25 | +Try it yourself |
| 26 | +--------------- |
| 27 | + |
| 28 | +You can interact with a demo dataset |
| 29 | +in a Python interactive shell. |
| 30 | + |
| 31 | +Start by importing the demo module |
| 32 | +and instantiating the demo connection:: |
| 33 | + |
| 34 | + >>> from gcloud.storage import demo |
| 35 | + >>> connection = demo.get_connection() |
| 36 | + |
| 37 | +Once you have the connection, |
| 38 | +you can create buckets and keys:: |
| 39 | + |
| 40 | + >>> connection.get_all_buckets() |
| 41 | + [<Bucket: ...>, ...] |
| 42 | + >>> bucket = connection.create_bucket('my-new-bucket') |
| 43 | + >>> print bucket |
| 44 | + <Bucket: my-new-bucket> |
| 45 | + >>> key = bucket.new_key('my-test-file.txt') |
| 46 | + >>> print key |
| 47 | + <Key: my-new-bucket, my-test-file.txt> |
| 48 | + >>> key = key.set_contents_from_string('this is test content!') |
| 49 | + >>> print key.get_contents_as_string() |
| 50 | + 'this is test content!' |
| 51 | + >>> print bucket.get_all_keys() |
| 52 | + [<Key: my-new-bucket, my-test-file.txt>] |
| 53 | + >>> bucket.delete() |
| 54 | + |
| 55 | +.. note:: |
| 56 | + The ``get_connection`` method is just a shortcut for:: |
| 57 | + |
| 58 | + >>> from gcloud import storage |
| 59 | + >>> from gcloud.storage import demo |
| 60 | + >>> connection = storage.get_connection( |
| 61 | + >>> demo.PROJECT_NAME, demo.CLIENT_EMAIL, demo.PRIVATE_KEY_PATH) |
| 62 | + |
| 63 | +OK, that's it! |
| 64 | +-------------- |
| 65 | + |
| 66 | +And you can always check out |
| 67 | +the :doc:`storage-api`. |
0 commit comments