Skip to main content

Python gRPC client for the Salesforce PubSub API.

Project description

pysfpubsub

Python gRPC client for the Salesforce Pub/Sub API.

https://developer.salesforce.com/docs/platform/pub-sub-api/overview

Installation

pip install pysfpubsub

Usage

from datetime import datetime
from pysfpubsub import Client

def process_event(event, client):
    """
    This is a callback that gets passed to the `Client.subscribe()` method.
    When no events are received within a certain time period, the API's subscribe
    method sends keepalive messages and the latest replay ID through this callback.
    """
    if event.events:
        print("Number of events received in FetchResponse: ", len(event.events))
        # If all requested events are delivered, release the semaphore
        # so that a new FetchRequest gets sent by `Client.fetch_req_stream()`.
        if event.pending_num_requested == 0:
            client.release_subscription_semaphore()

        for evt in event.events:
            # Get the event payload and schema, then decode the payload
            payload_bytes = evt.event.payload
            json_schema = client.get_schema_json(evt.event.schema_id)
            decoded_event = client.decode(json_schema, payload_bytes)
            print(decoded_event)
    else:
        print(f"[{datetime.now():%Y-%m-%d %H:%M:%S}] The subscription is active.")

config = {
    "url": "https://login.salesforce.com",
    "username": "myusername",
    "password": "mypassword",
    "grpc_host": "api.pubsub.salesforce.com",
    "grpc_port": 7443,
    "api_version": "57.0"
}
sfdc_handler = Client(**config)
sfdc_handler.auth()
sfdc_handler.subscribe("/events/Example_Event__c", "LATEST", "", 1, process_event)

Project details


Download files

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

Source Distribution

pysfpubsub-0.1.2.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

pysfpubsub-0.1.2-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file pysfpubsub-0.1.2.tar.gz.

File metadata

  • Download URL: pysfpubsub-0.1.2.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.2

File hashes

Hashes for pysfpubsub-0.1.2.tar.gz
Algorithm Hash digest
SHA256 d61333bee3d2020b97203dab7aeef49c06a659303a370deb37c8532188f32217
MD5 8a1201168e1dba96633b7f17e57bafc4
BLAKE2b-256 72b90f2e5d595fb6f8adcda23ab945c0b37ed8c726a99b34f936c802178e1e94

See more details on using hashes here.

File details

Details for the file pysfpubsub-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: pysfpubsub-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 11.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.2

File hashes

Hashes for pysfpubsub-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bccf5703d0b0bdb3e50184541b39436aa7cf2480ed7150fe5fdad44781124111
MD5 65a0788c5d11e9cdfe1dbb0375a7a4fd
BLAKE2b-256 2116f6a8c05603b0d1b9e146b666a4a9a1ef883b294fdfa111be1d07548beb7c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page