{"id":4208,"library":"pytelegrambotapi","title":"pyTelegramBotAPI","description":"pyTelegramBotAPI is a straightforward yet comprehensive Python library providing both synchronous and asynchronous implementations of the Telegram Bot API. It enables developers to easily create Telegram bots with features like message handling, inline queries, and custom keyboards. The library is actively maintained, with frequent updates (often monthly or bi-monthly) to support the latest Telegram Bot API versions, and the current version is 4.33.0.","status":"active","version":"4.33.0","language":"en","source_language":"en","source_url":"https://github.com/eternnoir/pyTelegramBotAPI","tags":["telegram","bot","api","async","sync"],"install":[{"cmd":"pip install pyTelegramBotAPI","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"The primary class for synchronous bots is imported via 'import telebot'.","wrong":"from pyTelegramBotAPI import TeleBot","symbol":"TeleBot","correct":"import telebot\nbot = telebot.TeleBot(TOKEN)"},{"note":"The asynchronous bot class requires a specific import path from 'telebot.async_telebot'.","wrong":"import telebot\nbot = telebot.AsyncTeleBot(TOKEN)","symbol":"AsyncTeleBot","correct":"from telebot.async_telebot import AsyncTeleBot\nbot = AsyncTeleBot(TOKEN)"},{"note":"Commonly imported directly for convenience, though 'telebot.types' also works.","wrong":"import telebot.types","symbol":"types","correct":"from telebot import types"}],"quickstart":{"code":"import os\nimport telebot\n\nAPI_TOKEN = os.environ.get('TELEGRAM_BOT_TOKEN', 'YOUR_BOT_TOKEN_HERE')\n\nif not API_TOKEN or API_TOKEN == 'YOUR_BOT_TOKEN_HERE':\n    print(\"Warning: TELEGRAM_BOT_TOKEN environment variable not set or placeholder used. \\n\"\\\n          \"Please obtain a token from @BotFather on Telegram and set it.\")\n    exit(1)\n\nbot = telebot.TeleBot(API_TOKEN)\n\n@bot.message_handler(commands=['start', 'help'])\ndef send_welcome(message):\n    bot.reply_to(message, \"Hi there, I am an EchoBot. I will echo your messages.\")\n\n@bot.message_handler(func=lambda message: True)\ndef echo_message(message):\n    bot.reply_to(message, message.text)\n\nprint(\"Bot started polling...\")\nbot.infinity_polling()","lang":"python","description":"This quickstart sets up a basic synchronous 'EchoBot' that replies to /start, /help, and any other text message by echoing the input. Ensure you replace 'YOUR_BOT_TOKEN_HERE' or set the `TELEGRAM_BOT_TOKEN` environment variable with the token obtained from @BotFather. The bot uses `infinity_polling()` to continuously check for new messages."},"warnings":[{"fix":"Consult the official pyTelegramBotAPI GitHub releases and Telegram Bot API documentation for migration guides. Update your bot's code to align with new API specifications.","message":"Major changes in the official Telegram Bot API, while often accommodated by library updates, can sometimes introduce breaking changes requiring code migration. Always review the `pyTelegramBotAPI` changelog and Telegram Bot API release notes when upgrading, especially across significant version bumps.","severity":"breaking","affected_versions":"All versions, dependent on Telegram Bot API changes"},{"fix":"For replies, use `reply_parameters` instead of `reply_to_message_id`. For web page previews, refer to the current Telegram Bot API documentation for `link_preview_options`.","message":"The `reply_to_message_id`, `allow_sending_without_reply`, and `disable_web_page_preview` parameters in `bot.send_message()` and similar methods have been deprecated by Telegram. While they might still function, it's recommended to use newer alternatives for reply parameters and link previews.","severity":"deprecated","affected_versions":"4.26.0 and higher"},{"fix":"For synchronous bots, ensure handlers are fast or delegate long tasks to separate threads/processes (e.g., by initializing `TeleBot(threaded=True)`). For I/O-bound tasks and better scalability, consider using `AsyncTeleBot` and `async`/`await` patterns consistently throughout your bot's logic.","message":"The library offers both synchronous (`telebot.TeleBot`) and asynchronous (`telebot.async_telebot.AsyncTeleBot`) implementations. Mixing them incorrectly or using `TeleBot` with long-running operations in handlers without threading can block your bot. `TeleBot`'s `infinity_polling()` is synchronous, while `AsyncTeleBot` typically uses `asyncio.run(bot.polling())`.","severity":"gotcha","affected_versions":"All 4.x versions"},{"fix":"Always use `message.from_user` to access information about the user who sent the message.","message":"The `Message` object received by handlers has its `from` attribute renamed to `from_user` (`message.from_user`) to avoid conflict with Python's `from` keyword. Directly accessing `message.from` will raise an `AttributeError`.","severity":"gotcha","affected_versions":"All 4.x versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}