Skip to main content

Telegram Bot API - Python SDK (using aiohttp)

pytest asyncio, aiohttp Chat on Telegram Last Release

Simple and fast client to call rest-api endpoints api.telegram.org using aiohttp package.

View at: https://pypi.org/project/python-telegram-bot-api/

How to install

pip3 install python-telegram-bot-api

Usage

Main example:

import asyncio
from api_tgbot import TgBot, TgException


TGBOT_TOKEN = "12345:YOUR_TOKEN"
APP_HOSTNAME = "https://YOUR_HOSTNAME.ngrok.io"
CHAT_ID = 123456789  # your chat id

client_tgbot = TgBot(token=TGBOT_TOKEN)


async def main_async():
    try:
        response = await client_tgbot.setWebhook("{hostname}/tgbot/wh".format(hostname=APP_HOSTNAME))
        assert type(response) == bool
        assert response == True
    except TgException as e:
        print(e)

    try:
        sent_msg = await client_tgbot.sendMessage(CHAT_ID, "Hello from Telegram Bot!")
        assert sent_msg.chat.id == CHAT_ID
        print(sent_msg.text)
    except TgException as e:
        print(e)


if __name__ == "__main__":
    asyncio.run_until_complete(main_async())

Simple JSON-Example if you are not interested in pydantic models and want to use dict in answers:

import asyncio
from api_tgbot import TgBotJson


TGBOT_TOKEN = "12345:YOUR_TOKEN"
APP_HOSTNAME = "https://YOUR_HOSTNAME.ngrok.io"
CHAT_ID = 123456789  # your chat id

client_tgbot = TgBotJson(token=TGBOT_TOKEN)


async def main_async():
    response = await client_tgbot.setWebhook("{hostname}/tgbot/wh".format(hostname=APP_HOSTNAME))
    print(response.status)  # 200
    print(response.payload) # {'ok': True, 'result': True, 'description': 'Webhook was set'}

    response = await client_tgbot.sendMessage(CHAT_ID, "Hello from Telegram Bot!")
    print(response.status)  # 200
    print(response.payload) # {'ok': True, 'result': {'message_id': 786, 'from': {'id': ... } ... }


if __name__ == "__main__":
    asyncio.run_until_complete(main_async())

Docs

  1. How to publish pypi package Medium article in Russian

Dependencies

This package depends on devtud / pygramtic >= 0.2.0 package.

Disclaimer

This project and its author is neither associated, nor affiliated with Telegram in anyway. See License section for more details.

License

This project is released under the GNU LESSER GENERAL PUBLIC LICENSE License.

Metadata

Release files for python-telegram-bot-api 0.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-telegram-bot-api 0.0.7
File Size Uploaded
python-telegram-bot-api-0.0.7.tar.gz 7.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for python-telegram-bot-api 0.0.7
File Interpreter ABI Platform
python_telegram_bot_api-0.0.7-py3-none-any.whl Python 3 none any Details

Total release size: 23.1 kB

Release files / python-telegram-bot-api-0.0.7.tar.gz

Download URL python-telegram-bot-api-0.0.7.tar.gz
Size 7.2 kB
Tags Source
SHA-256 checksum
How to use checksums
a25dd5d1bb2b1a5b155506accc68791274787173373276bb4d18822b73966e93
BLAKE2b-256 checksum
How to use checksums
bec0951d4e828b22430feb466cf1c57398c50bc0214e1e5e85b7fff4a3bf5146
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.2.0 requests-toolbelt/0.8.0 tqdm/4.48.2 CPython/3.8.5

Release files / python_telegram_bot_api-0.0.7-py3-none-any.whl

Download URL python_telegram_bot_api-0.0.7-py3-none-any.whl
Size 16.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1775186caefd5906b27e321013873f3a30fce3f56ebcb2fef50e52ac577bbdbc
BLAKE2b-256 checksum
How to use checksums
32305e6054ba7373fccfe1ee7f67428d720920be5ae75c9d626ec00fe0539944
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.2.0 requests-toolbelt/0.8.0 tqdm/4.48.2 CPython/3.8.5

Release history Release notifications | RSS feed

This release

0.0.7 This release

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page