Do you need to write a Python script that needs some user input but you don’t want to create a whole frontend or ssh into your server all the time? An actionable notification sent from your script might be the perfect solution.
Actionable notifications are push notifications with action buttons associated to them. Selecting an action usually has some immediate effect.
Simplepush is an app for iOS and Android which enables you to send actionable notifications to your devices through an API. With the Simplepush Python library you can send actionable notifications and get a callback directly in Python once an action is selected. Scroll down to see how easy it is.
Simplepush is free up to five actionable notifications per month and 100 push notifications (without actions) per month. For $9.99/year you get unlimited actionable notifications.
We will assume that you already installed Python3 and Pip3. Python2 is not supported.
pip3 install simplepush
2) Install Simplepush on your Android or iOS device. After you launch the app for the first time, a personal key is presented to you. This key is necessary to send push notifications to your device.
The following Python code shows how to send an actionable notification to a device that’s associated to the key
YourKey (you need to replace
YourKey with the key you received when installing the app).
In addition to that the code defines a callback that fires once an action was selected.
If you run our example code and replaced the key with your key, you will immediately see a notification popping up on your device with an
If you select one of the three actions, the
callback function will be called and the selected action is printed to the console.
As you can see from the example code there are several additional arguments passed to the
If you don’t want to block your whole Python program while waiting for an action to be selected, you can use the asynchronous version of the send function:
It is also important to note that there is a default timeout of 60 seconds associated to the
This means that an
FeedbackActionTimeout exception will be thrown if no action has been selected at the moment of the timeout.
To adjust the timeout, set the
feedback_callback_timeout argument to the value that you want.