Skip to main content

Telegram Exception Alerts

Code style: black PyPI PyPI - Python Version PyPI - Wheel PyPI - Downloads

THIS LIBRARY HAS BEEN EXTENSIVELY TESTED AND IS CONSIDERED VERY STABLE: IT WORKS FINE AND HAS NO EXTERNAL DEPENDENCIES. SO NO FUTURE UPDATES ARE EXPECTED UNLESS I HAVE SOME VERY BRIGHT IDEA ABOUT IT.

A very lightweight library for sending exception details to Telegram using a decorator. It uses no external dependencies.

Installation

pip install telegram-exception-alerts

or

poetry add telegram-exception-alerts

Usage

After you initialize the alerter instance you can attach the decorator to any function. If it raises an exception information will be send to the chat specified in chat_id (don't forget that if you want to send notification to a channel you need to prepend that chat_id with -100).

Normal initialization

from telegram_exception_alerts import Alerter

tg_alert = Alerter(bot_token='YOUR_BOT_TOKEN', chat_id='YOUR_CHAT_ID')

@tg_alert
def some_func_that_can_raise_an_exception():
    raise RuntimeError('this is an exception')

Initialization from environment (recommended)

You can also initialize the alerter from environment variables. This is the recommended way because it will make sure you're not committing sensitive information to the repo.

  • ALERT_BOT_TOKEN - your bot token
  • ALERT_CHAT_ID - your chat id to receive notifications
from telegram_exception_alerts import Alerter

tg_alert = Alerter.from_environment()

@tg_alert
def some_func_that_can_raise_an_exception():
    raise RuntimeError('this is an exception')

Here's what a telegram message from an example above looks like:

Sending messages

You can also use the Alerter as a simple way to send messages to Telegram:

from telegram_exception_alerts import Alerter

tg_alert = Alerter.from_environment()

tg_alert.send_message(chat_id=111222333, text='Message text')

For real bot programming I highly recommend the excellent python-telegram-bot library.

Metadata

Release files for telegram-exception-alerts 1.0.1

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

Source distribution (sdist)

Source distribution for telegram-exception-alerts 1.0.1
File Size Uploaded Provenance Actions
telegram_exception_alerts-1.0.1.tar.gz 3.4 kB Without provenance Details for telegram_exception_alerts-1.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for telegram-exception-alerts 1.0.1
File Interpreter ABI Platform Actions
telegram_exception_alerts-1.0.1-py3-none-any.whl Python 3 none any Details for telegram_exception_alerts-1.0.1-py3-none-any.whl

Total release size: 7.0 kB

Release files / telegram_exception_alerts-1.0.1.tar.gz

Download URL telegram_exception_alerts-1.0.1.tar.gz
Size 3.4 kB
Tags Source
SHA-256 checksum
How to use checksums
3e352fa402a06617d1620b48b2a7cccb5e75004f3e28707eec2ee907416557e1
BLAKE2b-256 checksum
How to use checksums
bc13ec59278cc9b6c806ee6d1050151532ee6dca06c2bf839ab8b25facfe54f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.5 CPython/3.7.10 Linux/5.4.0-1041-azure

Release files / telegram_exception_alerts-1.0.1-py3-none-any.whl

Download URL telegram_exception_alerts-1.0.1-py3-none-any.whl
Size 3.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1710fd170f473dae933454de202c04e1b5bf9c74d961389c16412a4207be5574
BLAKE2b-256 checksum
How to use checksums
ac91312095a1ef9d3ff41b64d264ffd357f2bc4e161cc19cc265e4bb81c5bc45
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.5 CPython/3.7.10 Linux/5.4.0-1041-azure

Security for telegram-exception-alerts 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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