loguru.notifier

class Notifier

An object to send notifications to different providers.

Each method correspond to a notifications provider and return a Notificator parametrized according to the **kwargs passed. This Notificator should then be used through its send() method.

You should not instantiate a Notifier by yourself, use from loguru import notifier instead.

Notes

The Notifier is just a tiny wrapper around the terrific notifiers library from @liiight. Refer to its documentation for more information.

Available Notificator are:

Examples

>>> notifier.gmail(to="dest@mail.com", host="your.server.com").send("Sending an e-mail.")
>>> gmail = notifier.gmail(to="dest@gmail.com", username="you@gmail.com", password="abc123")
>>> logger.start(gmail.send, level="ERROR")
>>> notificator = notifier.slack(webhook_url="http://hooks.slack.com/xxx/yyy/zzz")
>>> notificator.send("Sending Slack message...")
>>> notificator.send("...from a Python app!")
email(**kwargs)

Return a Notificator to send messages using the Email backend.

Parameters:
  • message (str) – the content of the email message
  • to (str) – one or more email addresses to use
  • to – one or more email addresses to use
Other Parameters:
 
  • subject (str) – the subject of the email message (default to “New email from ‘notifiers’!”)
  • from (str) – the FROM address to use in the email (default to ‘docs@build-21784344-project-151228-loguru’)
  • from_ (str) – the FROM address to use in the email
  • attachments (list of str) – one or more attachments to use in the email
  • attachments (str) – one or more attachments to use in the email
  • host (str) – the host of the SMTP server (default to ‘localhost’)
  • port (int) – the port number to use (default to 25)
  • username (str) – username if relevant
  • password (str) – password if relevant
  • tls (bool) – should TLS be used (default to False)
  • ssl (bool) – should SSL be used (default to False)
  • html (bool) – should the email be parse as an HTML file (default to False)

Examples

>>> notificator = notifier.email(
...     subject="Loguru notification",
...     to="dest@gmail.com",
...     username="user@gmail.com",
...     password="UserPassword",
...     host="smtp.gmail.com",
...     port=465,
...     ssl=True,
... )
>>> notificator.send('Notify!')
gitter(**kwargs)

Return a Notificator to send messages using the Gitter backend.

Parameters:
  • message (str) – Body of the message
  • token (str) – access token
  • room_id (str) – ID of the room to send the notification to

Examples

>>> notificator = notifier.gitter(
...     token="qdp4k378twu994ss3940c35x87jbul3p6l6e32f0",
...     room_id="1935i60h67870wi4p9q0yc81",
... )
>>> notificator.send('Notify!')
gmail(**kwargs)

Return a Notificator to send messages using the Gmail backend.

Parameters:
  • message (str) – the content of the email message
  • to (str) – one or more email addresses to use
  • to – one or more email addresses to use
Other Parameters:
 
  • subject (str) – the subject of the email message (default to “New email from ‘notifiers’!”)
  • from (str) – the FROM address to use in the email (default to ‘docs@build-21784344-project-151228-loguru’)
  • from_ (str) – the FROM address to use in the email
  • attachments (list of str) – one or more attachments to use in the email
  • attachments (str) – one or more attachments to use in the email
  • host (str) – the host of the SMTP server (default to ‘smtp.gmail.com’)
  • port (int) – the port number to use (default to 587)
  • username (str) – username if relevant
  • password (str) – password if relevant
  • tls (bool) – should TLS be used (default to True)
  • ssl (bool) – should SSL be used (default to False)
  • html (bool) – should the email be parse as an HTML file (default to False)

Examples

>>> notificator = notifier.gmail(
...     subject="Loguru notification",
...     to="dest@gmail.com",
...     username="user@gmail.com",
...     password="UserPassword",
... )
>>> notificator.send('Notify!')
hipchat(**kwargs)

Return a Notificator to send messages using the Hipchat backend.

Parameters:
  • room (str) – The id or url encoded name of the room
  • user (str) – The id, email address, or mention name (beginning with an ‘@’) of the user to send a message to.
  • message (str) – The message body
  • token (str) – User token
  • id (str) – An id that will help HipChat recognise the same card when it is sent multiple times
  • team_server (str) – An alternate team server. Example: ‘https://hipchat.corp-domain.com
  • group (str) – HipChat group name
Other Parameters:
 
  • notify (bool) – Whether this message should trigger a user notification (change the tab color, play a sound, notify mobile phones, etc). Each recipient’s notification preferences are taken into account.
  • message_format ({‘text’, ‘html’}) – Determines how the message is treated by our server and rendered inside HipChat applications
  • from (str) – A label to be shown in addition to the sender’s name
  • color ({‘yellow’, ‘green’, ‘red’, ‘purple’, ‘gray’, ‘random’}) – Background color for message
  • attach_to (str) – The message id to to attach this notification to
  • card (dict) –
    • style ({‘file’, ‘image’, ‘application’, ‘link’, ‘media’}) - Type of the card
    • description (str)
    • description (dict)
      • value (str)
      • format ({‘text’, ‘html’}) - Determines how the message is treated by our server and rendered inside HipChat applications
    • format ({‘compact’, ‘medium’}) - Application cards can be compact (1 to 2 lines) or medium (1 to 5 lines)
    • url (str) - The url where the card will open
    • title (str) - The title of the card
    • thumbnail (dict)
      • url (str) - The thumbnail url
      • width (int) - The original width of the image
      • url@2x (str) - The thumbnail url in retina
      • height (int) - The original height of the image
    • activity (dict)
      • html (str) - Html for the activity to show in one line a summary of the action that happened
      • icon (str) - The url where the icon is
      • icon (dict)
        • url (str) - The url where the icon is
        • url@2x (str) - The url for the icon in retina
    • attributes (list of dict) - List of attributes to show below the card
      • value (dict)
        • url (str) - Url to be opened when a user clicks on the label
        • style ({‘lozenge-success’, ‘lozenge-error’, ‘lozenge-current’, ‘lozenge-complete’, ‘lozenge-moved’, ‘lozenge’}) - AUI Integrations for now supporting only lozenges
        • label (str) - The text representation of the value
        • icon (str) - The url where the icon is
        • icon (dict)
          • url (str) - The url where the icon is
          • url@2x (str) - The url for the icon in retina
      • label (str) - Attribute label
  • icon (str) – The url where the icon is
  • icon (dict) –
    • url (str) - The url where the icon is
    • url@2x (str) - The url for the icon in retina

Examples

>>> notificator = notifier.hipchat(
...     token="2YotnFZFEjr1zCsicMWpAA",
...     room=7242,
...     group="namegroup",
...     id="6492f0a6-9fa0-48cd-a3dc-2b19a0036e99",
... )
>>> notificator.send('Notify!')
join(**kwargs)

Return a Notificator to send messages using the Join backend.

Parameters:
  • message (str) – usually used as a Tasker or EventGhost command. Can also be used with URLs and Files to add a description for those elements
  • apikey (str) – user API key
Other Parameters:
 
  • deviceId (str) – The device ID or group ID of the device you want to send the message to (default to ‘group.all’)
  • deviceIds (list of str) – A comma separated list of device IDs you want to send the push to
  • deviceIds (str) – A comma separated list of device IDs you want to send the push to
  • deviceNames (list of str) – A comma separated list of device names you want to send the push to
  • deviceNames (str) – A comma separated list of device names you want to send the push to
  • url (str) – A URL you want to open on the device. If a notification is created with this push, this will make clicking the notification open this URL
  • clipboard (str) – some text you want to set on the receiving device’s clipboard
  • file (str) – a publicly accessible URL of a file
  • smsnumber (str) – phone number to send an SMS to
  • smstext (str) – some text to send in an SMS
  • callnumber (str) – number to call to
  • interruptionFilter (int) – set interruption filter mode
  • mmsfile (str) – publicly accessible mms file url
  • mediaVolume (int) – set device media volume
  • ringVolume (str) – set device ring volume
  • alarmVolume (str) – set device alarm volume
  • wallpaper (str) – a publicly accessible URL of an image file
  • find (bool) – set to true to make your device ring loudly
  • title (str) – If used, will always create a notification on the receiving device with this as the title and text as the notification’s text
  • icon (str) – notification’s icon URL
  • smallicon (str) – Status Bar Icon URL
  • priority (int) – control how your notification is displayed
  • group (str) – allows you to join notifications in different groups
  • image (str) – Notification image URL

Examples

>>> notificator = notifier.join(
...     apikey="ar0pg953181y3lc75cl8n432x6j591ro",
... )
>>> notificator.send('Notify!')
mailgun(**kwargs)

Return a Notificator to send messages using the Mailgun backend.

Parameters:
  • api_key (str) – User’s API key
  • message (str) – Body of the message. (text version)
  • html (str) – Body of the message. (HTML version)
  • to (str) – Email address of the recipient(s). Example: “Bob <bob@host.com>”.
  • to – Email address of the recipient(s). Example: “Bob <bob@host.com>”.
  • from (str) – Email address for From header
  • from_ (str) – Email address for From header
  • domain (str) – MailGun’s domain to use
Other Parameters:
 
  • cc (list of str) – Email address of the recipient(s). Example: “Bob <bob@host.com>”.
  • cc (str) – Email address of the recipient(s). Example: “Bob <bob@host.com>”.
  • bcc (list of str) – Email address of the recipient(s). Example: “Bob <bob@host.com>”.
  • bcc (str) – Email address of the recipient(s). Example: “Bob <bob@host.com>”.
  • subject (str) – Message subject
  • attachment (list of str) – File attachment
  • attachment (str) – File attachment
  • inline (list of str) – Attachment with inline disposition. Can be used to send inline images
  • inline (str) – Attachment with inline disposition. Can be used to send inline images
  • tag (list of str) – Tag string
  • tag (str) – Tag string
  • dkim (bool) – Enables/disables DKIM signatures on per-message basis
  • deliverytime (str) – Desired time of delivery. Note: Messages can be scheduled for a maximum of 3 days in the future.
  • testmode (bool) – Enables sending in test mode.
  • tracking (bool) – Toggles tracking on a per-message basis
  • tracking_clicks ({True, False, ‘htmlonly’}) – Toggles clicks tracking on a per-message basis. Has higher priority than domain-level setting. Pass yes, no or htmlonly.
  • tracking_opens (bool) – Toggles opens tracking on a per-message basis. Has higher priority than domain-level setting
  • require_tls (bool) – If set to True this requires the message only be sent over a TLS connection. If a TLS connection can not be established, Mailgun will not deliver the message.If set to False, Mailgun will still try and upgrade the connection, but if Mailgun can not, the message will be delivered over a plaintext SMTP connection.
  • skip_verification (bool) – If set to True, the certificate and hostname will not be verified when trying to establish a TLS connection and Mailgun will accept any certificate during delivery. If set to False, Mailgun will verify the certificate and hostname. If either one can not be verified, a TLS connection will not be established.
  • headers (dict) – Any other header to add
  • data (dict) – attach a custom JSON data to the message

Examples

>>> notificator = notifier.mailgun(
...     subject="Loguru notification",
...     from_="user@gmail.com",
...     to="dest@gmail.com",
...     api_key="35a9tpnt1499o17eb14770iv2qm3775y-9258cqsa-u37b84u9",
...     domain="sandbox50v50d43fh261308q90f654p13364076.mailgun.org",
... )
>>> notificator.send('Notify!')
pagerduty(**kwargs)

Return a Notificator to send messages using the Pagerduty backend.

Parameters:
  • message (str) – A brief text summary of the event, used to generate the summaries/titles of any associated alerts
  • routing_key (str) – The GUID of one of your Events API V2 integrations. This is the “Integration Key” listed on the Events API V2 integration’s detail page
  • event_action ({'trigger', 'acknowledge', 'resolve'}) – The type of event
  • source (str) – The unique location of the affected system, preferably a hostname or FQDN
  • severity ({'critical', 'error', 'warning', 'info'}) – The perceived severity of the status the event is describing with respect to the affected system
Other Parameters:
 
  • dedup_key (str) – Deduplication key for correlating triggers and resolves
  • timestamp (str) – The time at which the emitting tool detected or generated the event in ISO 8601
  • component (str) – Component of the source machine that is responsible for the event
  • group (str) – Logical grouping of components of a service
  • class (str) – The class/type of the event
  • custom_details (dict) – Additional details about the event and affected system
  • images (list of dict) –
    • src (str) - The source of the image being attached to the incident. This image must be served via HTTPS.
    • href (str) - Optional URL; makes the image a clickable link
    • alt (str) - Optional alternative text for the image
  • links (list of dict) –
    • href (str) - URL of the link to be attached
    • text (str) - Plain text that describes the purpose of the link, and can be used as the link’s text
popcornnotify(**kwargs)

Return a Notificator to send messages using the Popcornnotify backend.

Parameters:
  • message (str) – The message to send
  • api_key (str) – The API key
  • recipients (str) – The recipient email address or phone number. Or an array of email addresses and phone numbers
  • recipients – The recipient email address or phone number. Or an array of email addresses and phone numbers
Other Parameters:
 

subject (str) – The subject of the email. It will not be included in text messages.

Examples

>>> notificator = notifier.popcornnotify(
...     recipients="dest@gmail.com",
...     api_key="abc123456",
... )
>>> notificator.send('Notify!')
pushbullet(**kwargs)

Return a Notificator to send messages using the Pushbullet backend.

Parameters:
  • message (str) – Body of the push
  • token (str) – API access token
Other Parameters:
 
  • title (str) – Title of the push
  • type ({‘note’, ‘link’}) – Type of the push, one of “note” or “link” (default to ‘note’)
  • type_ ({‘note’, ‘link’}) – Type of the push, one of “note” or “link”
  • url (str) – URL field, used for type=”link” pushes
  • source_device_iden (str) – Device iden of the sending device
  • device_iden (str) – Device iden of the target device, if sending to a single device
  • client_iden (str) – Client iden of the target client, sends a push to all users who have granted access to this client. The current user must own this client
  • channel_tag (str) – Channel tag of the target channel, sends a push to all people who are subscribed to this channel. The current user must own this channel.
  • email (str) – Email address to send the push to. If there is a pushbullet user with this address, they get a push, otherwise they get an email
  • guid (str) – Unique identifier set by the client, used to identify a push in case you receive it from /v2/everything before the call to /v2/pushes has completed. This should be a unique value. Pushes with guid set are mostly idempotent, meaning that sending another push with the same guid is unlikely to create another push (it will return the previously created push).

Examples

>>> notificator = notifier.pushbullet(
...     token="g.iwdgad0l12pu11p3mvzpada4v8fjadfh",
...     email="user@gmail.com",
... )
>>> notificator.send('Notify!')
pushover(**kwargs)

Return a Notificator to send messages using the Pushover backend.

Parameters:
  • user (str) – the user/group key (not e-mail address) of your user (or you)
  • user – the user/group key (not e-mail address) of your user (or you)
  • message (str) – your message
  • token (str) – your application’s API token
Other Parameters:
 
  • title (str) – your message’s title, otherwise your app’s name is used
  • device (list of str) – your user’s device name to send the message directly to that device
  • device (str) – your user’s device name to send the message directly to that device
  • priority (int) – notification priority
  • url (str) – a supplementary URL to show with your message
  • url_title (str) – a title for your supplementary URL, otherwise just the URL is shown
  • sound (str) – the name of one of the sounds supported by device clients to override the user’s default sound choice. See sounds resource
  • timestamp (int | str) – a Unix timestamp of your message’s date and time to display to the user, rather than the time your message is received by our API
  • retry (int) – how often (in seconds) the Pushover servers will send the same notification to the user. priority must be set to 2
  • expire (int) – how many seconds your notification will continue to be retried for. priority must be set to 2
  • callback (str) – a publicly-accessible URL that our servers will send a request to when the user has acknowledged your notification. priority must be set to 2
  • html (bool) – enable HTML formatting
  • attachment (str) – an image attachment to send with the message

Examples

>>> notificator = notifier.pushover(
...     token="chlnisznqlttipch5e5zu3gmxo5qp7",
...     user="srpzuyopidaythfq3u1tj2fmee3ke0",
... )
>>> notificator.send('Notify!')
simplepush(**kwargs)

Return a Notificator to send messages using the Simplepush backend.

Parameters:
  • key (str) – your user key
  • message (str) – your message
Other Parameters:
 
  • title (str) – message title
  • event (str) – Event ID

Examples

>>> notificator = notifier.simplepush(
...     key="HuxgBB",
... )
>>> notificator.send('Notify!')
slack(**kwargs)

Return a Notificator to send messages using the Slack backend.

Parameters:
Other Parameters:
 
  • icon_url (str) – override bot icon with image URL
  • icon_emoji (str) – override bot icon with emoji name.
  • username (str) – override the displayed bot name
  • channel (str) – override default channel or private message
  • unfurl_links (bool) – avoid automatic attachment creation from URLs
  • attachments (list of dict) –
    • title (str) - Attachment title
    • author_name (str) - Small text used to display the author’s name
    • author_link (str) - A valid URL that will hyperlink the author_name text mentioned above. Will only work if author_name is present
    • author_icon (str) - A valid URL that displays a small 16x16px image to the left of the author_name text. Will only work if author_name is present
    • title_link (str) - Attachment title URL
    • image_url (str) - Image URL
    • thumb_url (str) - Thumbnail URL
    • footer (str) - Footer text
    • footer_icon (str) - Footer icon URL
    • ts (int | str) - Provided timestamp (epoch)
    • fallback (str) - A plain-text summary of the attachment. This text will be used in clients that don’t show formatted text (eg. IRC, mobile notifications) and should not contain any markup.
    • text (str) - Optional text that should appear within the attachment
    • pretext (str) - Optional text that should appear above the formatted data
    • color (str) - Can either be one of ‘good’, ‘warning’, ‘danger’, or any hex color code
    • fields (list of dict) - Fields are displayed in a table on the message
      • title (str) - Required Field Title
      • value (str) - Text value of the field. May contain standard message markup and must be escaped as normal. May be multi-line
      • short (bool) - Optional flag indicating whether the value is short enough to be displayed side-by-side with other values

Examples

>>> notificator = notifier.slack(
...     webhook_url="https://hooks.slack.com/services/T5WDFU/RPB8IF/UG93Wp9mgcae1V",
... )
>>> notificator.send('Notify!')
statuspage(**kwargs)

Return a Notificator to send messages using the Statuspage backend.

Parameters:
  • message (str) – The name of the incident
  • api_key (str) – OAuth2 token
  • page_id (str) – Page ID
Other Parameters:
 
  • status ({‘investigating’, ‘identified’, ‘monitoring’, ‘resolved’, ‘scheduled’, ‘in_progress’, ‘verifying’, ‘completed’}) – Status of the incident
  • body (str) – The initial message, created as the first incident update
  • wants_twitter_update (bool) – Post the new incident to twitter
  • impact_override ({‘none’, ‘minor’, ‘major’, ‘critical’}) – Override calculated impact value
  • component_ids (list of str) – List of components whose subscribers should be notified (only applicable for pages with component subscriptions enabled)
  • deliver_notifications (bool) – Control whether notifications should be delivered for the initial incident update
  • scheduled_for (str) – Time the scheduled maintenance should begin
  • scheduled_until (str) – Time the scheduled maintenance should end
  • scheduled_remind_prior (bool) – Remind subscribers 60 minutes before scheduled start
  • scheduled_auto_in_progress (bool) – Automatically transition incident to ‘In Progress’ at start
  • scheduled_auto_completed (bool) – Automatically transition incident to ‘Completed’ at end
  • backfilled (bool) – Create an historical incident
  • backfill_date (str) – Date of incident in YYYY-MM-DD format

Examples

>>> notificator = notifier.statuspage(
...     api_key="fc8f938z-9250-2buh-18r2-852312zi1y42",
...     page_id="xc4tcptf84pv",
... )
>>> notificator.send('Notify!')
telegram(**kwargs)

Return a Notificator to send messages using the Telegram backend.

Parameters:
  • message (str) – Text of the message to be sent
  • token (str) – Bot token
  • chat_id (int) – Unique identifier for the target chat or username of the target channel (in the format @channelusername)
  • chat_id – Unique identifier for the target chat or username of the target channel (in the format @channelusername)
Other Parameters:
 
  • parse_mode ({‘markdown’, ‘html’}) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot’s message.
  • disable_web_page_preview (bool) – Disables link previews for links in this message
  • disable_notification (bool) – Sends the message silently. Users will receive a notification with no sound.
  • reply_to_message_id (int) – If the message is a reply, ID of the original message

Examples

>>> notificator = notifier.telegram(
...     token="110201543:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw",
...     chat_id=94725518,
... )
>>> notificator.send('Notify!')
twilio(**kwargs)

Return a Notificator to send messages using the Twilio backend.

Parameters:
  • message (str) – The text body of the message. Up to 1,600 characters long.
  • account_sid (str) – The unique id of the Account that sent this message.
  • auth_token (str) – The user’s auth token
  • to (str) – The recipient of the message, in E.164 format
  • from (str) – Twilio phone number or the alphanumeric sender ID used
  • from_ (str) – Twilio phone number or the alphanumeric sender ID used
  • messaging_service_id (str) – The unique id of the Messaging Service used with the message
  • media_url (str) – The URL of the media you wish to send out with the message
Other Parameters:
 
  • status_callback (str) – A URL where Twilio will POST each time your message status changes
  • application_sid (str) – Twilio will POST MessageSid as well as MessageStatus=sent or MessageStatus=failed to the URL in the MessageStatusCallback property of this Application
  • max_price (float) – The total maximum price up to the fourth decimal (0.0001) in US dollars acceptable for the message to be delivered
  • provide_feedback (bool) – Set this value to true if you are sending messages that have a trackable user action and you intend to confirm delivery of the message using the Message Feedback API
  • validity_period (int) – The number of seconds that the message can remain in a Twilio queue

Examples

>>> notificator = notifier.twilio(
...     to="+15558675310",
...     account_sid="ACw7ly6d43h6752ld32o05c1p79u7br452",
...     auth_token="n780tw69475k8w1h3z996485rccn9i25",
... )
>>> notificator.send('Notify!')
zulip(**kwargs)

Return a Notificator to send messages using the Zulip backend.

Parameters:
  • message (str) – Message content
  • email (str) – User email
  • api_key (str) – User API Key
  • to (str) – Target of the message
  • domain (str) – Zulip cloud domain
  • server (str) – Zulip server URL. Example: https://myzulip.server.com
Other Parameters:
 
  • type ({‘stream’, ‘private’}) – Type of message to send (default to ‘stream’)
  • type_ ({‘stream’, ‘private’}) – Type of message to send
  • subject (str) – Title of the stream message. Required when using stream.

Examples

>>> notificator = notifier.zulip(
...     email="user@zulip.com",
...     to="dest@zulip.com",
...     server="https://yourZulipDomain.zulipchat.com",
...     api_key="a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5",
... )
>>> notificator.send('Notify!')
class Notificator[source]

An object to send notifications to an internally configured provider.

You should not instantiate a Notificator by yourself, use the Notifier to configure the requested notification provider instead.

Variables:
  • provider (Provider) – The provider object internally used to send notifications, created thanks to the notifiers library.
  • parameters (dict) – The parameters used to configure the Provider.
send(message, **kwargs)[source]

Send a notification through the internally configured provider.

Parameters:
  • message (str) – The message to send to the configured notifier.
  • **kwargs – Additional parameters to override or extend configured ones before sending the message.
Returns:

The response from the notifiers provider.