Send Telegram notifications from Python scripts and notebooks
Project description
telnoti
Send Telegram notifications from Python scripts and notebooks. Zero dependencies beyond requests.
Installation
pip install telnoti
One-time Setup
Interactive (Python):
import telnoti as tn
tn.setup()
CLI:
telnoti setup
Both prompt for your bot token (from @BotFather) and chat ID, then save to ~/.config/.telnoti.config.
Usage
Basic
import telnoti as tn
tn.init() # load saved config
tn.send("hello")
tn.done("training complete")
try:
1 / 0
except Exception as e:
tn.error(e) # sends ❌ ZeroDivisionError: ... with traceback
Training Loop with Status Updates
import telnoti as tn
tn.init()
def status():
tn.send(f"Epoch {current_epoch}/{total_epochs}, loss={loss:.4f}")
tn.start_status(status, every_n_seconds=300) # every 5 minutes
for epoch in range(total_epochs):
# ... training ...
pass
tn.stop_status()
tn.done("Training finished!")
Decorator
import telnoti as tn
tn.init()
@tn.notify(start=True, end=True, error=True)
def run_experiment():
# ... long-running code ...
pass
run_experiment()
# sends: ▶️ run_experiment started
# sends: ✅ run_experiment finished (or ❌ ... on error)
Jupyter Notebook
import telnoti as tn
tn.init()
# In a cell you want to be notified when complete:
# ... heavy computation ...
tn.done("Cell finished")
Send Images
tn.send_image("plot.png", caption="Loss curve")
Catch All Unhandled Exceptions
import telnoti as tn
tn.init()
tn.catch_all() # any uncaught exception will be sent to Telegram
Bot Commands
Send /list to your bot to see all active and recently completed runs:
Active runs
• train.py · PID 12345 · 14:32 (running 1h 23m, 42 msgs — "Epoch 8/10")
Last 24h
✅ data_prep.py · PID 10022 · 09:15 (2h 41m)
❌ train_v2.py · PID 11500 · 11:00 (45m)
💀 overnight.py · PID 8800 · 02:00 (7h 12m)
The polling thread starts automatically on tn.init(). Active runs are always shown; completed/errored runs appear for 24 hours. Dead runs (process killed, last seen > 5 min ago) are shown with 💀.
API
| Function | Description |
|---|---|
init(token=None, chat_id=None, run_name=None) |
Initialize (loads config if no args); run_name overrides auto-detected name |
setup() |
Interactive config wizard |
send(text) |
Send a message |
done(text) |
Send ✅ message |
error(e, tb=True) |
Send ❌ error with optional traceback |
send_image(path, caption=None) |
Send an image file |
start_status(func, every_n_seconds=60) |
Schedule periodic status messages |
stop_status() |
Cancel the status timer |
notify(start, end, error) |
Decorator for notifications |
catch_all() |
Hook sys.excepthook to send all unhandled errors |
disable() |
Suppress all notifications (no messages sent) |
enable() |
Re-enable notifications |
Project details
Release history Release notifications | RSS feed
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 telnoti-0.2.0.tar.gz.
File metadata
- Download URL: telnoti-0.2.0.tar.gz
- Upload date:
- Size: 11.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9cb58f3b1a5c2062d6227cf8956a3e51e1bf0f65ea3eb5dde9db28ad62f4bffe
|
|
| MD5 |
3500135f168791b8c76e0cc61ef2b682
|
|
| BLAKE2b-256 |
56b36b9848078a16a407c48c91967ce4f35470dfb47588b8a151550489f2e19f
|
Provenance
The following attestation bundles were made for telnoti-0.2.0.tar.gz:
Publisher:
publish.yml on linfeng-wang/telnoti
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
telnoti-0.2.0.tar.gz -
Subject digest:
9cb58f3b1a5c2062d6227cf8956a3e51e1bf0f65ea3eb5dde9db28ad62f4bffe - Sigstore transparency entry: 1087565582
- Sigstore integration time:
-
Permalink:
linfeng-wang/telnoti@04760611f7109fbde90e2bcd413118ae1d40ed97 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/linfeng-wang
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@04760611f7109fbde90e2bcd413118ae1d40ed97 -
Trigger Event:
release
-
Statement type:
File details
Details for the file telnoti-0.2.0-py3-none-any.whl.
File metadata
- Download URL: telnoti-0.2.0-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
064254d1e3d76c15c74053ec4af25390c65d11d81b4dbb415e39e2aedac526d6
|
|
| MD5 |
7630bdb913e5ff7da1f31d79d54d96a6
|
|
| BLAKE2b-256 |
126a97b749e7e948c6bd6e93378466f57ae71c5cbc4e3e9d39b308fdb12c01cf
|
Provenance
The following attestation bundles were made for telnoti-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on linfeng-wang/telnoti
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
telnoti-0.2.0-py3-none-any.whl -
Subject digest:
064254d1e3d76c15c74053ec4af25390c65d11d81b4dbb415e39e2aedac526d6 - Sigstore transparency entry: 1087565722
- Sigstore integration time:
-
Permalink:
linfeng-wang/telnoti@04760611f7109fbde90e2bcd413118ae1d40ed97 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/linfeng-wang
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@04760611f7109fbde90e2bcd413118ae1d40ed97 -
Trigger Event:
release
-
Statement type: