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 details)
Built Distribution
File details
Details for the file aiosfpubsub-0.0.1.tar.gz
.
File metadata
- Download URL: aiosfpubsub-0.0.1.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e369e838ea1bfd7c7ccd09c4e221a8c092c37cab541e90c77238d29676cb6924 |
|
MD5 | 391dfd522b60869794c4c677ece64ae3 |
|
BLAKE2b-256 | d1081d04e194a88964389df6825a782dc194557a0ded4bdd159df2b167eb7626 |
Provenance
File details
Details for the file aiosfpubsub-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: aiosfpubsub-0.0.1-py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7392daddaa7032cdc3227442078c302c9a1f385b45d403b7358f7c5c3cadd5d1 |
|
MD5 | 5f33ba007df80662004ca5544053da8a |
|
BLAKE2b-256 | 234e997482e491332fe9c1b982d489f62c1eabf67ec7e9c7efa2d385d3f43a2d |