Skip to main content

An async Python gRPC client for the Salesforce PubSub API.

Project description

aiosfpubsub

An async Python gRPC client for the Salesforce Pub/Sub API.

https://github.com/forcedotcom/pub-sub-api/blob/main/pubsub_api.proto

install

pip install aiosfpubsub

usage

import asyncio
from aiosfpubsub import Client
from datetime import datetime 


def callback(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))

        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.")

async def main():
    client = Client(**{
        "url": "https://login.salesforce.com",
        "username": "myuser",
        "password": "mypass",
        "grpc_host": "api.pubsub.salesforce.com",
        "grpc_port": 7443,
        "api_version": "57.0"
    })
    client.auth()
    await client.subscribe(
        topic="/event/My_Event__e",
        replay_type="EARLIEST",
        replay_id=None,
        num_requested=10,
        callback=callback
    )
if __name__ == "__main__":
    asyncio.run(main())

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

aiosfpubsub-0.0.5.tar.gz (12.5 kB view hashes)

Uploaded Source

Built Distribution

aiosfpubsub-0.0.5-py3-none-any.whl (11.3 kB view hashes)

Uploaded Python 3

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