A lightweight REST framework that wraps the Apprise Notification Library
Go to file
Chris Caron 408fe293d1
Merge pull request #3 from caronc/testing-and-coverage
Added CI which includes unit testing and code coverage
2020-01-04 16:37:44 -05:00
.github Initial commit 2019-10-27 11:12:44 -04:00
apprise_api Added testing and code coverage 2020-01-04 16:27:17 -05:00
etc prepared for docker hub 2020-01-02 23:24:07 -05:00
.coveragerc Added testing and code coverage 2020-01-04 16:27:17 -05:00
.gitignore better stateless support 2019-10-28 21:54:51 -04:00
.travis.yml Added testing and code coverage 2020-01-04 16:27:17 -05:00
dev-requirements.txt Added testing and code coverage 2020-01-04 16:27:17 -05:00
docker-compose.yml Initial commit 2019-10-27 11:12:44 -04:00
Dockerfile README references Docker Pulls 2020-01-03 12:45:37 -05:00
Dockerfile-gunicorn Initial commit 2019-10-27 11:12:44 -04:00
Dockerfile-nginx prepared for docker hub 2020-01-02 23:24:07 -05:00
LICENSE Initial commit 2019-10-27 11:12:44 -04:00
manage.py Initial commit 2019-10-27 11:12:44 -04:00
README.md Added testing and code coverage 2020-01-04 16:27:17 -05:00
requirements.txt Initial commit 2019-10-27 11:12:44 -04:00
Screenshot-1.png screenshots of GUI added to README 2019-11-29 11:30:51 -05:00
Screenshot-2.png screenshots of GUI added to README 2019-11-29 11:30:51 -05:00
tox.ini Added testing and code coverage 2020-01-04 16:27:17 -05:00

Apprise API

Take advantage of Apprise through your network with a user-friendly API.

  • Send notifications to more then 50+ services.
  • An incredibly lightweight gateway to Apprise.
  • A production ready micro-service at your disposal.

Apprise API was designed to easily fit into existing (and new) eco-systems that are looking for a simple notification solution.

Paypal Discord
Build Status CodeCov Status Docker Pulls

Screenshots

There is a small built-in Configuration Manager that can be accesed using /cfg/{KEY}:
Screenshot of GUI - Using Keys

Below is a screenshot of how you can set either a series of URL's to your {KEY}, or set your YAML and/or TEXT configuration below. Screenshot of GUI - Configuration

Installation

The following options should allow you to access the API at: http://localhost:8000/ from your browser.

Using dockerhub, you can do the following:

# Retrieve container
docker pull caronc/apprise:latest

# Start it up:
# /config is used for a persistent store, you do not have to mount
#         this if you don't intend to use it.
docker run --name apprise \
   -p 8000:8000 \
   -v /var/lib/apprise/config:/config \
   -d caronc/apprise:latest

A docker-compose.yml file is already set up to grant you an instant production ready simulated environment:

# Docker Compose
docker-compose up

API Details

Path Description
/add/{KEY} Saves Apprise Configuration (or set of URLs) to the persistent store.
Parameters
🔺 urls: Used to define one or more Apprise URL(s). Use a comma and/or space to separate one URL from the next.
🔺 config: Provide the contents of either a YAML or TEXT based Apprise configuration.
🔺 format: This field is only required if you've specified the config parameter. Used to tell the server which of the supported (Apprise) configuration types you are passing. Valid options are text and yaml.
/del/{KEY} Removes Apprise Configuration from the persistent store.
/get/{KEY} Returns the Apprise Configuration from the persistent store. This can be directly used with the Apprise CLI and/or the AppriseConfig() object (see here for details).
/notify/{KEY} Sends a notification based on the Apprise Configuration associated with the specified {KEY}.
Parameters
🔺 body: Your message body. This is the only required field.
🔺 title: Optionally define a title to go along with the body.
🔺 type: Defines the message type you want to send as. The valid options are info, success, warning, and error. If no type is specified then info is the default value used.
🔺 tag: Optionally notify only those tagged accordingly.
/notify/ Similar to the notify API identified above except this one sends a stateless notification and requires no reference to a {KEY}.
Parameters
🔺 urls: One or more URLs identifying where the notification should be sent to. If this field isn't specified then it automatically assumes the settings.APPRISE_STATELESS_URLS value or APPRISE_STATELESS_URLS environment variable.
🔺 body: Your message body. This is a required field.
🔺 title: Optionally define a title to go along with the body.
🔺 type: Defines the message type you want to send as. The valid options are info, success, warning, and error. If no type is specified then info is the default value used.

API Notes

  • {KEY} must be 1-64 alphanumeric characters in length. In addition to this, the underscore (_) and dash (-) are also accepted.
  • You must POST to URLs defined above in order for them to respond.
  • Specify the Content-Type of application/json to use the JSON support.
  • There is no authentication (or SSL encryption) required to use this API; this is by design. The intentio here to be a lightweight and fast micro-service that can be parked behind another tier that was designed to handle security.
  • There are no additional dependencies should you choose to use the optional persistent store (mounted as /config).

Environment Variables

The use of environment variables allow you to provide over-rides to default settings.

Variable Description
APPRISE_CONFIG_DIR Defines the persistent store location of all configuration files saved. By default:
- Configuration is written to the apprise_api/var/config directory when just using the Django manage runserver script.
APPRISE_STATELESS_URLS A default set of URLs to notify when using the stateless /notify reference (no reference to {KEY} variables). Use this option if you don't intend to use the persistent store at all.
SECRET_KEY A Django variable acting as a salt for most things that require security. This API uses it for the hash sequences when writing the configuration files to disk.
ALLOWED_HOSTS A list of strings representing the host/domain names that this API can serve. This is a security measure to prevent HTTP Host header attacks, which are possible even under many seemingly-safe web server configurations. By default this is set to * allowing any host. Use space to delimit more then one host.
DEBUG This defaults to False however can be set to Trueif defined with a non-zero value (such as 1).

Development Environment

The following should get you a working development environment to test with:

# Create a virtual environment in the same directory you
# cloned this repository to:
python -m venv .

# Activate it now:
. ./bin/activate

# install dependencies
pip install -r dev-requirements.txt -r requirements.txt

# Run a dev server (debug mode):
./manage.py runserver

You can now access the API at: http://localhost:8000/ from your browser.

Some other useful development notes:

# Check for any lint errors
flake8 apprise_api

# Run unit tests
pytest apprise_api

Apprise Integration

Apprise CLI Pull Example

A scenario where you want to poll the API for your configuration:

# A simple example of the Apprise CLI
# pulling down previously stored configuration
apprise -body="test message" --config=http://localhost:8000/get/{KEY}

AppriseConfig() Pull Example

Using the Apprise Library through Python, you can easily pull your saved configuration off of the API to use for future notifications.

import apprise

# Point our configuration to this API server:
config = apprise.AppriseConfig()
config.add('http://localhost:8000/get/{KEY}')

# Create our Apprise Instance
a = apprise.Apprise()

# Store our new configuration
a.add(config)

# Send a test message
a.notify('test message')

Micro-Service Integration

You can trigger the API to notify your pre-created keys like so: (using /notify/{key}):

# Send notification(s) to a {key} defined as 'my-apprise-key'
curl -X POST -d '{"body":"test message"}' \
    -H "Content-Type: application/json" \
    http://localhost:8000/notify/my-apprise-key

Here is a stateless example where no key is required (using /notify/):

# Send your notifications directly
curl -X POST -d '{"urls": "mailto://user:pass@gmail.com", "body":"test message"}' \
    -H "Content-Type: application/json" \
    http://localhost:8000/notify