Python

Report an Issue

Pub/Sub#

gcloud.pubsub#

GCloud Pubsub API wrapper.

The main concepts with this API are:

gcloud.pubsub.__init__.get_connection()[source]#

Shortcut method to establish a connection to Cloud Storage.

Use this if you are going to access several buckets with the same set of credentials:

>>> from gcloud import pubsub
>>> connection = pubsub.get_connection()
>>> bucket1 = pubsub.get_bucket('bucket1', connection=connection)
>>> bucket2 = pubsub.get_bucket('bucket2', connection=connection)
Return type:gcloud.pubsub.connection.Connection
Returns:A connection defined with the proper credentials.
gcloud.pubsub.__init__.set_default_connection(connection=None)[source]#

Set default connection either explicitly or implicitly as fall-back.

Parameters:connection (gcloud.pubsub.connection.Connection) – A connection provided to be the default.
gcloud.pubsub.__init__.set_defaults(project=None, connection=None)[source]#

Set defaults either explicitly or implicitly as fall-back.

Uses the arguments to call the individual default methods.

Parameters:
  • project (string) – Optional. The name of the project to connect to.
  • connection (gcloud.pubsub.connection.Connection) – Optional. A connection provided to be the default.

Connections#

Create / interact with gcloud pubsub connections.

class gcloud.pubsub.connection.Connection(credentials=None, http=None)[source]#

Bases: gcloud.connection.JSONConnection

A connection to Google Cloud Pubsub via the JSON REST API.

API_BASE_URL = 'https://pubsub.googleapis.com'#

The base of the API call URL.

API_URL_TEMPLATE = '{api_base_url}/{api_version}{path}'#

A template for the URL of a particular API call.

API_VERSION = 'v1beta2'#

The version of the API, used in building the API call’s URL.

Interacting with the API#

Define API functions (not bound to classes).

gcloud.pubsub.api.list_subscriptions(page_size=None, page_token=None, topic_name=None, project=None, connection=None)[source]#

List subscriptions for a given project.

See: https://cloud.google.com/pubsub/reference/rest/v1beta2/projects/topics/list

and (where topic_name is passed): https://cloud.google.com/pubsub/reference/rest/v1beta2/projects/topics/subscriptions/list

Parameters:
  • page_size (int) – maximum number of topics to return, If not passed, defaults to a value set by the API.
  • page_token (string) – opaque marker for the next “page” of topics. If not passed, the API will return the first page of topics.
  • topic_name (string) – limit results to subscriptions bound to the given topic.
  • project (string) – project ID to query. If not passed, defaults to the project ID inferred from the environment.
  • connection (gcloud.pubsub.connection.Connection) – connection to use for the query. If not passed, defaults to the connection inferred from the environment.
Return type:

tuple, (list, str)

Returns:

list of gcloud.pubsub.subscription.Subscription, plus a “next page token” string: if not None, indicates that more topics can be retrieved with another call (pass that value as page_token).

gcloud.pubsub.api.list_topics(page_size=None, page_token=None, project=None, connection=None)[source]#

List topics for a given project.

See: https://cloud.google.com/pubsub/reference/rest/v1beta2/projects/topics/list

Parameters:
  • page_size (int) – maximum number of topics to return, If not passed, defaults to a value set by the API.
  • page_token (string) – opaque marker for the next “page” of topics. If not passed, the API will return the first page of topics.
  • project (string) – project ID to query. If not passed, defaults to the project ID inferred from the environment.
  • connection (gcloud.pubsub.connection.Connection) – connection to use for the query. If not passed, defaults to the connection inferred from the environment.
Return type:

tuple, (list, str)

Returns:

list of gcloud.pubsub.topic.Topic, plus a “next page token” string: if not None, indicates that more topics can be retrieved with another call (pass that value as page_token).