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 three utilities:
drpython.telegram: send messages via a Telegram bot.drpython.email: send emails via an SMTP server.drpython.database: append-friendly helpers for CSV, Excel (.xlsx), and JSON.
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_TOKENDRPYTHON_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(default587)DRPYTHON_SMTP_USERDRPYTHON_SMTP_PASSWORDDRPYTHON_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)
Database (CSV, Excel, JSON)
Convenience functions to append or create tabular data files from a list of dictionaries. Dependencies pandas and openpyxl are included.
Functions:
add_to_csv(data, filename, *, encoding='utf-8', index=False, append=True, **kwargs)add_to_excel(data, filename, *, sheet_name='Sheet1', index=False, append=True, **kwargs)add_to_json(data, filename, *, append=True, indent=2, **kwargs)
Example:
from drpython.database import add_to_csv, add_to_excel, add_to_json
data = [
{"id": 1, "name": "Alice", "score": 95},
{"id": 2, "name": "Bob", "score": 87},
]
# CSV: appends if file exists, otherwise creates; controls header/index
add_to_csv(data, "users.csv", append=True, index=False)
# Excel (.xlsx): appends to an existing sheet starting at next row; creates otherwise
add_to_excel(data, "users.xlsx", sheet_name="Users", append=True, index=False)
# JSON: writes a proper JSON array; appends safely if file exists and is valid JSON
add_to_json(data, "users.json", append=True, indent=2)
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_telegramusesrequests.getand returnsTrue/Falsebased on Telegram API response.notify_emailusessmtplib.SMTPand returnsTrue/Falsebased on send success.- Data helpers rely on
pandas(andopenpyxlfor Excel) which are installed automatically. - If you encounter build/publish issues, ensure your
pyproject.tomlincludes asrc/drpythonwheel target and excludes.envfrom 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file drpython-0.3.1.tar.gz.
File metadata
- Download URL: drpython-0.3.1.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d5e5e53023e44d6697e49fe3fe8b12be69f51eed25928a80748d465cb9f2585
|
|
| MD5 |
13dcea1b885999e3847a486f1709cc98
|
|
| BLAKE2b-256 |
e54a660c546e8b3519c496726a88620e551829803815b87dd872f4cd3efd3c9b
|
File details
Details for the file drpython-0.3.1-py3-none-any.whl.
File metadata
- Download URL: drpython-0.3.1-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd811566595b0b6e4828b64cfa99eeb372d527eace0998eb3e72a6b6ecf08061
|
|
| MD5 |
d34f5849e92e0c975caaeb6cad93eee6
|
|
| BLAKE2b-256 |
7222c5fd30534b4221852df84b4c1e96048218507980ce947d0a41b079029e17
|