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

Usage

Configuring the SDK for Your Instance

Use your instance id and secret key (you can get these from the dashboard) to create a PushNotifications instance:

Python

1
2
3
4
5
6
from pusher_push_notifications import PushNotifications

pn_client = PushNotifications(
    instance_id='YOUR_INSTANCE_ID_HERE',
    secret_key='YOUR_SECRET_KEY_HERE',
)

Publishing a Notification

Once you have created your PushNotifications instance you can publish a push notification to your registered and subscribed devices:

Python

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
response = pn_client.publish(
  interests=['hello'],
  publish_body={
    'apns': {
      'aps': {
        'alert': 'Hello!',
      },
    },
    'fcm': {
      'notification': {
        'title': 'Hello',
        'body': 'Hello, world!',
      },
    },
  },
)

print(response['publishId'])

Reference

Class pusher_push_notifications.PushNotifications(instance_id, Secret_key)

Arguments

  • instance_id(string): The unique identifier for your Push notifications instance. This can be found in the dashboard under "keys".
  • secret_key(string): The secret key your server will use to access your Beams instance. This can be found in the dashboard under "keys".

publish(interests, publish_body)

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 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

Did you find this document useful?

We are always striving to create the most accurate and informative docs as possible. If there is something especially wrong (or right) here then please let us know.