Skip to main content

Fast & Free notifications for your code: Python wrapper around the ntfy.sh notifications service.

Project description

ntfy-wrapper is a free and hassle-free customizable notifier for Python. No login, no API token, no fees, no bullshit.

It's actually a simple Python wrapper around ntfy. Kudos to them ❤️

You can now send notification from your Python code and receive them on your computer through a Web App or a CLI, or on your phone with a dedicated app!

Again, all credit to ntfy.

Install

Install ntfy-wrapper (and its 2 dependencies: requests and typer) with pip:

pip install ntfy-wrapper

How to use

from ntfy_wrapper import Notifier

if __name__ == "__main__":

    ntfy = Notifier(defaults={"title": "Your Project Name"})
    # grab the topic id that was just printed here ⬆️ in order
    # to subscribe to it on the web app or cli or mobile app
    # (ntfy_wrapper will dump a config file so the same id will be
    # re-used next time. Remember to *exclude* it from version control)

    ntfy.notify("Job has been allocated, starting Model training")

    try:
        results = do_some_stuff()
        if results["metric"] > threshold:
            ntfy.notify(
                f"Great model! Its metric is {results['metric']:.3f}",
                tags="white_check_mark",  # this is the ✅ emoji
                click=results["online_run_url"],
            )
        else:
            ntfy.notify(f"Done, but not great ({results['metric']:.3f})", tags="disappointed")
    except Exception as e:
        ntfy.notify(f"Error! -> {str(e)}", priority=4, emails="you@foo.bar")

Command-line

ntfy_wrapper comes with a command-line interface called py-ntfy. It uses the great Python CLI tool Typer

  • Get help

    $ py-ntfy --help
    
    Usage: py-ntfy [OPTIONS] COMMAND [ARGS]...
    
    ╭─ Options ────────────────────────────────────────────────────────────────╮
    │ --install-completion          Install completion for the current shell.  │
    │ --show-completion             Show completion for the current shell, to  │
    │                               copy it or customize the installation.     │
    │ --help                        Show this message and exit.                │
    ╰──────────────────────────────────────────────────────────────────────────╯
    ╭─ Commands ───────────────────────────────────────────────────────────────╮
    │ add     [command sub-group] Add a new notification target or a default   │
    │         notification value. Run `$ py-ntfy add --help` for more info.    │
    │ clean   Removes the configuration file. Use --conf-path to specify a     │
    │         path to the configuration file. Use --force to skip the          │
    │         confirmation prompt.                                             │
    │ init    Initializes the configuration file. It should NOT be tracked by  │
    │         version control in order to protect the topic ID. Use            │
    │         --conf-path to specify a path to the configuration file. Use     │
    │         --force to overwrite an existing configuration file.             │
    │ remove  [command sub-group] Remove a notification target or a default    │
    │         notification value. Run `$ py-ntfy remove --help` for more info. │
    ╰──────────────────────────────────────────────────────────────────────────╯
    
    $ py-ntfy add --help
    (similar output)
    
    $ py-ntfy add default --help
    (similar output)
    
    $ py-ntfy remove --help
    (similar output)
    
  • Initialize the configuration file

    $ py-ntfy init
    🔑 Your first topic is `f8e34b7a-74a3-49e7-96fc-4d89eaf6ea6c`.
    Use it to subscribe to notifications!
    🎊 Config file created at /path/to/repo/.ntfy.conf
    
  • Add a topic or an email

    $ py-ntfy add topic some-secret-string-for-your-topic
    🎊 Topic `some-secret-string-for-your-topic` added to /path/to/repo/.ntfy.conf
    
    $ py-ntfy add email you@foo.bar
    🎊 Email you@foo.bar added to /Users/.../vict0rsch/ntfy-wrapper/.ntfy.conf
    
  • Add a default value for the .notify(...) calls

    $ py-ntfy add default key value
    🎊 Default key=value added to /Users/.../vict0rsch/ntfy-wrapper/.ntfy.conf
    
  • Remove items by simply replacing add by remove

    $ py-ntfy remove default key
    🎊 Default key=value removed from /Users/.../vict0rsch/ntfy-wrapper/.ntfy.conf
    
    $ py-ntfy remove email hello@you.com
    Email hello@you.com does not exist. Ignoring.
    
  • Change the default configuration path for any command with the option --conf-path

    • Specify a directory --conf-path path/to/conf/directory and .ntfy.conf will be created there
    • Specify a file --conf-path path/to/file.conf and that will be used as a configuration file

Todo

  • Better readme and doc
  • CLI
  • Screenshots
  • requests timeout or non-blocking

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ntfy_wrapper-0.1.0.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

ntfy_wrapper-0.1.0-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file ntfy_wrapper-0.1.0.tar.gz.

File metadata

  • Download URL: ntfy_wrapper-0.1.0.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.9.2 Darwin/21.2.0

File hashes

Hashes for ntfy_wrapper-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bb68a16ca56dc348023739fc39e59077bdc90c2b8b12e1e8aa3cee09700e8d5f
MD5 aa175bddc759979a857c4d260cfefbd4
BLAKE2b-256 70397b457667361316c18265aa82aa322f830d0c778acdf4881f174ca72f67f8

See more details on using hashes here.

File details

Details for the file ntfy_wrapper-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ntfy_wrapper-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.9.2 Darwin/21.2.0

File hashes

Hashes for ntfy_wrapper-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6bb1979855568b0254a641b7fe396cca639b5e2f5c73f04c08cb7d3cbb29ace0
MD5 fb83f777ba8316ae00db4a73785b017d
BLAKE2b-256 e3178718eec570e224b6f9550e0a8af9777b0bad41d69a4970e59eefa2ce1ee7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page