notificator
Python SDK for Notificator, focused on:
- sending notifications through one unified API
- preparing multi-channel deliveries in one request
- managing admin login and account CRUD
- managing mail sender configuration
Installation
pip install notificator
Quick Start
from notificator import Notificator
client = Notificator(
name="demo_account",
token="account_token",
host="http://127.0.0.1:8000",
)
result = client.mail(
mail="user@example.com",
subject="Build finished",
body="The nightly build is green.",
recipient_name="Operator",
action_url="https://example.com/jobs/42",
action_text="Open job",
)
print(result)
Unified Multi-Channel Sending
You can prepare multiple deliveries and send them together:
from notificator import Notificator
client = Notificator(
name="demo_account",
token="account_token",
host="http://127.0.0.1:8000",
)
result = (
client
.clean()
.prepare_sms(
"+8613800000000",
template_param={"scene": "incident"},
)
.prepare_mail(
"user@example.com",
recipient_name="Operator",
action_url="https://example.com/incidents/7",
action_text="View incident",
)
.prepare_webhook(
"https://example.com/hooks/notificator",
headers={"Authorization": "Bearer your-secret"},
body={"source": "notificator-sdk"},
)
.send(
format="verification",
body={"code": "482901", "time": 10},
title="Incident opened",
)
)
print(result)
Shortcut Methods
client.mail(
"user@example.com",
subject="Welcome",
body="Your account is ready.",
recipient_name="Tom",
footer_note="Sent by Notificator",
)
SMS
client.sms(
"+8613800000000",
code="123456",
time=5,
)
Bark
client.bark(
"https://api.day.app/your-device-key",
title="Deploy finished",
body="Production is healthy.",
)
Webhook
client.webhook(
"https://example.com/hooks/notificator",
headers={"Authorization": "Bearer your-secret"},
body={"message": "Production is healthy."},
)
AdminClient
AdminClient wraps administrator APIs such as login, account CRUD, and mail sender management.
from notificator import AdminClient
admin = AdminClient(
email="admin@example.com",
password="your-password",
host="http://127.0.0.1:8000",
)
accounts = admin.get_accounts()
print(accounts)
account = admin.create_account(
name="ops_bot",
nick="Ops Bot",
)
print(account)
sender_client = admin.get_notificator("ops_bot")
sender_client.webhook(
"https://example.com/hooks/notificator",
body={"message": "Hello from Notificator"},
)
Mail sender management:
admin.create_mail_sender(
sender_id="PRIMARY",
email="noreply@example.com",
password="app-password",
smtp_server="smtp.example.com",
smtp_port=465,
enabled=True,
weight=3,
)
Defaults
- default host:
https://notice.6-79.cn - default locale:
zh-CN - default timeout:
15seconds
Errors
The SDK raises:
NotificatorErrorfor client-side validation or request failuresNotificatorAPIErrorfor structured API errors returned by the server
Example:
from notificator import NotificatorAPIError
try:
client.sms("+8613800000000", code="123456", time=5)
except NotificatorAPIError as err:
print(err.identifier)
print(err.message)
print(err.details)
Testing
Run unit tests:
python -m unittest tests/test_sdk_unit.py
Run integration tests with environment variables:
export NOTIFICATOR_TEST_HOST=http://127.0.0.1:8000
export NOTIFICATOR_TEST_ADMIN_EMAIL=admin@example.com
export NOTIFICATOR_TEST_ADMIN_PASSWORD=your-password
python -m unittest tests/test_integration.py
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
notificator-0.4.1.tar.gz
(9.9 kB
view details)
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 notificator-0.4.1.tar.gz.
File metadata
- Download URL: notificator-0.4.1.tar.gz
- Upload date:
- Size: 9.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8bbb42fee618134dd3ba5c5b7b306583a094fb86db43adb2dd25392d26c037f2
|
|
| MD5 |
3e4b5ceed0294e738e85319977676a13
|
|
| BLAKE2b-256 |
0ffc7bc907f85bcd2654ede0e460a9ca0aeebce2c5b0d0708ceba6dba0bcfdf0
|
File details
Details for the file notificator-0.4.1-py3-none-any.whl.
File metadata
- Download URL: notificator-0.4.1-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
04f2462aec06ceb0c0ec52ca521edef0a26ca535dbddf635955bc77687d76497
|
|
| MD5 |
859a84fe82d142c6f97084cc9b494afd
|
|
| BLAKE2b-256 |
fc3c2738b1e40e3d51198e3c4323c1a4567f89e637c0a4438f4c2664e6475ad5
|