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():
    await Client(**{
        "url": "https://login.salesforce.com",
        "username": "myuser",
        "password": "mypass",
        "grpc_host": "api.pubsub.salesforce.com",
        "grpc_port": 7443,
        "api_version": "57.0"
    }).subscribe(
        topic="/event/My_Event__e",
        replay_type="EARLIEST",
        replay_id=None,
        num_requested=10,
        callback=callback
    )

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.3.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

aiosfpubsub-0.0.3-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file aiosfpubsub-0.0.3.tar.gz.

File metadata

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

File hashes

Hashes for aiosfpubsub-0.0.3.tar.gz
Algorithm Hash digest
SHA256 3ab0e4b34104149595dc5921e8cf825811dda31a29628d5ce423c40e5972da01
MD5 34f339f1561690312a22b4f4d869abc5
BLAKE2b-256 54840a1679b2933b2dad15ff95f9cc39062bc6ffb199dcafc3e718cabe17e8db

See more details on using hashes here.

Provenance

File details

Details for the file aiosfpubsub-0.0.3-py3-none-any.whl.

File metadata

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

File hashes

Hashes for aiosfpubsub-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5e814f918c16344cdc311acff81f7cfdc785e2106db9340e4984d6133198cf40
MD5 8f6c87e3002c95b35ac82276247df0ae
BLAKE2b-256 8e3b63a7ef63d2e1ab34c4e00dab7d2812181e9405a6a2eeab2dd70e679ebeab

See more details on using hashes here.

Provenance

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