What is the difference between google.cloud.pubsub_v1 and google.cloud.pubsub?
Asked Answered
C

1

18

I see both used in different documentation from Google:

from google.cloud import pubsub

Is found in:

Whereas

from google.cloud import pubsub_v1

Is find in:

Colewort answered 10/1, 2018 at 22:51 Comment(1)
The link is no longer valid.https://github.com/GoogleCloudPlatform/google-cloud-python/tree/master/pubsub. And also i don't see usage of approach #1 of from google.cloud import pubsub any where.Wherewithal
H
14

The google.cloud.pubsub library is designed to be make it easy to get the best performance out of a Cloud Pub/Sub publisher and subscriber. It has more advanced features such as message batching, asynchronous message delivery, and automatic ack deadline extension for messages not yet acknowledged by a subscriber. The API is different from the underlying Cloud Pub/Sub service API. For example, this library does not expose the pull method directly; messages are instead delivered to a callback passed into the subscriber's open method.

The google.cloud.pubsub_v1 library exposes the underlying API directly. It can be useful in specific cases where this level of control is necessary, e.g., when a synchronous subscriber is required in order to make requests in response to synchronous actions from a downstream dependency.

When possible, it is best to use the google.cloud.pubsub library.

Heave answered 16/1, 2018 at 17:25 Comment(7)
Hi, Just to confirm, is this still valid? I did pip install google-cloud-pubsub just now and in virtualenv all it seems to create folders /site-packages/google/cloud/pubsub_v1/* ... doing pip install google-cloud-pubsub_v1 returns: > Could not find a version that satisfies the requirement google-cloud-pubsub_v1 ...Ungula
also, it seems the Client Library (pubsub_v1) no longer suppose REST API, it only supports gRPC based API any longer... Thanks!Ungula
@VibhorJain The package to install is google-cloud-pubsub which uses the name spaces google and google.cloud and installs to those pubsub_v1 directories as you found. The name of the directory is not important. Google are moving all the client libraries to gRPC, as mentioned cloud.google.com/apis/docs/client-libraries-explained "We plan to upgrade as many Cloud Client Libraries as possible to gRPC" and why not? protocol buffers over http/2 is faster. Ideally, don't write your own REST client code, let the client library handle low level details.Lala
Looks like there is no difference pubsub appears to be just importing from pubsub_v1 see github.com/googleapis/google-cloud-python/blob/master/pubsub/… AND github.com/googleapis/google-cloud-python/blob/master/pubsub/… i.e. the pubsub SubcriberClient() class IS pubsub_v1.subscriber.client The pull method was blacklisted in the pubsub_v1 client and consequently in pubsub client. That method was also re-exposed github.com/googleapis/google-cloud-python/commit/…Lala
I think this answer is still correct though, because there are some things not exposed, like futures, and it does have some tricky decorators, blacklisting and add method mechanisms to control the interface. It also makes heavy use of __all__ to control exactly what is imported.Lala
@Lala I had posted a question earlier here https://stackoverflow.com/questions/52659169/is-google-cloud-pubsub-v1-publisherclient-thread-safe does it impact the choice between pubsusb vs pubs_v1 ?Vine
@Fadi no I think that question's answer is clear. This page explains the difference between the older google api client libraries vs the newer google cloud client libraries. The names are similar and it is confusing tbh. cloud.google.com/apis/docs/client-libraries-explainedLala

© 2022 - 2024 — McMap. All rights reserved.