tg-rich-converter 🚀
A lightweight, zero-dependency Python library that converts standard LLM Markdown, LaTeX formulas, thinking processes, and tables into native Telegram Bot API 10.1+ Rich HTML (sendRichMessage).
Why tg-rich-converter?
Starting with Telegram Bot API 10.1, Telegram introduced Rich Messages (sendRichMessage) supporting:
- Messages up to 32,768 characters (no more 4,096-character limit!).
- Native interactive tables with borders and striping.
- Native LaTeX math rendering (both inline and display equations).
- Expandable spoiler/details blocks for reasoning models (
DeepSeek-R1,OpenAI o1/o3).
However, LLMs (OpenAI, Anthropic, DeepSeek, Ollama) still output plain Markdown and LaTeX. tg-rich-converter bridges this gap seamlessly in a single function call.
Features
- 📊 Native Tables: Converts standard Markdown pipe tables (
| col | col |) into<table bordered striped>with column alignment (left,center,right). - 🧮 LaTeX Math: Converts
$$...$$into<tg-math-block>and$x$into<tg-math>. Even works inside table cells! - 🧠 AI Thinking Blocks: Converts
<think>...</think>tags from reasoning models into expandable native<details><summary>Размышления</summary>...</details>blocks. - 💻 Syntax-Highlighted Code: Converts
```pythoninto<pre><code class="language-python">preserving quotes and copy-paste buttons. - 💬 Quotes & Spoilers: Native blockquotes and spoilers (
||spoiler||) with snake_case protection. - ⚡ Zero Dependencies: Pure standard Python (
re,html). Extremely fast (~0.001s per message).
Installation
pip install tg-rich-converter
Quick Start
from tg_rich_converter import to_rich
llm_output = """
# Quantum Computing Report
| Algorithm | Database | Complexity | Speedup |
|:----------|:--------:|:----------:|--------:|
| Linear Search | $N$ items | $O(N)$ | $1\\times$ |
| Grover Search | $N$ items | $O(\\sqrt{N})$ | Quadratic |
### Key Formula
$$|\\psi\\rangle = \\alpha |0\\rangle + \\beta |1\\rangle$$
<think>
Evaluating time complexity and qubit entanglement...
</think>
"""
rich_html = to_rich(llm_output)
Framework Integrations
1. aiogram (3.31+)
from aiogram import Bot
from tg_rich_converter import to_rich
bot = Bot(token="YOUR_BOT_TOKEN")
rich_html = to_rich(llm_response)
await bot.send_rich_message(
chat_id=chat_id,
rich_message={"html": rich_html}
)
2. pyTelegramBotAPI (telebot 4.36+)
import telebot
from tg_rich_converter import to_rich
bot = telebot.TeleBot("YOUR_BOT_TOKEN")
rich_html = to_rich(llm_response)
bot.send_rich_message(
chat_id=chat_id,
rich_message={"html": rich_html}
)
3. Direct HTTP (requests / httpx)
import requests
from tg_rich_converter import to_rich
rich_html = to_rich(llm_response)
requests.post(
f"https://api.telegram.org/bot{BOT_TOKEN}/sendRichMessage",
json={
"chat_id": chat_id,
"rich_message": {
"html": rich_html
}
}
)
Testing
Run unit tests locally:
pytest
License
MIT License. Free for commercial and personal use.
Release files for tg-rich-converter 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| tg_rich_converter-0.1.1.tar.gz | 80.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tg_rich_converter-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 86.7 kB
Release files / tg_rich_converter-0.1.1.tar.gz
| Download URL | tg_rich_converter-0.1.1.tar.gz |
|---|---|
| Size | 80.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1de8d8ea9fb2e7f065eb212366a80d4e40b32c69dc744dcc9930ddebf7325962
|
|
BLAKE2b-256 checksum How to use checksums |
2eb9d435a675161ded215fa915220990552c3a75a8f5f311f22181337ec80618
|
| 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 Sep 20, 2026.
Transparency logRelease files / tg_rich_converter-0.1.1-py3-none-any.whl
| Download URL | tg_rich_converter-0.1.1-py3-none-any.whl |
|---|---|
| Size | 5.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
34f1ac58870d16a187230f21edd15e165890a46c13e444fea65b547667f2a0d2
|
|
BLAKE2b-256 checksum How to use checksums |
2c7e8397ec4ccf9ccd2e09df074f5f319f5d105ecca53a65131d87eed79b8a90
|
| 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 Sep 20, 2026.
Transparency log