Skip to content

tanrbobanr/ntfy-api

Repository files navigation

ntfy-api

A Python wrapper around the ntfy API

Explore the docs »

Tests: passing Coverage: 100% License: Apache 2.0 PyPI Downloads Code style: black

Install

$ pip install ntfy-api

Usage

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}')

Tests and Coverage Policies

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.

About

A Python wrapper around the ntfy API

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published