Skip to main content

KFormat

Short aliases for Telegram HTML formatting, tables, inline keyboards, and Rich Message JSON helpers.

Install

pip install kformat-telebot

For inline keyboard helpers, install the optional TeleBot dependency:

pip install "kformat-telebot[telebot]"

Quick example

import telebot
from kformat import K

bot = telebot.TeleBot("YOUR_BOT_TOKEN")

@bot.message_handler(commands=["start"])
def start(message):
    text = (
        K.b("Bold") + "\n"
        + K.un("Underline") + "\n"
        + K.sp("Spoiler") + "\n"
        + K.a("Open website", "https://example.com")
    )
    bot.send_message(message.chat.id, text, parse_mode="HTML")

bot.infinity_polling()

Tables

text = K.table(
    [["Kentucky", "10"], ["Kentucky", "20"]],
    headers=["Name", "Count"]
)
bot.send_message(chat_id, text, parse_mode="HTML")

Classic Telegram sendMessage has no native table-cell layout, so K.table renders a readable monospace text table.

Inline keyboard

markup = K.buttons(
    [("Open", "callback:open"), ("Website", "url:https://example.com")],
    [K.btn("Second row", data="second")]
)
bot.send_message(chat_id, "Choose:", reply_markup=markup)

Rich Message JSON

payload = K.rich(
    K.rh("Heading"),
    K.rb("Paragraph"),
    K.rtable([["Name", "Count"], ["Kentucky", "10"]])
)
print(K.rich_json(K.rh("Heading"), K.rb("Paragraph")))

Rich Message helpers only build the JSON structure. Sending it requires a Telegram Bot API method/client that supports Rich Messages.

API

  • K.b(text): bold
  • K.i(text): italic
  • K.un(text): underline
  • K.st(text): strikethrough
  • K.sp(text): spoiler
  • K.c(text): inline code
  • K.pre(text, lang=None): preformatted code
  • K.a(text, url): hyperlink
  • K.tg(text, user_id): user mention
  • K.block(text): blockquote
  • K.expand(text): expandable blockquote
  • K.table(rows, headers=None): monospace table
  • K.buttons(*rows): inline keyboard markup
  • K.btn(text, data=... or url=...): button specification
  • K.rb, K.rh, K.rdiv, K.rtable, K.rbutton, K.rbuttons, K.rich, K.rich_json: Rich Message JSON builders
  • K.ul, K.ol, K.bullet, K.hr, K.join, K.plain, K.raw
  • K.help(): usage guide

Text helpers return Telegram HTML fragments. Use parse_mode="HTML". Text is escaped automatically. K.raw() is for trusted HTML only.

Metadata

Release files for kformat-telebot 0.1.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 kformat-telebot 0.1.0
File Size Uploaded Provenance Actions
kformat_telebot-0.1.0.tar.gz 5.1 kB Without provenance Details for kformat_telebot-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for kformat-telebot 0.1.0
File Interpreter ABI Platform Actions
kformat_telebot-0.1.0-py3-none-any.whl Python 3 none any Details for kformat_telebot-0.1.0-py3-none-any.whl

Total release size: 10.8 kB

Release files / kformat_telebot-0.1.0.tar.gz

Download URL kformat_telebot-0.1.0.tar.gz
Size 5.1 kB
Tags Source
SHA-256 checksum
How to use checksums
38a157972f60d8373b873cdce2e610f665cfeb597b8ae8bf7ac9fa511b5be3b1
BLAKE2b-256 checksum
How to use checksums
5f5b806864b91e587d3f7a0bc47ed012f748fd02e171a7da16c7577dbecd8a44
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.13.13

Release files / kformat_telebot-0.1.0-py3-none-any.whl

Download URL kformat_telebot-0.1.0-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d1a5ed1e5dbc475cc11708b03111c105dc8b5deda205e1e62427771549fc0991
BLAKE2b-256 checksum
How to use checksums
c58934e533cd51e3501b2707f1dd7441437cb1e98a59c1d30619484bea5c47d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.13.13

Security for kformat-telebot 0.1.0

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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