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

Uploaded Source

Built Distribution

aiosfpubsub-0.0.6-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: aiosfpubsub-0.0.6.tar.gz
  • Upload date:
  • Size: 12.5 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.6.tar.gz
Algorithm Hash digest
SHA256 3933a426ca6377aff0c767da87b43d18f33c974dc750d55e12823f138959a353
MD5 6617b5ab90e46d94fb921be1dfd7d4f4
BLAKE2b-256 fc00058caa7a9a0edf0c662ae5d7e5827367fe7e47ad78f3eacd0b02d2538a4d

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: aiosfpubsub-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 11.3 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.6-py3-none-any.whl
Algorithm Hash digest
SHA256 e0d7ccfeb377941eb11846ba5a6a33b3ce81ac39c149c1d9b5da78f674c9bd3a
MD5 4b4934d40b270e8ba244ecaa2dbb71d1
BLAKE2b-256 283510229c46f98c3ac1ab04ff96316eda257261513ed7915ac908d974dd8662

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