background-hooknotifierbackground-hooknotifier
Last update: Feb 25, 20236 minutes read

Receive push notifications from Python

illuday

Emmanuel Russeil

February 25, 2023

Interact with your phone from your Python scripts using webhooks. Quickly configure and send push notifications to your Hook.Notifier inbox.

Introduction

About Python

Python is a popular programming language used for many fields such as web development, data science, machine learning, scripting, robotics, and finance. It is appreciated for its simplicity and readability, and is particularly popular in data science and machine learning due to its dedicated libraries.

Check Python official website

About HookNotifier

HookNotifier is a push notification inbox, it allows you to receive push notifications from webhooks.

Check Hook.Notifier official website

Our first push notification from Python

hook notifier notification

Objective

As the purpose of this guide is to introduce you to the basics of Hook.Notifier, we will keep it very simple, and we will try to receive a test notification from a basic python script.

The Requests library to the rescue

To communicate with Hook.Notifier, we will need to set up a webhook (http request). To do this we will use the "Requests" library which is widely used by the Python community. You can make a request in another way but the following example will be based on this library.

The following command allows you to install the "Requests" library.

[[bash]]pip install requests

1. A small Python script

We will create a simple python script that includes all the parameters that Hook.Notifier provides. For more information, we refer you to our article Get Started.

get started with hook.notifier header

Get started with Hook.Notifier

This article aims to introduce you to Hook.Notifier, including its benefits, recommended introductory articles, and developer documentation.

[[python]]import requests
import urllib

# Required
identifier = '%_YOUR_IDENTIFIER_%'
key = '%_YOUR_KEY_%'
object = 'My notification from Python'
body = 'Hooray, my notification from my python script has been sent!'

# Optionnal
tags = 'python,test'
color = urllib.parse.quote('#7C86B4')
image = ''
redirectUrl = 'https://hooknotifier.com'
sound = true
sendToTeam = false
preventData = false

innerData = {
  'author': '...',
  'message': '...',
  'receiver': '...'
}

parameters = f'object={object}&body={body}&tags={tags}&color={color}&image={image}&redirectUrl={redirectUrl}&sendToTeam={sendToTeam}&sound={sound}&preventData={preventData}'

headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}

r = requests.post(f'https://hooknotifier.com/{identifier}/{key}?{parameters}', json=innerData, headers=headers)

This script simply executes an HTTP request to our Hook.Notifier server sending the parameters of your notification. Remember to change your identifiers "%_YOUR_IDENTIFIER_%" and "%_YOUR_KEY_%" and to vary the different parameters of your notification to adapt it to your needs.

2. Triggering and sending

All you have to do is to send your notification by executing your Python script. You should receive your notification within a second!

Our push notifications has arrived!
Our push notifications has arrived!

Conclusion

You should now be able to send notifications from your Python environment. This solution fits perfectly with all Python technologies like Flask for example.

Send notifications when you run server scripts, inject data in the object or body of your notification, get statistics... The possibilities are unlimited with Hook.Notifier. Be creative!


If you like this article, feel free to connect with us on Twitter.

If you have any questions or special requests, such as needing clarification on the terms discussed in this article, more information on a specific part, or additional articles and tutorials, please feel free to provide feedback through the widget below.

illuday

Emmanuel Russeil

February 25, 2023

What do you think of this article?

robot need an integration

You need an integration?

Let us know what you need, we will work to bring you a solution.

Fill our form

Related

get started with hook.notifier header

Get started with Hook.Notifier

This article aims to introduce you to Hook.Notifier, including its benefits, recommended introductory articles, and developer documentation.