Skip to main content

Python SDK to integrate with Suprsend Platform

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

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"
        },
        "$attachments": [
            {
                "filename": "billing.pdf",
                "contentType": "application/pdf",
                "data": "Q29uZ3JhdHVsYXRpb25zLCB5b3UgY2FuIGJhc2U2NCBkZWNvZGUh",
            }
        ],
    }
}

# Trigger workflow
supr_client.trigger_workflow(workflow_body)

Add attachments

Structure of an attachment

// attachment-structure
{
    "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.

To add one or more Attachments to a Notification (viz. Email, Whatsapp), add an attachment-structure for each of the attachment-files to data->"$attachments" as shown below.

# this snippet can be used to create attachment-structure given a file_path.
file_path = "/home/user/billing.pdf"

resp = supr_client.get_attachment_json_for_file(file_path)
# if some error occurs while reading content, the call returns success=False
if resp["success"]:
   attachment = resp["attachment"] 
   # add the attachment to workflow_body->data->$attachments
   if workflow_body["data"].get("$attachments") is None:
      workflow_body["data"]["$attachments"] = []
   workflow_body["data"]["$attachments"].append(attachment) 
else:
    # Handle as per requirement.
    pass

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

suprsend-py-sdk-0.0.11.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

suprsend_py_sdk-0.0.11-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file suprsend-py-sdk-0.0.11.tar.gz.

File metadata

  • Download URL: suprsend-py-sdk-0.0.11.tar.gz
  • Upload date:
  • Size: 7.5 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.7.3

File hashes

Hashes for suprsend-py-sdk-0.0.11.tar.gz
Algorithm Hash digest
SHA256 a14b31846ecd31e5afb78f907b4151f2d2908e7b3057e0b3e95f46ad8be7401f
MD5 b0338431bb00baa9f1ff59a7cd26cb5a
BLAKE2b-256 b514e1a501f525519df7a23b6e1a81bf19ae9feb401a85fcae7f564c4b0f180d

See more details on using hashes here.

File details

Details for the file suprsend_py_sdk-0.0.11-py3-none-any.whl.

File metadata

  • Download URL: suprsend_py_sdk-0.0.11-py3-none-any.whl
  • Upload date:
  • Size: 9.6 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.7.3

File hashes

Hashes for suprsend_py_sdk-0.0.11-py3-none-any.whl
Algorithm Hash digest
SHA256 b97ec03af4b70af14e169009ab1544915bd5412baf9101dd11cfe5f2940137b4
MD5 12bb90ca0fe2ac4d0216a09efe16cf71
BLAKE2b-256 c21211092c35bb32f49db2f18e928ec0ab108696cdee65bc9d93cc36afe7e3fb

See more details on using hashes here.

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