Skip to main content

Notification Triggers for Python

Project description

Notipyer

Notification Triggers for Python

Send async email and slack notifications via Python. Get updates/crashlogs from your scripts with ease.

Installation

python -m venv env
source env/bin/activate
pip install notipyer

Email Notifications

Notipyer currently supports Gmail accounts as senders. To allow the library to use your Gmail account, make the following changes:

  1. Turn on 2-Step authentication. Ref
  2. Create an app password. Ref
  3. While creating an app password, select app as "Other (Custom name)" and enter a name of your choice.
  4. Use the password obtained from app password for the configuration step below.
  5. More information can be obtained on the wiki page here

Configuration

from notipyer.email_notify import set_email_config

SENDER_EMAIL = 'myemail@gmail.com'
SENDER_PASS = 'my_app_password'
SENDER_NAME = 'my name'
set_email_config(SENDER_EMAIL, SENDER_PASS, SENDER_NAME)

Sending Email

from notipyer.email_notify import send_email

subject = 'My Email Subject'
body = 'My Email Body'
reply_to_recipient = 'reply-to-email@domain.com' # Can be None
to_recipients = ['to-email-1@domain.com', 'toemail2@domain.com'] # Can be None
cc_recipients = ['cc-email-1@domain.com', 'cc-email-2@domain.com'] # Can be None
bcc_recipients = ['bcc-email-1@domain.com', 'bcc-email-2@domain.com'] # Can be None
attachment_path = 'path_to_my_file' # Can be None
html = """\
<html>
  <head></head>
  <body>
    <p>Hi!<br>
       How are you?<br>
    </p>
  </body>
</html>
""" # Can be None
is_async = True # Sent as an async email only if this parameter is True

send_email(subject, body, to_recipients, reply_to_recipient, cc_recipients, bcc_recipients, attachment_path, html_text, is_async)

Slack Notifications

Notipyer currently supports running a single workplace install only.

For setting up token keys for using slack notifications, follow the wiki page here

Configuration

from notipyer.slack_notify import set_slack_token_config

# Follow the wiki for getting the bot token
BOT_TOKEN = 'xoxb-12345678990123-1234567890123-abcdefghijklmnopqrstuvwx' 
set_slack_token_config(BOT_TOKEN)

Sending Message

from notipyer.slack_notify import send_message

# the bot should be added to the channel
channel = 'my-channel-name'
message = 'my-message'

set_slack_token_config(SLACK_TOKEN)
send_message(channel, message)

Contact

Chirag Jain

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

notipyer-0.3.5.tar.gz (16.6 kB view details)

Uploaded Source

File details

Details for the file notipyer-0.3.5.tar.gz.

File metadata

  • Download URL: notipyer-0.3.5.tar.gz
  • Upload date:
  • Size: 16.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.3.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.12.4

File hashes

Hashes for notipyer-0.3.5.tar.gz
Algorithm Hash digest
SHA256 7773760caa962d5a1094fa4286edc6125518d7bafdecf41cf84648fc5d9664f2
MD5 47d5bbbc1e085fc402c9baa8e4837d73
BLAKE2b-256 14d4a4645325ee776f21b324e0afac9f4b9e9aa50db4c83335d06ace3dfbeb37

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page