Push notifications with Python
Recently, I’ve had an interest in using push notifications to keep me updated. These are extremely common nowadays, but they’re surprisingly difficult to implement as a hobbyist. I wasn’t opposed to installing an app on my phone or laptop, but I did want whatever service I picked to be reasonably low-cost and easy to use.
I had a few criteria I was looking for in a push notification service provider. As I’m mostly planning on using these for personal notifications, the assumptions and criteria I’ve outlined might not necessarily be suitable for you.
- My main criteria was support for Android. Preferably this would come through a first-party app, but I’d also be open the option of using a third-party notification aggregator app. Services relying solely on push web APIs are not suitable.
- It would also be nice to have support for desktop notifications. Preferably through a desktop app, but those coming through from a website would also be acceptable.
- Lastly, I really wanted notification history, so I could look back and see what had been sent through in the past.
Something that was a passing thought, but not a serious consideration for me, was the ability to integrate the platform into my own website or a custom app.
Simplepush is an Android-only push notification service. Unlike most other push notification services, they don’t cater to large-scale notification delivery. In fact, their service doesn’t even support sending to more than a single recipient at a time. This makes it perfect for individual developers such as myself, who don’t need to be able to coordinate notifications to a team. There are no costs associated with using this API for service. However, the Android app must be purchased for continued use after a 7-day free trial (about $5).
To get started with Simplepush, I installed the app on my phone and was issued with a unique Device ID. Their website provides a demo of how to send notifications from the command line using
curl, but I prefer to use ntfy as I can swap out the notification backend easily. This code block demonstrates each approach:
Pushover seems like a reasonably mature product. However, their pricing model was a bit unexpected. The end user has to pay $4.99USD per platform they wish to use (iOS, Android or Desktop). Once they’ve paid that amount, they can have as many devices (of that platform) as they like registered to their account. Developers also have to pay — the first 7500 messages per month are free, after which charges apply. This is a good deal for developers, but the requirement for clients to pay made it unattractive for me.
Additionally, there’s no capacity for integrating their service into a third party own website or app. The only supported configurations are sending messages through their website or API, and receiving them through their own branded apps or website.
Pushsafer notifications support custom icons, formatting, up to three images and even the ability to reply with a basic string — but only when you use their app on iOS, Android or Windows 10 (not through Web Push for Chrome or Firefox).
They do not allow push notifications to be embedded into custom Android apps (you must use their branded app, which looks rather dated) and have a limited free tier of “a small quota of API calls for test purposes”. Additionally, fees are charged per API call made and not per message delivered; whether this works better for you or not depends on how many recipients you plan to push to.
But wait, there’s more!
- notify.run: Free and open-source, notify.run is a framework you can use to implement browser-based push notifications. They don’t support any advanced formatting, but they’re lightweight and extremely easy to send data to. One downside is the lack of authentication: anyone can push a message to your channel.
- Pushpad: Flexible notifications for developers to integrate into their own websites based on the web push notification standard.
- OneSignal: Free for pretty much everything up to an enterprise scale, but explicitly indicate they sell you and your users data for their own profit1.
- Pushjet: Open-source framework used to develop your own push notification services. There are no user accounts, instead devices are subscribed to services (to which messages can be pushed).
Looking at the options available, I initially thought I’d start with one of the options offering a free trial and then move onto the next when the free trial ended.
I started with Simplepush, but then never actually moved on. I didn’t end up buying it, even after the 7 day trial period. From my experience, the trial period didn’t stop delivery of new push notifications — I could continue to receive them, I just couldn’t open the app dashboard to see notification history. I realise that seeing the notification history was part of my original requirements, but in practice it wasn’t as big a deal as I was anticipating.
Since writing this article I’ve continued to look at alternative platforms for notifications. In particular, I’ve been experimenting with using Slack and a custom integration, which I’ll discuss in a future post.
“For free plans, OneSignal makes money by sharing data with advertisers and research companies.” OneSignal docs ↩