A Python wrapper around the ntfy API
$ pip install ntfy-api
This package supports sending and receiving messages. Here is an example of how to send a message:
import ntfy_api
# create a client
client = ntfy_api.NtfyClient(
base_url="https://www.example.com",
credentials=ntfy_api.Credentials(...), # if authorization is needed
)
# create a message
msg = Message(
topic="my-topic",
message="**Hello World**",
title="Super Cool Message",
priority=Priority.urgent, # or `5`
tags=[Tag._100], # or `["100"]`
markdown=True,
delay="10m",
actions=[
ViewAction(label="GOOGLE", url="https://google.com"),
BroadcastAction(
label="Take picture",
extras={"cmd": "pic", "camera": "front"}
)
],
click="https://youtube.com",
attach="https://docs.ntfy.sh/static/img/ntfy.png",
filename="ntfy_api.png",
icon="https://ntfy.sh/_next/static/media/logo.077f6a13.svg"
)
# send message
client.publish(msg)
For polling or subscribing:
# poll messages
for msg in client.poll("my-topic"):
print('>> Message received <<')
print(f'Title: {msg.title}')
print(f'Message: {msg.message}')
print(f'Click: {msg.click}')
if msg.attachment:
print(f'Attachments: {msg.attachment}')
# subscribe
with client.subscribe("my-topic") as subscription:
msg = subscription.messages.get()
print('>> Message received <<')
print(f'Title: {msg.title}')
print(f'Message: {msg.message}')
print(f'Click: {msg.click}')
if msg.attachment:
print(f'Attachments: {msg.attachment}')
This project does not have coverage reports or test results available. As part of the release process, full (100%) code coverage is required, and all tests must pass for all supported versions on all major operating systems.