Skip to main content

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)
  • node (suprsend-node-sdk)
  • java (suprsend-java-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("workspace_key", "workspace_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


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

Uploaded Source

Built Distribution

suprsend_py_sdk-0.0.14-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: suprsend-py-sdk-0.0.14.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for suprsend-py-sdk-0.0.14.tar.gz
Algorithm Hash digest
SHA256 2867af44d2e0b69032301c693ab3d9709dd0bb0b8507b561450685acff618cf4
MD5 897afc63b52f5e7d7cc5e45719ec4f09
BLAKE2b-256 e8bd8b9fd49143a2304d54046862fbd04e804a879e88d68296dd6e2ad3407e85

See more details on using hashes here.

File details

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

File metadata

  • Download URL: suprsend_py_sdk-0.0.14-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for suprsend_py_sdk-0.0.14-py3-none-any.whl
Algorithm Hash digest
SHA256 af319e211607343e6893132c8974d41b95b3957303168f89d85a675a15eea966
MD5 7cc210791bee5b74306bb1ea6543ede3
BLAKE2b-256 5204c8d8b511ff65a3be21af1ba9c40f5425a8c5b0aa421738c59b876810cdae

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