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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: aiosfpubsub-0.0.5.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.5.tar.gz
Algorithm Hash digest
SHA256 ef704729463ec933b243c8a24db453d782233c83a7058fe2c7354d3c54dd29d6
MD5 2f9d44486a7d4b6b1f119b8e37068579
BLAKE2b-256 e6c1c523d949b7a0ae856dc8f6a02e3bf523f1f390238393db8fa190ffc2c954

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: aiosfpubsub-0.0.5-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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 8d486ff070ae0bb024384acfbecdc094967ae57a97c15e2a59635bdc11dc3521
MD5 28b60524f0fbddc389df3ed0bb6ca714
BLAKE2b-256 752bc0a08bb0518aed2432243cf18d198a7b2624513cb330fcd72243bfe51549

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