Skip to main content

A simple and convenient library for creating Telegram bots.

Project description

Extergram v0.5.0 — Asynchronous Telegram Bot Framework

Extergram is a simple, modern, and fully asynchronous library for creating Telegram bots in Python.

Quick Start

Installation

pip install extergram

Complete Example (main.py)

import asyncio import datetime from extergram import Bot, ButtonsDesign, Message, CallbackQuery, errors from extergram.api_types import BotCommand from extergram.ext import CommandHandler, CallbackQueryHandler, MessageHandler

bot = Bot('YOUR_BOT_TOKEN')

main_menu = ButtonsDesign().add_row( ButtonsDesign.create_button("Show time", "show_time"), ButtonsDesign.create_button("About", "about") ).add_row( ButtonsDesign.create_button("Delete this message", "delete") )

async def start(bot_instance: Bot, message: Message): user_name = message.from_user.first_name await bot_instance.send_message( chat_id=message.chat.id, text=f"Hello, {user_name}! I am running on Extergram v0.5.0.", reply_markup=main_menu )

async def handle_callbacks(bot_instance: Bot, callback: CallbackQuery): await bot_instance.answer_callback_query(callback.id)

if callback.data == 'show_time':
    now = datetime.datetime.now().strftime("%H:%M:%S")
    await bot_instance.edit_message_text(
        chat_id=callback.message.chat.id,
        message_id=callback.message.message_id,
        text=f"The current time is: {now}",
        reply_markup=main_menu
    )
elif callback.data == 'delete':
    try:
        await bot_instance.delete_message(callback.message.chat.id, callback.message.message_id)
    except errors.BadRequestError:
        await bot_instance.answer_callback_query(callback.id, "Error: Message too old.", show_alert=True)

async def main(): bot.add_handler(CommandHandler("start", start)) bot.add_handler(CallbackQueryHandler(handle_callbacks))

print("Bot is polling...")
bot.polling()

if name == 'main': try: asyncio.run(main()) except KeyboardInterrupt: pass

Features & Core Concepts

  • Fully Async: High-performance non-blocking operations using httpx.
  • Handler System: Manage updates with CommandHandler, MessageHandler, and CallbackQueryHandler.
  • Type Hinting: Comprehensive api_types for better IDE support.
  • Error Handling:
    • errors.NetworkError: Connection issues.
    • errors.BadRequestError: Invalid API requests.
    • errors.ForbiddenError: Bot blocked by user.
    • errors.UnauthorizedError: Invalid token.

Local Documentation

You can access the full documentation directly from your terminal: from extergram import Docs Docs.print_docs()

License

MIT License. Copyright (c) 2024-2025.

Project details


Download files

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

Source Distribution

extergram-0.6.0a1.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

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

extergram-0.6.0a1-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file extergram-0.6.0a1.tar.gz.

File metadata

  • Download URL: extergram-0.6.0a1.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for extergram-0.6.0a1.tar.gz
Algorithm Hash digest
SHA256 cd203d93bd184f1e7252b3db224c08eab5280f4f8306348faca2c66752710307
MD5 46b5ff470bf96f14170d5479a4cd1236
BLAKE2b-256 8afbc56c0cf98dad6516530af42e34ed2582a66dea9b037b8792c495a2303a38

See more details on using hashes here.

File details

Details for the file extergram-0.6.0a1-py3-none-any.whl.

File metadata

  • Download URL: extergram-0.6.0a1-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for extergram-0.6.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 ce3e1e9e0230c94fa1a3758a2f70bfa766fe0f34a194bda2e1f40b1175a62e89
MD5 fba3d2ac8b1b9326abef985c18843472
BLAKE2b-256 d83f31764c4485c16555692b87366cfad89408f4e903f0b0ea83397d9d564003

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