Suprsend library for Python
Project description
suprsend-py-sdk
This package can be included in a python3 project to easily integrate
with Suprsend
platform.
We're working towards creating SDK in other languages as well.
Suprsend SDKs available in following languages
- python3 >= 3.7 (
suprsend-py-sdk
)
Installation
suprsend-py-sdk
is available on PyPI. You can install using pip.
pip cache purge && pip install suprsend-py-sdk
This SDK depends on a system package called libmagic
. You can install it as follows:
# On debian based systems
sudo apt install libmagic
# If you are using macOS
brew install libmagic
Usage
Initialize the Suprsend SDK
from suprsend import Suprsend
# Initialize SDK
supr_client = Suprsend("env_key", "env_secret")
Following example shows a sample request for triggering a workflow.
It triggers a notification to a user with id: distinct_id
,
email: user@example.com
& androidpush-token: __android_push_token__
using template purchase-made
and notification_category system
# Prepare Workflow body
workflow_body = {
"name": "Purchase Workflow",
"template": "purchase-made",
"notification_category": "system",
"delay": "15m",
"users": [
{
"distinct_id": "0f988f74-6982-41c5-8752-facb6911fb08",
"$email": ["user@example.com"],
"$androidpush": ["__android_push_token__"],
}
],
"data": {
"template": {
"first_name": "User",
"spend_amount": "$10"
},
}
}
# Trigger workflow
response = supr_client.trigger_workflow(workflow_body)
When you call supr_client.trigger_workflow
, the SDK internally makes an HTTP call to SuprSend
Platform to register this request, and you'll immediately receive a response indicating
the acceptance status.
Note: The actual processing/execution of workflow happens asynchronously.
# If the call succeeds, response will looks like:
{
"success": True,
"status": 201,
"message": "Message received",
}
# In case the call fails. You will receive a response with success=False
{
"success": False,
"status": 400,
"message": "error message",
}
Add attachments
To add one or more Attachments to a Notification (viz. Email, Whatsapp),
call supr_client.add_attachment(...)
for each file.
Ensure that file_path is proper, otherwise it will raise FileNotFoundError.
# this snippet can be used to add attachment to workflow_body.
file_path = "/home/user/billing.pdf"
supr_client.add_attachment(workflow_body, file_path)
Attachment structure
The add_attachment(...)
call appends below structure to data->'$attachments'
{
"filename": "billing.pdf",
"contentType": "application/pdf",
"data": "Q29uZ3JhdHVsYXRpb25zLCB5b3UgY2FuIGJhc2U2NCBkZWNvZGUh",
}
Where
filename
- name of file.contentType
- MIME-type of file content.data
- base64-encoded content of file.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file suprsend-py-sdk-0.0.13.tar.gz
.
File metadata
- Download URL: suprsend-py-sdk-0.0.13.tar.gz
- Upload date:
- Size: 9.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0529ef5c7ed3d454de1b8b1f3a0842566f237e8d33922d57a41d342261c7cc47 |
|
MD5 | 8ddd02279ef502f5352133cc63304d99 |
|
BLAKE2b-256 | 149c9ef9b63898f7a1d04de391fb5d9b2153f6a268872f7452111f0332b5e606 |
File details
Details for the file suprsend_py_sdk-0.0.13-py3-none-any.whl
.
File metadata
- Download URL: suprsend_py_sdk-0.0.13-py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f5cec5bf9f577e5d52ee35a2ac235989807978417de3fbca5e0da4b53513fcc |
|
MD5 | ef1c8b1ca93dee024fdc3e627dc27fdd |
|
BLAKE2b-256 | 247006dde0b7d14983310f212e5e0d4b992011344ad0b1de86b16ad615a056be |