Python Client for Google Cloud Pub / Sub
Python idiomatic client for Google Cloud Pub / Sub
Quick Start
$ pip install --upgrade google-cloud-pubsub
Authentication
With google-cloud-python we try to make authentication as painless as possible. Check out the Authentication section in our documentation to learn more. You may also find the authentication document shared by all the google-cloud-* libraries to be helpful.
Using the API
Google Cloud Pub/Sub (Pub/Sub API docs) is designed to provide reliable, many-to-many, asynchronous messaging between applications. Publisher applications can send messages to a topic and other applications can subscribe to that topic to receive the messages. By decoupling senders and receivers, Google Cloud Pub/Sub allows developers to communicate between independently written applications.
See the google-cloud-python API Pub/Sub documentation to learn how to connect to Cloud Pub/Sub using this Client Library.
Publishing
To publish data to Cloud Pub/Sub you must create a topic, and then publish messages to it
import os
from google.cloud import pubsub
publisher = pubsub.PublisherClient()
topic = 'projects/{project_id}/topics/{topic}'.format(
project_id=os.getenv('GOOGLE_CLOUD_PROJECT'),
topic='MY_TOPIC_NAME', # Set this to something appropriate.
)
publisher.create_topic()
publisher.publish(topic, b'My first message!', spam='eggs')
To learn more, consult the publishing documentation.
Subscribing
To subscribe to data in Cloud Pub/Sub, you create a subscription based on the topic, and subscribe to that.
import os
from google.cloud import pubsub
subscriber = pubsub.SubscriberClient()
topic = 'projects/{project_id}/topics/{topic}'.format(
project_id=os.getenv('GOOGLE_CLOUD_PROJECT'),
topic='MY_TOPIC_NAME', # Set this to something appropriate.
)
subscription_name = 'projects/{project_id}/subscriptions/{sub}'.format(
project_id=os.getenv('GOOGLE_CLOUD_PROJECT'),
sub='MY_SUBSCRIPTION_NAME', # Set this to something appropriate.
)
subscription = subscriber.create_subscription(topic, subscription)
The subscription is opened asychronously, and messages are processed by use of a callback.
def callback(message):
print(message.data)
message.ack()
subscription.open(callback)
To learn more, consult the subscriber documentation.
Metadata
Release files for google-cloud-pubsub 0.28.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| google-cloud-pubsub-0.28.3.tar.gz | 70.0 kB | Without provenance | Details for google-cloud-pubsub-0.28.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| google_cloud_pubsub-0.28.3-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for google_cloud_pubsub-0.28.3-py2.py3-none-any.whl |
Total release size: 149.4 kB
Release files / google-cloud-pubsub-0.28.3.tar.gz
| Download URL | google-cloud-pubsub-0.28.3.tar.gz |
|---|---|
| Size | 70.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0dd33a336ef9874ef09d24d529cc24a7c3202d4a589de2e5a1a3d0758579e49f
|
|
BLAKE2b-256 checksum How to use checksums |
2bc00f38a15214929923eaa776a54af5636b3f6ac6c187f2e0f8e754322bb41c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / google_cloud_pubsub-0.28.3-py2.py3-none-any.whl
| Download URL | google_cloud_pubsub-0.28.3-py2.py3-none-any.whl |
|---|---|
| Size | 79.4 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
39da4da5c8b0abed00fa12f15985a0b3bd61d5833bc4b8b17fe11808f8fc7942
|
|
BLAKE2b-256 checksum How to use checksums |
4bb0982035062c00f369820f55966e9e96e58e3c437f858aa2aef9953d6130be
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for google-cloud-pubsub 0.28.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.