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)[source]# Bases:
google.cloud.client.JSONClient
Client to bundle configuration needed for API requests.
Parameters: - project (string) – 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 (
oauth2client.client.OAuth2Credentials
orNoneType
) – The OAuth2 Credentials to use for the connection owned by this client. If not passed (and if nohttp
object is passed), falls back to the default inferred from the environment. - http (
httplib2.Http
or class that definesrequest()
.) – An optional HTTP object to make requests. If not passed, anhttp
object is created that is bound to thecredentials
for the current object.
-
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:
subscriptions, token = client.list_subscriptions() # API request while True: for subscription in subscriptions: do_something_with(subscription) if token is None: break subscriptions, token = client.list_subscriptions( page_token=token) # API request
Parameters: Return type: tuple, (list, str)
Returns: list of
Subscription
, plus a “next page token” string: if not None, indicates that more topics can be retrieved with another call (pass that value aspage_token
).
-
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:
topics, token = client.list_topics() # API request while True: for topic in topics: do_something_with(topic) if token is None: break topics, token = client.list_topics(page_token=token) # API request
Parameters: Return type: tuple, (list, str)
Returns: list of
google.cloud.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 aspage_token
).
-
publisher_api
# Helper for publisher-related API calls.
-
subscriber_api
# Helper for subscriber-related API calls.
Connection#
Create / interact with Google Cloud Pub/Sub connections.
-
class
google.cloud.pubsub.connection.
Connection
(credentials=None, http=None)[source]# Bases:
google.cloud.connection.JSONConnection
A connection to Google Cloud Pub/Sub via the JSON REST API.
Parameters: - credentials (
oauth2client.client.OAuth2Credentials
) – (Optional) The OAuth2 Credentials to use for this connection. - http (
httplib2.Http
or class that definesrequest()
.) – (Optional) HTTP object to make requests.
-
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
= 'v1'# The version of the API, used in building the API call’s URL.
-
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.
-
build_api_url
(path, query_params=None, api_base_url=None, api_version=None)[source]# Construct an API url given a few components, some optional.
Typically, you shouldn’t need to use this method.
Parameters: - path (string) – The path to the resource.
- query_params (dict or list) – A dictionary of keys and values (or list of key-value pairs) to insert into the query string of the URL.
- api_base_url (string) – The base URL for the API endpoint. Typically you won’t have to provide this.
- api_version (string) – The version of the API to call. Typically you shouldn’t provide this and instead use the default for the library.
Return type: Returns: The URL assembled from the pieces provided.
- credentials (
-
google.cloud.pubsub.connection.
PUBSUB_API_HOST
= 'pubsub.googleapis.com'# Pub / Sub API request host.