A very simple Python package to send and receive Telegram messages
Project description
telegram-easy
A minimal, lightweight Python package to send and receive Telegram Bot messages, with both synchronous and asynchronous APIs.
Designed for simple automation and monitoring use cases where only basic Telegram Bot interactions are required.
For more advanced features, see the official Telegram Bot Python examples.
Features
- Send text messages to Telegram bots.
- Receive update messages.
- Synchronous and asynchronous APIs.
- Environment variable support for credentials.
- Command Line Interface (CLI).
- No external Telegram frameworks required.
Installation
pip install telegram-easy
Python version
- Python 3.8+
Configuration
Create a Telegram bot using BotFather and save your Bot Token.
Avoid hardcoding credentials. You can configure the package using environment variables:
export TELEGRAM_TOKEN="your_bot_token"
export TELEGRAM_CHAT_ID="your_chat_id"
If token or chat_id parameters are not explicitly provided, the package will try to read them from these variables.
Receive messages
Synchronous using environment variables (Recommended)
from telegram_easy import get_updates
updates = get_updates()
Synchronous with no environment variables (Not recommended)
from telegram_easy import get_updates
updates = get_updates(token="xxx")
print(updates)
Asynchronous using environment variables (Recommended)
import asyncio
from telegram_easy.aio import get_updates
updates = asyncio.run(get_updates())
print(updates)
Asynchronous with no environment variables (Not recommended)
import asyncio
from telegram_easy.aio import get_updates
updates = asyncio.run(get_updates(token="xxx"))
print(updates)
CLI using environment variables (Recommended)
telegram-easy get_updates
CLI with no environment variables (Not recommended)
telegram-easy get_updates --token XXX
Get the Chat ID
To get the chat_id id you have different methods.
The easiest method if you have access to the chat is to open the chat in Telegram Web and look in the URL:
https://web.telegram.org/a/#1234567890
In this case the chat_id is 1234567890.
If you don't have access to the chat or if the chat url does not have a number, you can use the following method. Send (or request the owner to send) manually a message to your bot from the Telegram App or Web, then run:
from telegram_easy import get_updates
updates = get_updates()
for update in updates.get("result", []):
chat_id = update["message"]["chat"]["id"]
user_name = update["message"]["from"].get("first_name", "Unknown")
print(f"User: {user_name}, Chat ID: {chat_id}")
Save that CHAT_ID to use it when sending messages to the bot.
Send a text message
Synchronous using environment variables (Recommended)
from telegram_easy import send_text_message
send_text_message(message="Hello World!")
Synchronous with no environment variables (Not recommended)
from telegram_easy import send_text_message
send_text_message(message="Hello World!", token="123",chat_id="1234")
Asynchronous using environment variables (Recommended)
import asyncio
from telegram_easy.aio import send_text_message
asyncio.run(send_text_message(message="Hello World!"))
Asynchronous with no environment variables (Not recommended)
import asyncio
from telegram_easy.aio import send_text_message
asyncio.run(send_text_message(message="Hello World!", token="123",chat_id="1234"))
CLI using environment variables (Recommended)
telegram-easy send_message "hello world"
CLI with no environment variables (Not recommended)
telegram-easy send_message "hello world" --token XXX --client_id XXX
Next steps
- Add image send/receive support.
- Add more features to get_updates.
- Add more features to send_text_message.
- If you have any suggestions, please open an issue.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file telegram_easy-0.1.1.tar.gz.
File metadata
- Download URL: telegram_easy-0.1.1.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3af55f563b62ed3e4ebdbb475b0f363f41e3e420fb60f18ef8e5b40fc91434d8
|
|
| MD5 |
87f43531f609390940aee18d3b34f7f1
|
|
| BLAKE2b-256 |
742abcc55aff80774b71e555257c0f41f3f2fdf128971a2b8bee2174364189a0
|
File details
Details for the file telegram_easy-0.1.1-py3-none-any.whl.
File metadata
- Download URL: telegram_easy-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
51a14d4d5fda6d285b09d5865d97c9bb16f587a5a46cbb0235f59d616cac7fb3
|
|
| MD5 |
1ccd6ebc7f389b959df36efa383089c0
|
|
| BLAKE2b-256 |
9cb9acb5d0fdbf5ccd591007b142cb3fc3f69477b3ba7b871e477b2b0836525a
|