Python Server SDK
∞ Installation
The Beams Python server SDK is available on PyPi here.
You can install this SDK by using pip:
pip install pusher_push_notifications
∞ Reference
∞ class PushNotifications
Constructs a new Beams client instance using your instance id and secret key (you can get these from the dashboard)
∞ Arguments
- ∞ instance_idString Required
-
The unique identifier for your Push notifications instance. This can be found in the dashboard under “Credentials”
- ∞ secret_keyString Required
-
The secret key your server will use to access your Beams instance. This can be found in the dashboard under “Credentials”.
∞ Returns
A Beams token for the given user.
∞ Example
beams_client = PushNotifications(
instance_id='YOUR_INSTANCE_ID_HERE',
secret_key='YOUR_SECRET_KEY_HERE',
)
∞ .publish_to_interests
Sends broadcast notifications to groups of subscribed devices using Device Interests
∞ Arguments
- ∞ interestslist<String> Min length=1, Max length=100 Required
-
List of interests to send the push notification to, ranging from 1 to 100 per publish request. See Device Interests
- ∞ publish_bodyDictionary
-
A dictionary containing the publish request body. See publish API reference
∞ Returns
A dictionary containing the publish response body. See publish API reference
∞ Example
response = beams_client.publish_to_interests(
interests=['hello'],
publish_body={
'apns': {
'aps': {
'alert': {
'title': 'Hello',
'body': 'Hello, world!',
},
},
},
'fcm': {
'notification': {
'title': 'Hello',
'body': 'Hello, world!',
},
},
'web': {
'notification': {
'title': 'Hello',
'body': 'Hello, world!',
},
},
},
)
print(response['publishId'])
∞ .publish_to_users
Securely send notifications to individual users of your application using Authenticated Users
∞ Arguments
- ∞ user_idslist<String> Min length=1, Max length=100 Required
-
List of ids of users to send the push notification to, ranging from 1 to 1000 per publish request. See Authenticated Users
- ∞ publish_bodyDictionary
-
A dictionary containing the publish request body. See publish API reference
∞ Returns
A dictionary containing the publish response body. See publish API reference
∞ Example
response = beams_client.publish_to_users(
user_ids=['user-001', 'user-002'],
publish_body={
'apns': {
'aps': {
'alert': {
'title': 'Hello',
'body': 'Hello, world!',
},
},
},
'fcm': {
'notification': {
'title': 'Hello',
'body': 'Hello, world!',
},
},
'web': {
'notification': {
'title': 'Hello',
'body': 'Hello, world!',
},
},
},
)
print(response['publishId'])
∞ .generate_token
Generate a Beams auth token to allow a user to associate their device with their user id. The token is valid for 24 hours.
∞ Arguments
- ∞ user_idString Required
-
Id of the user you would like to generate a Beams auth token for.
∞ Returns
Beams token string.
∞ Example
user_id = '<ID_OF_AUTHENTICATED_USER>'
token = beams_client.generate_token(user_id)
# Return token to device
∞ .delete_user
Remove the given user (and all of their devices) from Beams. This user will no longer receive any notifications and all state stored about their devices will be deleted.
∞ Arguments
- ∞ user_idString Required
-
Id of the user you would like to delete from Beams.
∞ Returns
None
∞ Example
user_id = '<ID_OF_USER_TO_BE_DELETED>'
beams_client.delete_user(user_id)