Skip to main content

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 💀.

Version

import telnoti
print(telnoti.__version__)  # e.g. 0.2.0
telnoti --version  # telnoti 0.2.0
telnoti -V

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


Download files

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

Source Distribution

telnoti-0.2.1.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

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

telnoti-0.2.1-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file telnoti-0.2.1.tar.gz.

File metadata

  • Download URL: telnoti-0.2.1.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for telnoti-0.2.1.tar.gz
Algorithm Hash digest
SHA256 c44253edb39e0ff057fb4347bf409fa9adbccdad9b52ec6a418fd84f59eef072
MD5 f8852459f9feb4423b67a75cc9db852b
BLAKE2b-256 4982df8c20be81149808755d03c164f49bbb6fc03a7d68606f270a6a516d48fd

See more details on using hashes here.

Provenance

The following attestation bundles were made for telnoti-0.2.1.tar.gz:

Publisher: publish.yml on linfeng-wang/telnoti

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file telnoti-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: telnoti-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for telnoti-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6cc08f22528060648caee6c6c4f3dc4e9b30c1e34033c9370acc42f86977258e
MD5 49497cb70338866fbb6a8fbc2d9c6465
BLAKE2b-256 851ccba24d73bf6b0c11e9df6cde320e2b2e3ad6fd1288c59fc0e29da9e19223

See more details on using hashes here.

Provenance

The following attestation bundles were made for telnoti-0.2.1-py3-none-any.whl:

Publisher: publish.yml on linfeng-wang/telnoti

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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