Skip to main content

Push Notifications

Project description

pushno is a Python package for sending push notifications to mobile devices. It provides a simple, common interface for sending push notifications via the two services PushOver and Prowl.

pushno focuses on Python 3.x so there will be no legacy support for Python 2.x. Due to its modular structure theoretically further services can be added.

Module Installation

The easiest way to install the newest version of the pushno module is via pip:

pip install -U pushno

or clone/download this repository and install it:

python setup.py install

Basic Setup

In the first step, you need to setup an account at PushOver or Prowl and create a corresponding API key that you want to use.

Examples

The easiest way to send a push message with pushno is to use the PushNotification class that provides a common interface to all available push notification services.

Prowl

For Prowl do:

from pushno import PushNotification

PUSHNO_PROWL_API_KEY = "<your_prowl_api_key>"

pn = PushNotification(
    "prowl", api_key=PUSHNO_PROWL_API_KEY, application="pushno"
)
is_valid, res = pn.validate_user()
if is_valid:
    pn.send(event="How simple is that?", description="Great News")
else:
    print(res)

PushOver

For PushOver do:

from pushno import PushNotification

PUSHNO_PUSHOVER_API_KEY = "<your_pushover_api_key>"
PUSHNO_PUSHOVER_USER_KEY = "<your_pushover_user_key>"

pn = PushNotification(
    "pushover", token=PUSHNO_PUSHOVER_API_KEY,
    user=PUSHNO_PUSHOVER_USER_KEY
)
is_valid, res = pn.validate_user()
if is_valid:
    pn.send(title="How simple is that?", message="Great News")
else:
    print(res)

Note that the validation part is optional, so if you are sure that the API key is working as expected, you can send the push message directly. As a result, you can send a push message in two lines of code. The API key is the key of the specific app.

It is also possible to use the underlying client classes directly, which is however a little bit more verbose:

Prowl

from pushno.plugins import ProwlClient
from pushno.messages import ProwlMessage

# prepare the pushover client
client = ProwlClient(PUSHNO_PROWL_API_KEY)

# validate the user key
is_valid, res = client.validate_user()
if is_valid is True:
    # key is still valid => send a notification message
    res = client.send(
        ProwlMessage(
            application="pushno",
            event="How simple is that?",
            description="Great News"
        )
    )
    print(res)

else:
    print(res)

PushOver

from pushno.plugins import PushOverClient
from pushno.messages import PushOverMessage

# prepare the pushover client
client = PushOverClient(PUSHNO_PUSHOVER_API_KEY, PUSHNO_PUSHOVER_USER_KEY)

# validate the user key
is_valid, res = client.validate_user()
if is_valid is True:
    # key is still valid => send a notification message
    client.send(
        PushOverMessage(
            title="Great News",
            message="How simple is that?"
        )
    )

else:
    print(res["errors"])

Again the validation part of the user’s API key is optional.

For the complete example scripts see https://github.com/keans/pushno/tree/master/examples .

Development

If you want to contribute in the development, please check out the source code at https://github.com/keans/pushno.git .

To get started with the development:

git clone git@github.com:keans/pushno.git
cd pushno/
python3 -m venv env
source env/bin/activate
pip install -r requirements.txt

For verbose debug output simply set the logging level to debug:

import logging
logging.basicConfig(level=logging.DEBUG)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pushno-0.0.3.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

pushno-0.0.3-py2.py3-none-any.whl (11.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file pushno-0.0.3.tar.gz.

File metadata

  • Download URL: pushno-0.0.3.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for pushno-0.0.3.tar.gz
Algorithm Hash digest
SHA256 44385aab29a49d957fd7e818164dc72d8a4d0bb97cb530f1af4a6c7a71708226
MD5 c8dec1bcba1c0d3831ab8d854b6740d6
BLAKE2b-256 de09ddf100187c8c6e49afdad832900d61790f8dd7adeda67286b6a315fe8530

See more details on using hashes here.

File details

Details for the file pushno-0.0.3-py2.py3-none-any.whl.

File metadata

  • Download URL: pushno-0.0.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 11.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for pushno-0.0.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1b580d5ecb613acfc15df5c8964f751d8f672865a9fab810803c492e81c94cf5
MD5 2402e7e4bb780c0bcef3246e3f30ecc3
BLAKE2b-256 a7eaa477c0028a3d3e7dcaf4fd3010ca34facfba35eb33a062df09550c0cc87c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page