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
usage
import asyncio
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.1.tar.gz
(10.6 kB
view hashes)
Built Distribution
Close
Hashes for aiosfpubsub-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7392daddaa7032cdc3227442078c302c9a1f385b45d403b7358f7c5c3cadd5d1 |
|
MD5 | 5f33ba007df80662004ca5544053da8a |
|
BLAKE2b-256 | 234e997482e491332fe9c1b982d489f62c1eabf67ec7e9c7efa2d385d3f43a2d |