Send Push Notification Using Pushy (Python)

I wanted to send alert messages from my Python application to a few Android devices when certain event triggered. The requirement is time sensitive: preferbly notification is received within 5 minutes. I doubt Firebase Cloud Messaging is fast enough, SMS is probably too costly, thus I wanted to give Pushy a spin since it is marketed as Lightning-fast, highly-reliable push notification delivery.

NOTE: Other options to experiement include WhatsApp Business API or Telegram API.

Notes about Pushy

def send_alert(to, message):    PUSHY_SECRET_API_KEY = 'e56b....'    params = {        'to': to,        'data': {            'message': message        }    }    url = f"https://api.pushy.me/push?api_key={PUSHY_SECRET_API_KEY}"    r = requests.post(url, json=params)    if r.status_code == 200:        # print(json.dumps(r.json(), indent=2))        data = r.json()        print(json.dumps(data, indent=2))    else:        print(r.json()['error'])        r.raise_for_status()

Usage

PUSHY_DEVICE_TOKEN = '6b35...'send_alert(to=PUSHY_DEVICE_TOKEN, message='Hello')

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.