Skip to main content

telegram-python

Надсилання Telegram-повідомлень із Python-сервісів через Bot API sendMessage.

uv add telegram-python
from telegram_python import TelegramError, send

send('job_caps failed', chat_id=-1001234567890, message_thread_id=7)

Налаштування

Аргументи send мають пріоритет над змінними оточення.

Змінна Аргумент Призначення
TELEGRAM_BOT_TOKEN token токен бота
TELEGRAM_CHAT_ID chat_id чат або група
TELEGRAM_THREAD_ID message_thread_id тема в групі з темами (topics)
TELEGRAM_SOUND_START_HOUR — початок годин зі звуком, за замовчуванням 9
TELEGRAM_SOUND_END_HOUR — кінець годин зі звуком, за замовчуванням 18

Поза годинами зі звуком повідомлення надсилається беззвучно, якщо не передано disable_notification.

Поведінка

  • Налаштування читаються під час виклику: імпорт не падає без змінних оточення.
  • parse_mode за замовчуванням не задано — текст надсилається як є. Тексти помилок із _, *, ` ламають Markdown, і Telegram відхиляє повідомлення.
  • Текст довший за 4096 символів обрізається.
  • Помилка відправки піднімає TelegramError; токен у текст помилки не потрапляє.
  • Повертає об'єкт Message з відповіді Telegram.

Зміни 1.0.0

Несумісні з 0.x:

  • send піднімає TelegramError замість запису в лог-файл py_log.log;
  • parse_mode за замовчуванням None (було Markdown);
  • send приймає лише keyword-аргументи після message.

Нове: message_thread_id / TELEGRAM_THREAD_ID, явні chat_id і token, тести, збірка через uv.

Розробка

uv run pytest
uv run ruff check . && uv run ruff format --check .

Репозиторій: https://git.7n.ai/nitra/telegram-python. GitHub nitra/telegram-python — лише дзеркало (Forgejo push mirror, deploy key); зміни туди напряму не вносяться, бо дзеркало їх перезапише.

Реліз: підняти version у pyproject.toml, злити в main на Forgejo і поставити тег v<version>. Дзеркало переносить тег на GitHub, де .github/workflows/publish.yml проганяє тести й публікує пакет на PyPI через Trusted Publishing (environment pypi, лише теги v*). Токена PyPI немає.

Metadata

Release files for telegram-python 1.0.0

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-python 1.0.0
File Size Uploaded
telegram_python-1.0.0.tar.gz 32.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for telegram-python 1.0.0
File Interpreter ABI Platform
telegram_python-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 38.2 kB

Release files / telegram_python-1.0.0.tar.gz

Download URL telegram_python-1.0.0.tar.gz
Size 32.3 kB
Tags Source
SHA-256 checksum
How to use checksums
71f288a1c6184a2657293b83223fa6394b46f3f683f62c1fcff24ef9a62c61e7
BLAKE2b-256 checksum
How to use checksums
27386ee055cbbbf499d3e96daa54009b83195fd1154d81bcdc6aaa88dc20eb65
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.

Transparency log

Release files / telegram_python-1.0.0-py3-none-any.whl

Download URL telegram_python-1.0.0-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
538fc6af4ccea538ed4867c8447aa6d0c912c91e0fa57c63da5ae94f21631a98
BLAKE2b-256 checksum
How to use checksums
b7389852d7633c3e4afe07569b0b6f62e0e7222014e5e1efd5f0bd90a39af76f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.6.4

2 release files

0.6.3

2 release files

0.6.2

2 release files

0.4.0

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

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