Pub/Sub Client#

Client for interacting with the Google Cloud Pub/Sub API.

class google.cloud.pubsub.client.Client(project=None, credentials=None, http=None, use_gax=None)[source]#

Bases: google.cloud.client.ClientWithProject

Client to bundle configuration needed for API requests.

Parameters:
  • project (str) – the project which the client acts on behalf of. Will be passed when creating a topic. If not passed, falls back to the default inferred from the environment.
  • credentials (Credentials) – (Optional) The OAuth2 Credentials to use for this client. If not passed (and if no http object is passed), falls back to the default inferred from the environment.
  • http (Http) – (Optional) HTTP object to make requests. Can be any object that defines request() with the same interface as request(). If not passed, an http object is created that is bound to the credentials for the current object.
  • use_gax (bool) – (Optional) Explicitly specifies whether to use the gRPC transport (via GAX) or HTTP. If unset, falls back to the GOOGLE_CLOUD_DISABLE_GRPC environment variable
SCOPE = ('https://www.googleapis.com/auth/pubsub', 'https://www.googleapis.com/auth/cloud-platform')#

The scopes required for authenticating as a Cloud Pub/Sub consumer.

iam_policy_api#

Helper for IAM policy-related API calls.

list_subscriptions(page_size=None, page_token=None)[source]#

List subscriptions for the project associated with this client.

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

Example:

    for subscription in client.list_subscriptions():  # API request(s)
        do_something_with(subscription)
Parameters:
  • page_size (int) – maximum number of topics to return, If not passed, defaults to a value set by the API.
  • page_token (str) – opaque marker for the next “page” of topics. If not passed, the API will return the first page of topics.
Return type:

Iterator

Returns:

Iterator of Subscription accessible to the current client.

list_topics(page_size=None, page_token=None)[source]#

List topics for the project associated with this client.

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

Example:

    for topic in client.list_topics():   # API request(s)
        do_something_with(topic)
Parameters:
  • page_size (int) – maximum number of topics to return, If not passed, defaults to a value set by the API.
  • page_token (str) – opaque marker for the next “page” of topics. If not passed, the API will return the first page of topics.
Return type:

Iterator

Returns:

Iterator of Topic accessible to the current API.

publisher_api#

Helper for publisher-related API calls.

subscriber_api#

Helper for subscriber-related API calls.

topic(name, timestamp_messages=False)[source]#

Creates a topic bound to the current client.

Example:


Parameters:
  • name (str) – the name of the topic to be constructed.
  • timestamp_messages (bool) – To be passed to Topic constructor.
Return type:

google.cloud.pubsub.topic.Topic

Returns:

Topic created with the current client.