Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Python Client for Google Cloud Pub/Sub

Project Description
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.

Release History

Release History

This version
History Node

0.28.4

History Node

0.28.3

History Node

0.28.2

History Node

0.28.1

History Node

0.28.0

History Node

0.27.0

History Node

0.26.0

History Node

0.25.0

History Node

0.24.0

History Node

0.23.0

History Node

0.22.0

History Node

0.21.0

History Node

0.20.0

History Node

0.0.1

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
google_cloud_pubsub-0.28.4-py2.py3-none-any.whl (79.4 kB) Copy SHA256 Checksum SHA256 py2.py3 Wheel Oct 13, 2017
google-cloud-pubsub-0.28.4.tar.gz (71.0 kB) Copy SHA256 Checksum SHA256 Source Oct 13, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting