From charlesreid1

 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
=Installing and Using=
=Installing=


{{Main|Gcloud}}
{{Main|Gcloud}}
Line 5: Line 5:
==Gcloud==
==Gcloud==


To use PubSub from gcloud, you have to install the Google Cloud SDK (standard developers' kit).
{{Main|Gcloud}}
 
==PubSub Client Library==
 
There is a long list of client libraries for Google Cloud provided here: https://cloud.google.com/apis/docs/cloud-client-libraries


You have two options:
The Python API bundles each component separately, and not everything comes with the client library by default. For example, if you want to use BigQuery, you have to install the BigQuery API components. If you want to use PubSub, you have to install the PubSub API components. Installing one does not necessarily install the other.
* Install using Homebrew
* Install using bundled installer from Google


===Homebrew===
===Python API===


To install the Google Cloud SDK using Homebrew:
The standard Google Cloud SDK does not install any Python bindings. If you want Python bindings, you'll need to install those things using pip:


<pre>
<pre>
$ brew cask install google-cloud-sdk
$ pip3 install --upgrade google-cloud
$ pip3 install --upgrade google-cloud-pubsub
</pre>
</pre>


Now you can run a which gcloud:
Link/reference: https://cloud.google.com/pubsub/docs/reference/libraries#client-libraries-install-python
 
Also see: https://github.com/GoogleCloudPlatform/google-cloud-python
 
Specifically: https://github.com/GoogleCloudPlatform/google-cloud-python/tree/master/pubsub
 
=Using=


<pre>
==Using from gcloud==
$ which gcloud
/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/bin/gcloud
</pre>


===Google Installer===
The prefix beta is required to come before pubsub.


To use the installer provided by Google, visit the following link: https://cloud.google.com/sdk/docs/
Here is how to create a topic:


==PubSub Client Library==
<pre>
$ gcloud beta pubsub topics create sandiego
</pre>


There is a long list of client libraries for Google Cloud provided here: https://cloud.google.com/apis/docs/cloud-client-libraries
Here is how to publish a message (a glob of bytes) to said topic:


The Python API bundles each component separately, and not everything comes with the client library by default. For example, if you want to use BigQuery, you have to install the BigQuery API components. If you want to use PubSub, you have to install the PubSub API components. Installing one does not necessarily install the other.
<pre>
$ gcloud beta pubsub topics publish sandiego "hello world"
</pre>


===Python API===
==Using from Python==


The standard Google Cloud SDK does not install any Python bindings. If you want Python bindings, you'll need to install those things using pip:
Example of creating a topic and publishing a message from Python code:


<pre>
<pre>
$ pip3 install --upgrade google-cloud-pubsub
from google.cloud import pubsub
client = pubsub.Client()
 
topic = client.topic("sandiego")
topic.create()
topic.publish(b'hello world')
</pre>
</pre>


Link/reference: https://cloud.google.com/pubsub/docs/reference/libraries#client-libraries-install-python
=Resources=


Also see: https://github.com/GoogleCloudPlatform/google-cloud-python
=Flags=


Specifically: https://github.com/GoogleCloudPlatform/google-cloud-python/tree/master/pubsub
[[Category:Data Engineering]]
[[Category:Google Cloud]]
[[Category:Python]]

Latest revision as of 01:29, 24 October 2017

Installing

Gcloud

PubSub Client Library

There is a long list of client libraries for Google Cloud provided here: https://cloud.google.com/apis/docs/cloud-client-libraries

The Python API bundles each component separately, and not everything comes with the client library by default. For example, if you want to use BigQuery, you have to install the BigQuery API components. If you want to use PubSub, you have to install the PubSub API components. Installing one does not necessarily install the other.

Python API

The standard Google Cloud SDK does not install any Python bindings. If you want Python bindings, you'll need to install those things using pip:

$ pip3 install --upgrade google-cloud
$ pip3 install --upgrade google-cloud-pubsub

Link/reference: https://cloud.google.com/pubsub/docs/reference/libraries#client-libraries-install-python

Also see: https://github.com/GoogleCloudPlatform/google-cloud-python

Specifically: https://github.com/GoogleCloudPlatform/google-cloud-python/tree/master/pubsub

Using

Using from gcloud

The prefix beta is required to come before pubsub.

Here is how to create a topic:

$ gcloud beta pubsub topics create sandiego

Here is how to publish a message (a glob of bytes) to said topic:

$ gcloud beta pubsub topics publish sandiego "hello world"

Using from Python

Example of creating a topic and publishing a message from Python code:

from google.cloud import pubsub
client = pubsub.Client()

topic = client.topic("sandiego")
topic.create()
topic.publish(b'hello world')

Resources

Flags