Python — Sending Push Notifications To Your Phone

Jonas A.
myNotifier
Published in
3 min readDec 12, 2021

In this tutorial, I’ll talk about how to send push notifications to yourself using Python and the myNotifier API.

myNotifier

myNotifier is an API with the possibility to send push notifications to your mobile phone. This can be beneficial in many different circumstances such as monitoring your API or Saas product. You can also send server updates or updates from your custom python scripts. The possibilities are endless ☝️

Getting Started

Getting started is no more than 3 simple steps and can be done in less than 5 minutes.

  • Sign up for myNotifier (It’s fast and free)
  • Write a few lines of Python code
  • Sending notifications

Sign Up

  • Head on over to myNotifier and create a free account. There’s a Pro plan as well but we won’t be needing that for today's purpose.
  • Download the app on the Apple Store for IOS or Google Play Store for android. Whichever one you own.
  • Log in on the app with the account you created earlier, and press ‘Add This Device’ under the ‘Profile’ tab.
You don’t need any more setup on your phone

Now the API knows which phone to send notifications to. You can add multiple phones by logging in to other phones and adding them as well.

Write a few lines of Python code

We’ll be using the Python module called ‘Requests’ to send HTTP requests to the API.

  • If you don’t have it installed already, you can install it by running ‘pip3 install requests’ in the terminal of your computer
  • Next up, create a new python file called ‘notification.py’ in your favorite code editor. I use VSCode but you can use whichever one you like.
  • Now it’s time to write the code. Write in the code below and we’ll go through it afterward.
import requestsrequests.post('https://api.mynotifier.app', {    "apiKey": '****-****-****-****',    "message": "Our first notification!",    "description": "This is cool",    "type": "info", # info, error, warning or success})
  • First of all, you need to provide your own apiKey. You can get yours by logging in to the web app here and going to the ‘Account tab’ and clicking ‘Reveal Api Key’.
The account tab in the web app
  • Paste in the API key instead of the ‘****-****-****-****’.
  • The ‘message’ and ‘description’ properties can be anything you want.
  • The ‘type’ property can be either ‘info’, ‘error’, ‘warning’, or ‘success’. It defaults to info if nothing is set.

Now all the code is written and all we have left to do is run it⚡️

Sending notifications

Now you can run the code by typing ‘python3 notification.py’ in the terminal in the directory where your file is located. If everything was done correctly you should now have your very first notification on your phone.

And you can see a history of all the notifications on the ‘Dashboard’ tab in the web app.

And that’s all there is to it ☝️

If you by any chance have any problems or have any questions or feedback for this tutorial, contact me on Twitter or comment on this post and I’ll respond as soon as possible. Give a follow while you’re at it if you want to hear about updates on myNotifier and be a part of the growth ⚡️🙏

Any love in form of claps or comments on this blog post would also be greatly appreciated 😁

Thank you for reading and remember to keep on coding on 💙

All the best,

Jonas A.

--

--

Jonas A.
myNotifier

Passionate about software development and indie business. Currently building mynotifier.app ⚡️