Posts Tagged ‘notification’

How to send a notification to your Android phone from a Python script

I have a long-running script and when something important happens, I’d like to send a notification to my Android phone. This way I shouldn’t be close to my machine. How to do it?

I found a very simple solution for this that can be set up in 3 minutes. This service can be found at . First, install the necessary package:

$ pip install notify-run

Then, register a channel:

$ notify-run register

It’ll print a QR code to the screen. Scan it with your phone and it brings you to a page where you can accept the notifications to your phone. Then, you can send notifications with the following Python snippet:

from notify_run import Notify

notify = Notify()
notify.send('sent from my Python script')

As can be seen, you don’t need to specify the name of the channel. It’s because it’s stored in the file ~/.config/notify-run and the notify_run module picks it up automatically.

You can also send a message to the channel from the command line, thus you can integrate it in any application:

curl<channel_id> -d "message goes here"


Categories: python Tags: , , , ,