Advanced Usage
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 -- like notify(), this returns an # AppriseResult, so capture it if you care whether delivery succeeded result = await apobj.async_notify( title='Async Test', body='This was sent asynchronously', )
if not result: print("Delivery failed:", result.status.name)
asyncio.run(main())See Notification Results for everything result can tell you (per-service detail, timing, captured logs, and more).
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")URLs and Their Fields
Section titled “URLs and Their Fields”A notification object can give its URL back as separate fields, named after the tokens and arguments in details(), the same names the URL Builder shows. fields_to_url() puts fields back together into a URL. This lets a program show a URL as a form and turn the form back into a URL.
import apprisefrom apprise.fields import fields_to_url
obj = apprise.Apprise.instantiate( "mailtos://user:secret@example.com?to=a@example.com&smtp=smtp.example.com")
# The URL as fields, and the same fields with the secrets hiddenfields = obj.url_fields()hidden = obj.url_fields(privacy=True)
# fields["targets"] == ["a@example.com"]# fields["smtp"] == "smtp.example.com"# hidden["password"] == "****"
# The fields make the same URL againurl = fields_to_url(fields)assert apprise.Apprise.instantiate(url).url() == obj.url()- An alias such as
tois folded into the entry it stands for, heretargets. - Key/value options (
+header,-param,:key) come back as maps, such asheaders,paramsandpayload. - Values come back as the type
details()gives them: lists, numbers andTrue/False. - The hidden fields mask every entry
details()marks as private. fields_to_url()returnsNonewhen the schema is unknown, a field name isn’t one the service lists, or the service refuses the values. A host holding/,?,#,@or:(other than an IPv6 address) and a port that isn’t a whole number from 1 to 65535 are refused too, so one field can never change another part of the URL.apprise.fields.parse_fields(url)reads the fields of a URL its service wouldn’t load yet, such asmailto://with nothing after it, so a form can show what was typed so far.
Handling Configuration Errors
Section titled “Handling Configuration Errors”Apprise raises AppriseImproperlyConfigured when a library call receives missing, invalid, or conflicting settings. Catch it when your application needs to report a configuration problem:
from apprise import AppriseAssetfrom apprise.exception import AppriseImproperlyConfigured
try: asset = AppriseAsset(service_timeout=-1)except AppriseImproperlyConfigured as error: print(f"Invalid Apprise settings: {error}")Existing handlers for TypeError, ValueError, or AttributeError continue to work. New code should catch AppriseImproperlyConfigured so configuration problems are easier to identify.
All Apprise-specific exceptions inherit from AppriseException, which provides one catch-all when your application does not need to distinguish the cause. Disk failures reported as AppriseDiskIOError can also be caught as OSError. Plugin-specific failures based on ApprisePluginException can be handled together when their individual details are not needed.
notify() and async_notify() report these problems in their return value instead of raising exceptions.
A service that fails before preparing its message gets its own FAILURE entry, just like one that fails while sending. Other services still run, escalation continues, and optional services remain optional. A call with mixed outcomes reports PARTIAL.
If Apprise cannot use the message, the whole call reports FAILURE with no service entries and sends nothing. An invalid timeout= value is the only case these methods still raise for.
Proxy Support
Section titled “Proxy Support”Apprise sends every notification over requests, which honours the standard HTTP_PROXY, HTTPS_PROXY, and NO_PROXY environment variables automatically. No Apprise-specific configuration is required. Set the variable before your process starts (or export it in the environment Apprise runs under) and every outbound request routes through the proxy:
export HTTPS_PROXY="http://127.0.0.1:3128"export HTTP_PROXY="http://127.0.0.1:3128"
python3 my_script.pyIf you only want Apprise to proxy (and not the rest of your application), scope the variable to the subprocess or environment that runs Apprise rather than exporting it globally. Set it inline for a single command, for example, or in a systemd unit’s Environment= directive for a long-running service.
NO_PROXY is also honoured, letting you exempt specific hosts:
export HTTPS_PROXY="http://127.0.0.1:3128"export NO_PROXY="localhost,127.0.0.1,internal.example.com"Questions or Feedback?
Technical Issues
Having trouble with the code? Open an issue on GitHub: