How Suprsend identifies a user

SuprSend identifies users with immutable distinct_id. It’s best to map the same identifier in your DB with distinct_id in SuprSend. Do not use identifiers that can be changed like email or phone number. You can view synced users by searching distinct_id on Users page.

Create User

To create a new user or to update an existing user, you’ll have to fetch user instance. Call supr_client.user.get_instance to instantiate user object.

import suprsend

supr_client = suprsend.Suprsend("workspace_key", "workspace_secret")

distinct_id = "distinct_id"  # Unique identifier of user in your application

# Instantiate User profile
user = supr_client.users.get_edit_instance(distinct_id)

Edit User

To Edit user, you need to first fetch user instance, call all the update methods and save changes using users.async_edit method.

#Fetch user instance
user = supr_client.users.get_edit_instance("__distinct_id__")

#Call user update methods
user.set_timezone("America/Los_Angeles")
user.set("name", "John Doe")

#Save Changes
res = supr_client.users.async_edit(user)
print(res)

Here’s a list of all edit methods:

After calling add*/remove*/unset methods, don’t forget to call users.async_edit() since user edit is async update and the changes will be sent to SuprSend only after calling this method.

Bulk Update Users

There isn’t any limit on number-of-records that can be added to bulk_users instance.

Use .append() on bulk_users instance to add however-many-records to call in bulk.

# Create bulk instance
bulk_ins = supr_client.users.get_bulk_edit_instance()

# Prepare multiple users edit instance 
distinct_id1 = "__distinct_id1__"  # User 1
u1 = supr_client.users.get_edit_instance(distinct_id1)
u1.add_email("u1@example.com")

distinct_id2 = "__distinct_id2__"  # User 2
u2 = supr_client.users.get_edit_instance(distinct_id2)
u2.add_email("u2@example.com")

# Append users to the bulk instance
bulk_ins.append(u1, u2)

# -------
res = bulk_ins.save()
print(res)

Bulk API supported in SDK version 0.2.0 and above:

Bulk API is supported in SuprSend python-sdk version 0.2.0 and above. If you are using an older version, please upgrade to the latest SDK version.

Get User Details

res = supr_client.users.get("__distinct_id__")
print(res)

Delete User

res = supr_client.users.delete("__distinct_id__")
print(res)

Get list of objects subscribed by user

You can pass optional query parameters -limitbeforeafter

res = supr_client.users.get_objects_subscribed_to("__distinct_id__", {"after": "01JJW6HXXXXPB59ARDW85G0KN", "limit": 1})
print(res)

Get lists subscribed by user

You can pass optional query parameters -limitbeforeafter

res = supr_client.users. get_lists_subscribed_to("__distinct_id__", {"after": "01JJW6HXXXXPB59ARDW85G0KN", "limit": 1})
print(res)