Skip to main content

Async-Notify

Async-Notify is a simple, asyncio-based notification library for Apps.

Notify is built on top of python asyncio for send notifications asynchronous with support of twilio, telegram, o365, email, slack, onesignal and many others.

Why Async-Notify?

The finality of Async-Notify is to provide us a subset of communication providers for sending different notifications in a non-blocking mode.. The main goal of Async-Notify is using only asyncio-based technologies.

Requirements

Installation

The core install is deliberately slim: it carries only what the provider-agnostic core path needs. Providers that depend on a third-party SDK ship that SDK in an extra — install async-notify[<extra>] for one provider (for example pip install async-notify[telegram]), async-notify[all] for every provider, or async-notify[server] for the Redis-backed notify server.

Provider Notify(...) alias Extra required
Amazon (AWS) e-mail aws none — core install
Dialpad dialpad none — core install (aiohttp)
Dummy (testing) dummy none — core install
Generic e-mail email none — core install
Gmail gmail google
Office 365 (Microsoft Graph) office365 azure
OneSignal push onesignal push
Outlook (Microsoft Graph) outlook azure
SendGrid sendgrid none — core install
Amazon SES ses ses
Slack slack slack
SMTP smtp none — core install
Microsoft Teams teams azure
Telegram telegram telegram
Twilio SMS twilio twilio
XMPP xmpp xmpp
Zoom zoom none — core install (aiohttp)

Other extras: all (every provider SDK plus the extras below), server (notify server: cloudpickle, qworker, redis), uvloop, templates (extra Jinja2 extensions) and default (aiogram + slack_bolt).

The notify console script (notify/__main__.py) starts the Redis-backed notification server and therefore requires the server extra; without it the script exits with an import error for cloudpickle.

Quick Tutorial

Currently Async-Notify supports the following providers:

  • Amazon SES
  • Email (SMTP)
  • Gmail
  • Office 365 (Microsoft Graph; outlook is a compatible alias)
  • Telegram (requires aiogram)
  • Twilio (SMS)
  • OneSignal
  • Twitter
  • XMPP stanzas

Templates

send(template=...) accepts either a template filename (resolved on TEMPLATE_DIR, unchanged since earlier versions) or raw Jinja2 source text, auto-detected by a conservative heuristic (a Jinja2 delimiter {{, {%, {#, or a line break means source; anything else is treated as a filename). Use template_is_source=True/False to force either interpretation when the heuristic can't decide (for example a body with no Jinja markup and no newline, which is indistinguishable from a filename).

# raw source — new in 1.6.0
await Notify("smtp").send(
    recipient=[actor],
    subject="Welcome",
    template="<p>Hola {{ recipient.account.address }} — {{ message }}</p>",
    message="…",
)

# filename — unchanged behaviour
await Notify("smtp").send(recipient=[actor], template="welcome.html")

# forced, for a body with no Jinja markup
await Notify("telegram").send(
    recipient=[chat], template="Hello world", template_is_source=True,
)

Security note: autoescape is disabled, so a template compiled from a string executes arbitrary Jinja2 and emits unescaped output. Template source must come from trusted operators (configuration, database rows written by staff) — never from end-user input. End-user data belongs in the message parameters, not in the template body itself.

Microsoft Graph mail (office365 / outlook)

office365 (and its backward-compatible alias outlook) now send mail through Microsoft Graph (msgraph-sdk), not the legacy Outlook REST API — one Graph message per send() call, to every recipient. Four auth flows share one MSAL-backed credential: client_credentials (app-only, secret or certificate), on_behalf_of (OAuth2 OBO — a signed-in user's token exchanged for a Graph token, send-only, never queued), delegated (headless device-code bootstrap, then silent cached refresh), and the deprecated password (ROPC).

# App-only, sending as a shared mailbox
mail = Notify(
    "office365", auth_flow="client_credentials",
    client_id="CLIENT_ID", client_secret="CLIENT_SECRET", tenant_id="TENANT_ID",
    sender="noreply@contoso.com",
)
async with mail as m:
    [result] = await m.send(
        recipient=[alice, bob], subject="Report", template="report.html",
        cc=["ops@contoso.com"], attachments=["/tmp/report.pdf"], importance="high",
    )
    assert result.success

# One-time headless delegated bootstrap (no browser redirect):
#   $ python -m notify.providers.office365.login --username me@contoso.com

Token caches are pluggable (memory default, file, redis) and encrypted (Fernet) for the persistent stores unless allow_unencrypted=True is explicit. Full flow reference, tenant/app permission prerequisites, send-as/OBO semantics, and the migration notes for the use_credentials default change and the removed o365/Office365-REST-Python-Client dependencies live in docs/providers.rst.

Future work:

  • Slack
  • Facebook Messenger
  • Discord
  • IRC

How do I get set up?

  • Summary of set up
  • Configuration
  • Dependencies
  • Database configuration
  • How to run tests
  • Deployment instructions

Contribution guidelines

Please have a look at the Contribution Guide

  • Writing tests
  • Code review

Who do I talk to?

  • Repo owner or admin
  • Other community or team contact

License

Async-Notify is copyright of Jesus Lara (https://phenobarbital.info) and is licensed under BSD license. I am providing code in this repository under an open source licenses, remember, this is my personal repository; the license that you receive is from me and not from my employeer.

Metadata

Release files for async-notify 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for async-notify 2.0.0
File Size Uploaded
async_notify-2.0.0.tar.gz 124.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for async-notify 2.0.0
File Interpreter ABI Platform
async_notify-2.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 230.4 kB

Release files / async_notify-2.0.0.tar.gz

Download URL async_notify-2.0.0.tar.gz
Size 124.6 kB
Tags Source
SHA-256 checksum
How to use checksums
511ccebf1b23996fc784f76014aeda49f86aef17eb9b968617fbc36ea08f0515
BLAKE2b-256 checksum
How to use checksums
0d5c93e5ed3f9a0710b617a826e62c237c7bbc0ea8ea7bf929c42ca447ca3395
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / async_notify-2.0.0-py3-none-any.whl

Download URL async_notify-2.0.0-py3-none-any.whl
Size 105.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f26baaec239cf130dceed37feb12851ead3626cb5460701a4b573de908c4b4bc
BLAKE2b-256 checksum
How to use checksums
51c39577e92872f55b8c05ef739456613f60e89b9e514f6324d86b27b3df07d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files

1.6.2

8 release files

1.6.1

8 release files

1.6.0

4 release files

1.5.7

4 release files

1.5.5

3 release files

1.5.4

3 release files

1.5.3

3 release files

1.5.2

3 release files

1.5.1

3 release files

1.5.0

3 release files

1.4.2

4 release files

1.4.1

4 release files

1.4.0

4 release files

1.3.10

4 release files

1.3.9

4 release files

1.3.8

4 release files

1.3.7

4 release files

1.3.6

4 release files

1.3.5

4 release files

1.3.4

4 release files

1.3.3

4 release files

1.3.2

4 release files

1.3.1

4 release files

1.3.0

4 release files

1.2.4

4 release files

1.2.3

3 release files

1.2.2

3 release files

1.2.1

3 release files

1.2.0

3 release files

1.1.5

3 release files

1.1.4

3 release files

1.1.3

3 release files

1.1.2

3 release files

1.1.1

3 release files

1.1.0

3 release files

1.0.1

3 release files

1.0.0

3 release files

0.9.4

1 release file

0.9.3

1 release file

0.9.2

1 release file

0.9.1

2 release files

0.9.0

2 release files

0.8.13

2 release files

0.8.12

2 release files

0.8.10

2 release files

0.8.9

2 release files

0.8.8

2 release files

0.8.7

2 release files

0.8.6

2 release files

0.8.5

2 release files

0.8.4

2 release files

0.8.3

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.4

2 release files

0.6.3

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.27

2 release files

0.5.23

2 release files

0.5.21

2 release files

0.5.20

2 release files

0.5.19

2 release files

0.5.8

2 release files

0.5.7

2 release files

0.5.6

2 release files

0.5.5

2 release files

0.5.4

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page