How to send push notifications on your phone easily and for free?

If you code a bit of your own scripts at an amateur level, and are looking for a simple way to get alerts on your Android / iOS smartphone very easily, I have exactly what you need.

It is a project named ntfy (pronounced “notify”) that allows you to send a notification to your phone using a simple curl command or a script (Python, Go, JavaScript…).

Here is how it works. You install ntfy on Android (F-Droid) or iOS and once it’s done, you choose a “topic” which is a kind of key. This key is public so create something random and long enough that nobody can guess it. Otherwise, someone will have fun sending you notifications. For the example, I will choose “wikikeep234”.

Then, you just have to throw the notification via Curl like this:

curl -d "hello" ntfy.sh/wiki1234

In Python, it would look like this:

requests.post("https://ntfy.sh/wiki1234",
    data="hello".encode(encoding='utf-8'))

In JavaScript:

fetch('https://ntfy.sh/wiki1234', {
    method: 'POST', // PUT works too
    body: 'hello'
})

The cool thing about ntfy is that you can host it yourself since the project is open source. So you can deploy an ntfy server on your machine and manage everything yourself, keeping of course the applications made by the project developers.

It’s free and you don’t even need to create an account !

Leave a Comment