Advanced Usage
Ce contenu n’est pas encore disponible dans votre langue.
Asynchronous Notifications
Section titled “Asynchronous Notifications”If you are running inside an asyncio event loop, you can use async_notify() to send notifications without blocking.
import asyncioimport apprise
async def main(): apobj = apprise.Apprise() apobj.add('mailto://user:pass@example.com')
# Await the notification delivery await apobj.async_notify( title='Async Test', body='This was sent asynchronously', )
asyncio.run(main())Serialization (Pickle)
Section titled “Serialization (Pickle)”Apprise objects can be serialized (pickled). This allows you to configure an Apprise object once, save it to disk (or a database), and reload it later with all services configured.
import appriseimport pickle
# 1. Setupapobj = apprise.Apprise()apobj.add("json://localhost")
# 2. Serializeserialized_data = pickle.dumps(apobj)
# ... later in your code ...
# 3. Restorerestored_obj = pickle.loads(serialized_data)restored_obj.notify("I am back!")Low-Level: The Apprise Notification Object
Section titled “Low-Level: The Apprise Notification Object”When you call Apprise.notify(), it handles tagging, configuration, and logging for you. If you need to bypass this and interact directly with a specific notification object:
import apprise
# Instantiate a single notification object directly# (Bypassing the Apprise() manager)obj = apprise.Apprise.instantiate('glib://')
# Send raw contentobj.send( body="Raw message", title="Raw title")