Skip to content

Development_API

lead2gold edited this page Oct 10, 2018 · 30 revisions

Development API

Apprise is very easy to use as a developer. The Apprise() object handles everything for you, meanwhile the AppriseAsset() Object allows you to stray away from some default configuration to personalize the users experience (and perhaps fit your application better):

The Apprise Object

The Apprise() object is the heart and soul of this library. To instantiate an instance of the object, one might do the following:

# Import this library
import apprise

# create an Apprise instance and assign it to variable `apobj`
apobj = apprise.Apprise()

Use the add() function to append the notification URLs we want to provide notifications for.

# Add all of the notification services by their server url.
# A sample email notification
isokay = apobj.add('mailto://myemail:[email protected]')

# add() will return a True if the URL was successfully parsed and added into
# our notification pool.  Otherwise it returns False.

# A sample pushbullet notification
isokay = apobj.add('pbul://o.gn5kj6nfhv736I7jC3cj3QLRiyhgl98b')

We can retrieve a list of the active and loaded notification services by using python's built in len() function.

# len(apobj) returns the number of notifications loaded
# the below calls this and prints it to the screen:
print("There are %d notification services loaded" % len(apobj))

You can send a notification to all of the loaded notifications services by just providing it a title and a body like so:

# Then notify these services any time you desire. The below would
# notify all of the services loaded into our Apprise object.
apobj.notify(
    title='my notification title',
    body='what a great notification service!',
)

By default, all notifications are sent as type NotifyType.INFO using the default theme. The following other types are included with this theme:

Notification Type Description
NotifyType.INFO Build Status
NotifyType.SUCCESS Build Status
NotifyType.WARNING Build Status
NotifyType.FAILURE Build Status

Should you want to send a notification using a different status, simply include it as part of your notify() call:

# Import our NotifyType
from apprise import NotifyType

# Then notify these services any time you desire. The below would
# notify all of the services loaded into our Apprise object as a WARNING.
apobj.notify(
    title='my notification title',
    body='what a great notification service!',
    notify_type=NotifyType.WARNING,
)

If you ever want to reset the object, you can use the clear() function.

# clears out all of the loaded notification services associated with our
# Apprise Object.
apobj.clear()

The Apprise Asset Object

The apprise object allows you to customize your alarms by offering it different images, different sources and different themes.

Clone this wiki locally