Docs

  • Channels Channels
  • Beams Beams
  • Developers
  • Support
  • Blog
  • Sign up
    • Search powered by Algolia
    • Sign in
    • Sign up
    • Channels
    • Beams
    • Getting started
      • Android
        • 1. Configure FCM
        • 2. Integrate SDK
        • 3. Initialize Beams
        • 4. Publish Notifications
      • iOS
        • 1. Configure APNS
        • 2. Integrate SDK
        • 3. Publish Notifications
      • Web
        • 1. SDK integration
        • 2. Safari configuration
      • Flutter
        • 1. Configure FCM and APNS
        • 2. Integrate SDK
        • 4. Publish Notifications
    • Concepts
      • Subscribers
      • Device interests
      • Authenticated users
      • Insights
      • Webhooks
    • Guides
      • Handle incoming notifications
        • Android
        • iOS
        • Web
        • Flutter
      • Publishing to multiple devices
      • Publish to specific user
        • Android
        • iOS
        • Web
        • Flutter
      • Web push guides
        • Using an existing service worker
        • Web notification permissions in Firefox
        • Handling Safari certificate expiration
    • Reference
      • Client SDKs
        • Android
        • iOS
        • Web
      • All Libraries
      • Server SDKs
        • Go
        • PHP
        • Node.js
        • Python
        • Java/Kotlin
        • Ruby
        • Swift
      • API
        • Publish API
        • Customer API
        • Device API
        • Reporting API
        • Webhooks
      • Platform Publish Formats
    • Pusher lab

    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=1000 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)

    Contents

    • Installation
    • Reference
      • class PushNotifications
      • .publish_to_interests
      • .publish_to_users
      • .generate_token
      • .delete_user

    Spotted something that isn’t quite right? Create an issue on GitHub.

    Copyright © 2024 Pusher Ltd. All rights reserved.

    • Support,
    • Status
    • Follow Pusher on Twitter Twitter
    • Subscribe to Pusher’s channel on YouTube
    • Follow Pusher on LinkedIn
    • Follow Pusher on Github GitHub
    • Follow Pusher on Twitch Twitch
    • Follow Pusher on Discord Discord