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.10.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: suprsend-py-sdk-0.0.10.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.10.tar.gz
Algorithm Hash digest
SHA256 90a4260a7601306ae52e76f57a88828ab8a79039c3303053c1dfc0116302a6a8
MD5 dee202f3ba6908a62ea79bde34efaf36
BLAKE2b-256 6da841c3f5e056e21d338111f9161377dd9a5270d9f828bca20534d55d9c1742

See more details on using hashes here.

File details

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

File metadata

  • Download URL: suprsend_py_sdk-0.0.10-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.10-py3-none-any.whl
Algorithm Hash digest
SHA256 f9c168a91904e27e4cbb279e25f4baaef643e6ec9977c0a9bdcdba0f8adec588
MD5 9d13127b8ec2fab228b68316e7bb195f
BLAKE2b-256 5076b80d1e030297ebc56dc864556786565450371c05a3ccc2428e1e8f60ad81

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