Skip to main content

netcherTG

A simple, dependency-light Python library for building Telegram bots on top of the official Telegram Bot HTTP API.

Install

pip install netcherTG

Getting a bot token

Message @BotFather on Telegram, run /newbot, and follow the prompts to get an API token.

Quick start

from netcherTG import Bot

bot = Bot("123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11")

@bot.command("start")
def start(bot, message):
    bot.send_message(message.chat_id, f"Hello, {message.username}!")

@bot.command("echo")
def echo(bot, message):
    text = " ".join(message.args()) or "(nothing to echo)"
    bot.send_message(message.chat_id, text)

@bot.message_handler()
def fallback(bot, message):
    bot.send_message(message.chat_id, "I didn't understand that.")

bot.run()

Inline keyboards

from netcherTG import Bot, keyboards

bot = Bot("YOUR_TOKEN")

@bot.command("menu")
def menu(bot, message):
    kb = keyboards.inline_keyboard([
        [("Yes", "yes"), ("No", "no")],
    ])
    bot.send_message(message.chat_id, "Choose one:", reply_markup=kb)

@bot.callback_query_handler()
def on_click(bot, query):
    bot.answer_callback_query(query.id, text="Got it!")
    bot.send_message(query.message.chat_id, f"You picked: {query.data}")

bot.run()

Reply keyboards

from netcherTG import keyboards

kb = keyboards.reply_keyboard([["Option A", "Option B"], ["Cancel"]])
bot.send_message(chat_id, "Pick one:", reply_markup=kb)

What's new in 0.2.0

Features you won't find built into most other Telegram bot libraries:

Automatic /help

If you don't define your own /help, one is generated for you from your commands' docstrings:

@bot.command("start")
def start(bot, message):
    "Start the bot"
    ...

Users typing /help get a clean list of all commands automatically. Turn it off with bot.disable_auto_help().

Typo suggestions

If a user sends an unknown command, netcherTG suggests the closest match:

User: /stwrt
Bot:  Unknown command. Did you mean /start?

Built-in per-user sessions (no separate FSM library needed)

@bot.command("setname")
def setname(bot, message):
    bot.session(message.user_id)["awaiting_name"] = True

@bot.message_handler()
def on_text(bot, message):
    s = bot.session(message.user_id)
    if s.get("awaiting_name"):
        s["name"] = message.text
        s["awaiting_name"] = False
        bot.send_message(message.chat_id, f"Saved: {message.text}")

Rate limiting per handler, per user

@bot.command("draw")
@bot.rate_limit(seconds=5)
def draw(bot, message):
    ...

Repeat calls inside the window are silently ignored — no spam replies.

"Typing..." context manager

with bot.typing(message.chat_id):
    result = slow_computation()
bot.send_message(message.chat_id, result)

Auto-retry with backoff

bot.run() no longer crashes on a dropped connection — it retries with exponential backoff (up to max_backoff seconds) automatically.

Escaping helpers

from netcherTG import escape_markdown, escape_html

bot.send_message(chat_id, escape_markdown(user_input), parse_mode="MarkdownV2")

Avoids 400 Bad Request: can't parse entities errors from unescaped special characters.

API overview

Method Description
Bot(token) Create a bot instance
bot.send_message(chat_id, text, ...) Send a text message
bot.send_photo(chat_id, photo_url, caption=None) Send a photo
bot.edit_message_text(chat_id, message_id, text) Edit an existing message
bot.delete_message(chat_id, message_id) Delete a message
bot.answer_callback_query(id, text=None) Acknowledge a button press
bot.get_me() Get info about the bot
@bot.command(name) Register a /command handler
@bot.message_handler() Register a handler for plain text messages
@bot.callback_query_handler() Register a handler for inline button presses
bot.run(poll_interval=1.0) Start long-polling
bot.session(user_id) Get/create a per-user state dict
bot.clear_session(user_id) Clear a user's stored session
@bot.rate_limit(seconds) Throttle a handler per user
bot.typing(chat_id) Context manager for "typing..." indicator
bot.disable_auto_help() Turn off the auto-generated /help
escape_markdown(text) / escape_html(text) Escape text for safe sending

License

MIT

Download files

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

Source Distribution

netchertg-0.2.0.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

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

netchertg-0.2.0-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file netchertg-0.2.0.tar.gz.

File metadata

  • Download URL: netchertg-0.2.0.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.3

File hashes

Hashes for netchertg-0.2.0.tar.gz
Algorithm Hash digest
SHA256 94633023a3a932d574d5e965a55e5350cdaf7d995538153ef746618a02185657
MD5 5fce31e92180edeec57f2308f430c4f3
BLAKE2b-256 6ed37a281451055c517dcbce796be48e9b3084b809ab2b0718e83fbdb86c83fb

See more details on using hashes here.

File details

Details for the file netchertg-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: netchertg-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.3

File hashes

Hashes for netchertg-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 389e3e0a045fa6fb00b7700215b15a7564f8568b3f9b05983c88fe914312743c
MD5 6ce65272b6e04db95902f03a68db9139
BLAKE2b-256 9e3be1b1e8b6cd37df01164fc69328ead55e2d95618996a43c4a11174bf0eb81

See more details on using hashes here.

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