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
Release files for notifyon 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| notifyon-0.1.0.tar.gz | 4.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| notifyon-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.1 kB
Release files / notifyon-0.1.0.tar.gz
| Download URL | notifyon-0.1.0.tar.gz |
|---|---|
| Size | 4.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
101a6851096114f2a4e3af31373c494eab1e881b4e2d2f4d50608307099e9b54
|
|
BLAKE2b-256 checksum How to use checksums |
46601cbcf7e13c0bd5a0aa51437935fc0a17504efb40c0111c2b6f3a4ec9ea54
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / notifyon-0.1.0-py3-none-any.whl
| Download URL | notifyon-0.1.0-py3-none-any.whl |
|---|---|
| Size | 5.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2a6d41298f0887ae84aa072cf9395093662e8349f3aa575f05874712ed2da3aa
|
|
BLAKE2b-256 checksum How to use checksums |
330a93ae4fa45e79d1c2245f2f47dd027ccbaf0055f1fb6a3696db3a0830a702
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|