Python Server SDK

Installation

The Beams Python server SDK is available on PyPi here.

You can install this SDK by using pip:

bash

1
$ 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_id(string): The unique identifier for your Push notifications instance. This can be found in the dashboard under "Credentials".
  • secret_key(string): The secret key your server will use to access your Beams instance. This can be found in the dashboard under "Credentials".

Example

Python

1
2
3
4
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

  • interests(list<string> | Min length=1, Max length=100): List of interests to send the push notification to, ranging from 1 to 100 per publish request. See Device Interests
  • publish_body(dictionary): A dictionary containing the publish request body. See publish API reference

Returns
A dictionary containing the publish response body. See publish API reference

Example

Python

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
response = beams_client.publish_to_interests(
  interests=['hello'],
  publish_body={
    'apns': {
      'aps': {
        'alert': 'Hello!',
      },
    },
    'fcm': {
      '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_ids(list<string> | Min length=1, Max length=1000): List of ids of users to send the push notification to, ranging from 1 to 1000 per publish request. See Authenticated Users
  • publish_body(dictionary): A dictionary containing the publish request body. See publish API reference

Returns
A dictionary containing the publish response body. See publish API reference

Example

Python

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
response = beams_client.publish_to_users(
  users=['user-001', 'user-002'],
  publish_body={
    'apns': {
      'aps': {
        'alert': 'Hello!',
      },
    },
    'fcm': {
      '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_id(string): Id of the user you would like to generate a Beams auth token for.

Returns
Beams token string.

Example

Python

1
2
3
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_id(string): Id of the user you would like to delete from Beams.

Returns
None

Example

Python

1
2
user_id = '<ID_OF_USER_TO_BE_DELETED>'
beams_client.delete_user(user_id)