Skip to main content
https://img.shields.io/pypi/l/python-pushover-open-client.svg PyPI-Server https://img.shields.io/pypi/pyversions/python-pushover-open-client.svg https://img.shields.io/pypi/status/python-pushover-open-client.svg Project generated with PyScaffold

python-pushover-open-client

Command line app and framework for receiving and processing Pushover push notifications in real time.

Features

  • Receive notifications real time via Pushover websocket server.

  • Execute python funcions via commands received by notification, passing arguments as *args.

  • Execute shell commands, passing arguments.

  • Execute python functions to all received notifications (eg.,. you can use Popen to send all notifications to notify-send.)

  • Can be run as a system service, enabling your scripts from boot time.

  • It is being developed with facilities to make it easy subclassing.

Installing

pip install python-pushover-open-client

Python minimum version 3.10 is needed. (because of the `|` union annotations.)

Setting Up

The script expects a file at the home directory named ~/.pushover-open-client-creds.json. The file should be a JSON file with account’s email and password, this way:

file: ~/.pushover-open-client-creds.json

{
  "email": "USERS@EMAIL.ETC",
  "password": "M4HSUP3RBPASS"
}

Given the above, by logging and getting an auth secret, a new device will be created wielding it’s device_id, and that file will be updated containing all these four values.

Using

Command line

Our command line pushover-open-client still needs more functions, but we already have one. His whole interface is here.

pushover-open-client json

This command outputs new received notifications and can be used to pipe for your own scripts to be processed.

Programatically

Here is an example script of how using decorators to use the lib. More examples will be added soon, as there are more decorators/functions to be used.

file: notify.py

#!/usr/bin/env python

from subprocess import Popen

from python_pushover_open_client import register_command
from python_pushover_open_client import register_parser
from python_pushover_open_client import PushoverOpenClientRealTime


# Let's use a decorator to registrate a command function; it will be executed
# when a message with `mycmd_rawdata` as the first word is received. All
# the arguments, *ie.*, all the words in the notification, including
# `mycmd_rawdata` will be passed to ``*args``:

@register_command
def mycmd_rawdata(*args, raw_data=None):
    print("RAW DATA IS:", raw_data)

# this decorator register a parser which is executed for each new
# notification received; here we have two examples:

@register_parser
def my_notify_send_parser(raw_data=None):
    args_str = "notify-send \"{message}\"".format(message=raw_data["message"])
    Popen(args=args_str, shell=True)


@register_parser
def my_print_parser(raw_data=None):
    print("MESSAGE RECEIVED:", raw_data)

# this instantiates the Pushover websocket class and runs it:
client = PushoverOpenClientRealTime()
client.run_forever()

You can save the script above to a file (eg. ~/notify.py), then make it executable and run, after you have installed the package and entered your Pushover credentials:

chmod +x notify.py
./notify.py

Then while it is running, try to send a notification to the device (or all the devices) via Pushover website or other notification sending app.

A Little More Inner

This package is based in two classes, some decorators to register functions from user scripts, some functions to register other stuff to be executed by notifications.

The two classes are python_pushover_open_client.PushoverOpenClient and python_pushover_open_client.PushoverOpenClientRealTime. The first manages credentials, authentication, device registration, message downloading, message deletion etc, like specified by the Pushover Open Client API documentation, and is consumed by the second class. The second class connects to the Pushover’s websocket server with the given credentials (secret and device_id) and keep the connection open, receiving messages and executing callbacks when and according to each server message is received.

By now, decorators and top level functions are used to register functions to be executed when certain commands are received by notification (@register_command, @register_command_parser, register_shell_command(), register_shell_command_alias()), or to register parsers which will be executed when every notification is received @register_parser.)

Contributing

Please open an issue if you want to contribute with code. Or use discussions.

The sources’ package in reality contain only two files:

  • __init__.py - This contains the python_pushover_open_client library itself.

  • __main__.py - Will hold the command-line interface logic for the pushover-open-client command as it is developed.

Support

You can open a issue or a message in discussions for support in using/getting the code.

Is it ready already?

100%

Note

This project has been set up using PyScaffold 4.1.4. For details and usage information on PyScaffold see https://pyscaffold.org/.

Metadata

Release files for python-pushover-open-client 0.0.15

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-pushover-open-client 0.0.15
File Size Uploaded
python-pushover-open-client-0.0.15.tar.gz 45.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for python-pushover-open-client 0.0.15
File Interpreter ABI Platform
python_pushover_open_client-0.0.15-py3-none-any.whl Python 3 none any Details

Total release size: 70.1 kB

Release files / python-pushover-open-client-0.0.15.tar.gz

Download URL python-pushover-open-client-0.0.15.tar.gz
Size 45.3 kB
Tags Source
SHA-256 checksum
How to use checksums
6c8c5ef45ed9090801e9493ccb7b2eff10d3139305494ba0def4336c413ba410
BLAKE2b-256 checksum
How to use checksums
bd4d3d75828234055f8448c004a0d46014574466b63be97e01cc5bfc59c7a1cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.5

Release files / python_pushover_open_client-0.0.15-py3-none-any.whl

Download URL python_pushover_open_client-0.0.15-py3-none-any.whl
Size 24.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
728b9318c9546bb2cee8ba8fdd0a3c70c5ff879e07d49063092459bca8e0f4f9
BLAKE2b-256 checksum
How to use checksums
b0a95c2d5262d1ea9bbf3f0641ba84e731a942b561c0d078e58e9db85c6153f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.5

Release history Release notifications | RSS feed

This release

0.0.15 This release

2 release files

0.0.14

2 release files

0.0.11

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page