- Notifications
You must be signed in to change notification settings - Fork5
Mac OS notifications from Python
License
knowsuchagency/klaxon
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Send Mac OS (ornotifiers) notifications from the terminal or Python programs.
This is especially useful for when you want a push notificationfor some long-running background task.
Similar to theterminal-notifier ruby gem,but posix-compliant and able to send notifications viathenotifiers library.
For command-line use, the recommended method of installation is throughpipx.
pipx install klaxon
Naturally, klaxon can also be pip-installed.
pip install klaxon
# blank notificationklaxon# with custom messageklaxon --message"this is the message body"# pipe message from other programecho"this is the message body"| klaxon --
fromklaxonimportklaxon,klaxonify# send a notificationklaxon(title='hello, klaxon',subtitle='hola',message='it me')# we can decorate our functions to have# them send notifications at termination@klaxonifydefhello(name='world'):returnf'hello,{name}'@klaxonify(title='oh hai',output_as_message=True)deffoo():return"This will be the message body."
You'll need to install klaxon with thenotifiers
extra.
pipx install klaxon[notifiers]
You will need a~/.config/klaxon/config.toml
orpyproject.toml
file with thetool.klaxon
namespace configured at the top level. Values from the latter willoverride values in the former.
enable-notifiers
will need to be set totrue
and you will need a[[notifiers]]
key.
The latter will determine the parameters passed to thenotifiers.notify
method.
For example:
~/.config/klaxon/config.toml
enable-notifiers =true[[notifiers]]name ='slack'# see https://api.slack.com/incoming-webhooks#getting-startedwebhook_url = {{your webhook url}}[[notifiers]]name ='pushover'user = {{your user token}}token = {{your application token}}
Voila! Now messages sent from klaxon will be pushed to slack and pushover.
git clone git@github.com:knowsuchagency/klaxon.gitcd klaxon# create a virtualenv and activate itpython3 -m venv .venvsource .venv/bin/activate# install poetry and use it to install project dependenciespip install -U pippip install poetrypoetry install# this will install `invoke` which will let you use the tasks defined in `tasks.py`# install pre-commit hooksinv install-hooks# from now on, as you make changes to the project, the pre-commit hooks and# github workflows will help make sure code is formatted properly and tests# are invoked as you commit, push, and submit pull requests