- Python Advent Calendar
- Posts
- Day 1: Mastering Notifications with Python
Day 1: Mastering Notifications with Python
๐ Welcome to the Python Advent Calendar! ๐
Every day till Xmas, we'll open a new door to Python secrets.
Today, let's explore how to send notifications using Python.
Whilst your code is running, you could use your newfound downtime to make a cup of tea โ reply to that email ๐ง share this newsletter on LinkedIn or Twitter ๐ฃ and make someoneโs day โค๏ธ
1๏ธโฃ jupyterlab_notify: Desktop alerts from Jupyter
๐ Last updated: May 2023
โฌ๏ธ Downloads: 106/week
๐ PyPI | โญ GitHub Stars: 5
๐ What is it?
Trigger desktop notifications using a Jupyter cell magic to alert you when a cell has completed execution. Inspired by the earlier jupyter-notify (notebook only, and last updated April 2021) and adapted to work with Jupyter Lab.
๐ฆ Install
pip install jupyterlab-notify
๐ ๏ธ Use
First register the magic:
%load_ext jupyterlab_notify
Then trigger alerts using the %%notify magic:
%%notify
import time
time.sleep(3)
2๏ธโฃ pync: macOS alerts from Python
๐ Last updated: Jan 2022
โฌ๏ธ Downloads: 455/week
๐ PyPI | โญ GitHub Stars: 353
โ What about Linux & Windows?
Check out plyer - itโs actively maintained and exposes a huge array of native APIs on Windows, Linux, macOS, Android and iOS including notifications, audio recordings, camera access, GPS, native file chooser, keystores, and more.
๐ What is it?
Triggers macOS notifications with customisable callback actions by wrapping the terminal-notifier command-line tool.
๐ฆ Install
pip install pync
๐ ๏ธ Use
import pync # Notification from "Terminal" pync.notify("Hello from Terminal") # Notification from "Python" pync.notify("Hello from Python", title='Python') # Click the notification to open Safari pync.notify("Click me!", activate='com.apple.Safari') # Click the notification to open a URL url = "https://github.com/CoefficientSystems/python-advent-calendar" pync.notify("Check out our GitHub repo!", open=url) # Make macOS talk joke = "Knock knock. Race condition. Who's there?" pync.notify("Want to hear a joke?", execute=f'say "{joke}"')
3๏ธโฃ Pushover: Send notifications to your mobile
๐ Last updated: June 2023
โฌ๏ธ Downloads: 91/week
๐ PyPI | โญ GitHub Stars: 23
๐ What is it?
Use the pushover.net service to deliver notifications in real-time to the Pushover app on iOS, Android, or desktop client. The Pushover service has a one-off cost of $5 per platform to cover service costs. Their website states: โWe don't show ads in any of our apps or notifications, and we don't sell any of your data.โ
๐ฆ Install
Install the Pushover app on your mobile device.
Sign up to try it free for 30 days and go to https://pushover.net/apps/build to get your account details.
Verify your email address to create an API token.
pip install pushover
๐ ๏ธ Use
First create a file called credentials.pushover
[pushover] app_key = ############################### user_key = ##############################
Then you can start firing notifications to your mobile device:
from pushover import PushoverClient client = PushoverClient('credentials.pushover') client.send_message("โ Your tea is ready.")
๐บ Stay Tuned for More! ๐
Every day is a new surprise in our Python Advent Calendar. Tomorrow, we'll delve into another exciting Python topic. Until then, check out our python-advent-calendar GitHub repo full of code examples from every newsletter.
Happy Coding! ๐
Your Python Advent Calendar Team ๐
๐ค Python Advent Calendar is brought to you by Coefficient, a data consultancy with expertise in data science, software engineering, devops, machine learning and other AI-related services. We code, we teach, we speak, weโre part of the PyData London Meetup team, and we love giving back to the community. If youโd like to work with us, just email [email protected] and weโll set up a call to say hello. โ๏ธ
P.S. We love feedback! Did you like today's content? Did we miss a good Python package? Is there a package or tool or top tip you think we should feature? Whatever it is, reach out to us. Hereโs a link to our privacy policy.