This project provides a Python interface to the Pushover API, allowing you to send notifications through the Pushover service. The package supports sending messages, emergency messages, and group messages, as well as listing available sounds.
To install the package, you can use pip
:
pip install wolfsoftware.pushover
Here's a basic example of how to use the Pushover package:
from wolfsoftware.pushover import Pushover
# Initialize the Pushover instance
pushover = Pushover(user_key='your_user_key', api_token='your_api_token')
# Send a message
try:
response = pushover.send_message(message='Hello, this is a test message!')
print(response)
except PushoverException as e:
print(str(e))
The Pushover
class provides methods to interact with the Pushover API.
pushover = Pushover(user_key='your_user_key', api_token='your_api_token')
Sends a message through Pushover.
def send_message(message: str, title: Optional[str] = None, url: Optional[str] = None, url_title: Optional[str] = None, priority: Optional[int] = 0, sound: Optional[str] = None, device: Optional[str] = None, attachment: Optional[str] = None) -> dict:
"""
Send a message using the Pushover API.
Arguments:
message (str): The message content.
title (str, optional): The message title.
url (str, optional): A supplementary URL to show with the message.
url_title (str, optional): A title for the supplementary URL.
priority (int, optional): The priority of the message.
sound (str, optional): The name of the sound to play with the message.
device (str, optional): The device name to send the message to.
attachment (str, optional): Path to an attachment file.
Returns:
dict: The response from the Pushover API.
Raises:
PushoverException: If the request to the Pushover API fails.
"""
Sends an emergency message through Pushover.
def send_emergency_message(message: str, title: Optional[str] = None, url: Optional[str] = None, url_title: Optional[str] = None, retry: Optional[int] = 30, expire: Optional[int] = 3600, sound: Optional[str] = None, device: Optional[str] = None) -> Dict:
"""
Send an emergency message using the Pushover API.
Arguments:
message (str): The message content.
title (str, optional): The message title.
url (str, optional): A supplementary URL to show with the message.
url_title (str, optional): A title for the supplementary URL.
retry (int, optional): How often (in seconds) to retry the message.
expire (int, optional): How long (in seconds) before the message expires.
sound (str, optional): The name of the sound to play with the message.
device (str, optional): The device name to send the message to.
Returns:
dict: The response from the Pushover API.
Raises:
PushoverException: If the request to the Pushover API fails.
"""
Sends a message to a group through Pushover.
def send_group_message(message: str, group_key: str, title: Optional[str] = None, url: Optional[str] = None, url_title: Optional[str] = None, priority: Optional[int] = 0, sound: Optional[str] = None, device: Optional[str] = None, attachment: Optional[str] = None) -> Dict:
"""
Send a message to a group using the Pushover API.
Arguments:
message (str): The message content.
group_key (str): The Pushover group key.
title (str, optional): The message title.
url (str, optional): A supplementary URL to show with the message.
url_title (str, optional): A title for the supplementary URL.
priority (int, optional): The priority of the message.
sound (str, optional): The name of the sound to play with the message.
device (str, optional): The device name to send the message to.
attachment (str, optional): Path to an attachment file.
Returns:
dict: The response from the Pushover API.
Raises:
PushoverException: If the request to the Pushover API fails.
"""
Lists available sounds.
def list_sounds(self) -> dict:
"""
List the available sounds from the Pushover API.
Returns:
dict: The response from the Pushover API.
Raises:
PushoverException: If the request to the Pushover API fails.
"""