Python SDK for NotifyOn notification service
Project description
NotifyOn Python SDK
Python SDK for NotifyOn - Real-time notifications for long-running agent tasks.
Installation
pip install notifyon
Quick Start
from notifyon import NotifyOn
# Initialize the client
notifyon = NotifyOn(api_key="your_api_key")
# Send a notification
notifyon.send("user_123")
Configuration
Using Environment Variables
Set your API key as an environment variable:
export NOTIFYON_API_KEY=your_api_key
Then initialize without passing the key:
from notifyon import NotifyOn
notifyon = NotifyOn()
notifyon.send("user_123")
Using Context Manager
The SDK supports context manager for automatic cleanup:
from notifyon import NotifyOn
with NotifyOn(api_key="your_api_key") as notifyon:
notifyon.send("user_123", "Task complete")
API Reference
NotifyOn Class
__init__(api_key=None, api_url=None)
Initialize the NotifyOn client.
Parameters:
api_key(str, optional): Your NotifyOn API key. If not provided, looks forNOTIFYON_API_KEYenvironment variable.api_url(str, optional): Custom API URL for self-hosted or development environments.
send(user_id, message=None)
Send a notification to a user.
Parameters:
user_id(str): The external user ID to notify.message(str, optional): Custom message for the notification.
Returns:
dict: Response from the API
Raises:
NotifyOnError: If there's an API errorConfigurationError: If API key is missingValueError: If user_id is not provided
Error Handling
from notifyon import NotifyOn, NotifyOnError
try:
notifyon = NotifyOn(api_key="your_api_key")
notifyon.send("user_123", "Processing complete")
except NotifyOnError as e:
print(f"Failed to send notification: {e}")
Examples
Basic Usage
from notifyon import NotifyOn
import os
# Using environment variable
notifyon = NotifyOn()
# Notify when a long task completes
def process_data(user_id):
# Your long-running task here
result = perform_analysis()
# Notify the user
notifyon.send(user_id, "Analysis complete")
return result
With Error Handling
from notifyon import NotifyOn, NotifyOnError
notifyon = NotifyOn(api_key="your_api_key")
def safe_notify(user_id, message):
try:
notifyon.send(user_id, message)
print(f"Notification sent to {user_id}")
except NotifyOnError as e:
print(f"Failed to notify {user_id}: {e}")
# Handle the error appropriately
Batch Processing
from notifyon import NotifyOn
notifyon = NotifyOn(api_key="your_api_key")
def process_batch(user_ids, task):
results = []
for user_id in user_ids:
# Process task for each user
result = task(user_id)
results.append(result)
# Notify each user when their task is done
notifyon.send(user_id, f"Your {task.__name__} is complete")
return results
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file notifyon-0.1.0.tar.gz.
File metadata
- Download URL: notifyon-0.1.0.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
101a6851096114f2a4e3af31373c494eab1e881b4e2d2f4d50608307099e9b54
|
|
| MD5 |
f84423c36cc54117191f277e045f9eea
|
|
| BLAKE2b-256 |
46601cbcf7e13c0bd5a0aa51437935fc0a17504efb40c0111c2b6f3a4ec9ea54
|
File details
Details for the file notifyon-0.1.0-py3-none-any.whl.
File metadata
- Download URL: notifyon-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2a6d41298f0887ae84aa072cf9395093662e8349f3aa575f05874712ed2da3aa
|
|
| MD5 |
4c9c412360f33c42f777ea508ce79a0b
|
|
| BLAKE2b-256 |
330a93ae4fa45e79d1c2245f2f47dd027ccbaf0055f1fb6a3696db3a0830a702
|