Skip to content

PubSub

paystone.pubsub is a simple wrapper around google.cloud.pubsub, with one core piece of added functionality: all topics have schema, and the schema of topics is represented via Pydantic data models.

In this package, we've replaced the usage of Pydantic with pydantic-avro, which gives interoperability between Pydantic models and the Avro format. This is because Pubsub expects its schema to be represented as Avro data. We write our data models in pure Pydantic, and they are translated to Avro data models for consumption by google.cloud.pubsub.

The package provides an interface to the following functions:

  1. Creating topics.
  2. Creating push and pull subscriptions.
  3. Synchronously pulling data.
  4. Asynchronously pulling data.

We won't maintain our own documentation on the discussion of when to use push vs pull subscriptions. See the GCP docs for this.

Similarly, we defer to public documentation on sync vs async pulling.

Creating a Topic

When creating a new topic, there are essentially two steps:

  1. Create a Pydantic data model in paystone.pubsub.schemata representing the schema of the topic.
  2. Create a topic in paystone.pubsub.topics with the name of the topic and its data model.

With these things created, a PR can be raised. No continuous integration mechanism currently exists for automatically creating this topic once its code is written, but it may in the future.