Skip to main content

Modular notifications: drpython.telegram, drpython.email & drpython.database

Project description

drpython

Modular notifications for Python projects: simple helpers for Telegram bots and SMTP email.

This library provides two small utilities:

  • drpython.telegram: send messages via a Telegram bot.
  • drpython.email: send emails via an SMTP server.

Both modules expose a light class (TelegramNotifier, EmailNotifier) and a convenience function (notify_telegram, notify_email).

Installation

  • Using uv (recommended for projects):

    uv add drpython
    
  • Using pip:

    pip install drpython
    

Quickstart

You can pass credentials directly to the functions/classes, or supply them via environment variables. If you keep secrets in a .env file, load it with python-dotenv before calling the notifiers.

from dotenv import load_dotenv
load_dotenv()  # Only needed if using a .env file

Telegram

Environment variables used:

  • DRPYTHON_TELEGRAM_TOKEN
  • DRPYTHON_CHAT_ID

Send a Telegram message using environment variables:

from drpython.telegram import notify_telegram

ok = notify_telegram("Hello from drpython!", parse_mode="HTML")
print(ok)  # True if sent

Or pass credentials explicitly:

from drpython.telegram import TelegramNotifier

bot = TelegramNotifier(token="<BOT_TOKEN>", chat_id="<CHAT_ID>")
ok = bot.send("<b>Bold</b> and <i>italic</i>", parse_mode="HTML", disable_notification=False)
print(ok)

Email (SMTP)

Environment variables used:

  • DRPYTHON_SMTP_HOST (e.g., smtp.gmail.com)
  • DRPYTHON_SMTP_PORT (default 587)
  • DRPYTHON_SMTP_USER
  • DRPYTHON_SMTP_PASSWORD
  • DRPYTHON_SMTP_FROM (defaults to user)

Send an email using environment variables:

from drpython.email import notify_email

ok = notify_email(
    to="recipient@example.com",
    subject="Greetings",
    body="Hello from drpython!",
    html=False,  # set True to send HTML
)
print(ok)

Or pass credentials explicitly and use the class:

from drpython.email import EmailNotifier

mailer = EmailNotifier(
    host="smtp.example.com",
    port=587,
    user="user@example.com",
    password="app_password",
    from_addr="user@example.com",
)

ok = mailer.send(
    to=["recipient@example.com", "other@example.com"],
    subject="Attachments and HTML",
    body="<b>Hello</b> world",
    html=True,
    cc="cc@example.com",
    bcc=["bcc1@example.com", "bcc2@example.com"],
    attachments=["path/to/file.pdf"],
)
print(ok)

Using .env

If you prefer a .env file, create it and load it in your app:

# Telegram
DRPYTHON_TELEGRAM_TOKEN=your-bot-token
DRPYTHON_CHAT_ID=your-chat-id

# SMTP
DRPYTHON_SMTP_HOST=smtp.example.com
DRPYTHON_SMTP_PORT=587
DRPYTHON_SMTP_USER=user@example.com
DRPYTHON_SMTP_PASSWORD=app_password
DRPYTHON_SMTP_FROM=user@example.com

Then load it:

from dotenv import load_dotenv
load_dotenv()

Never commit real tokens or passwords to source control.

Notes

  • Commands above are shown for Windows PowerShell.
  • notify_telegram uses requests.get and returns True/False based on Telegram API response.
  • notify_email uses smtplib.SMTP and returns True/False based on send success.
  • If you encounter build/publish issues, ensure your pyproject.toml includes a src/drpython wheel target and excludes .env from distributions.

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

drpython-0.1.6.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

drpython-0.1.6-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file drpython-0.1.6.tar.gz.

File metadata

  • Download URL: drpython-0.1.6.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.18

File hashes

Hashes for drpython-0.1.6.tar.gz
Algorithm Hash digest
SHA256 44c63b2862d8ae80f1b446722c87eb5af238e1ec4b261431b15958137c768fe8
MD5 631174c11bd40912ab874ad8966879f7
BLAKE2b-256 1f2a0e7d4f2863c9fcf9b7a9ec5d31af16a7b726d68fe4bd32a618b271c7acb9

See more details on using hashes here.

File details

Details for the file drpython-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: drpython-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.18

File hashes

Hashes for drpython-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 a745cb5d951c6c16ec4d93f084f7bafada1ca019a4256179d8e78276a05fb408
MD5 6c5108562a2bb08aa8b21083dc1b0de8
BLAKE2b-256 7fcf4cbb40f0dee8f6b034052c9db7c3b8b015f1d1c802e479ff54d084e3eb5e

See more details on using hashes here.

Supported by

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