Skip to main content

A very simple Python package to send and receive Telegram messages

Project description

telegram-easy

PyPI version License: MIT Python 3.8+

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.
  • 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.

Usage

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)

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"))

Next steps

  • Add more features to get_updates.
  • Add more features to send_text_message.
  • Add CLI support.
  • Add image send/receive support.
  • If you have any suggestions, please open an issue.

License

MIT

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

telegram_easy-0.1.0.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

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

telegram_easy-0.1.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file telegram_easy-0.1.0.tar.gz.

File metadata

  • Download URL: telegram_easy-0.1.0.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for telegram_easy-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b0329315c88b5cb0dcfc8a1a1e8ffac4d046b58dd809fdb3e9ae16d6b81ff648
MD5 3743a723e67d8ede7051909fbbbdb57f
BLAKE2b-256 8a032ae1f0f9a5e2489b3846c269bb72ba722f7bf54a93a4f0beea34aeb28185

See more details on using hashes here.

File details

Details for the file telegram_easy-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: telegram_easy-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for telegram_easy-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8e4883a10f1c14d404a15162f51732dc50073e64adc95a7db38be7e05ebc1710
MD5 e2059e0b4d886d8afec04203434c2ad2
BLAKE2b-256 0f63972b0ad4698cb86f1e3f57576cea300327bc0a896193e1bc6d696e91ddb5

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