Skip to content

Instantly share code, notes, and snippets.

@caronc
Created December 30, 2020 22:20
Show Gist options
  • Save caronc/be9f0b6fb35f272e30087f48233576cf to your computer and use it in GitHub Desktop.
Save caronc/be9f0b6fb35f272e30087f48233576cf to your computer and use it in GitHub Desktop.
A simple Apprise Example (for Python v3+) leveraging async/await
# Under the hood, the NotifyBase class becomes AsyncNotifyBase() when Python 3 is detected
# see https://github.com/caronc/apprise/blob/ef2057c10aabd8119796338f41cd7970daeaacf9/apprise/py3compat/asyncio.py#L96
# The big difference is this introduces a new function called async_notify()
# which is called under the hood when you call Apprise().notify().
import apprise
import asyncio
# Add say... 2 entries:
aobj = apprise.Apprise()
aobj.add('mailto://user:[email protected]')
aobj.add('kodi://media.localhost')
# Async Notification (notifies both services above)
aobj.notify("Async notification")
# However, if you want to leverage the async calls directly, you can
# directly access them. The below outputs 2 (because we loaded 2 services)
print(len(aobj))
async def main():
"""
Directly call the async_notify() object
"""
await aobj[0].async_notify("Async notification")
asyncio.run(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment