Skip to main content

Asynchronous library for Telegram bot API

Project description

Latest PyPI package version License Downloads count

Key Features

  • Asyncio and aiohttp based

  • All Telegram Bot API types and methods supported

  • Bot API rate limit support

  • Both long polling and webhooks supported

  • Fully type annotated (PEP 484)

Installation

aiotgbot is available on PyPI. Use pip to install it:

pip install aiotgbot

Requirements

Using aiotgbot

from typing import AsyncIterator

from aiotgbot import (Bot, BotUpdate, HandlerTable, PollBot,
                      PrivateChatFilter, Runner)
from aiotgbot.storage_memory import MemoryStorage

handlers = HandlerTable()


@handlers.message(filters=[PrivateChatFilter()])
async def reply_private_message(bot: Bot, update: BotUpdate) -> None:
    assert update.message is not None
    name = (f'{update.message.chat.first_name} '
            f'{update.message.chat.last_name}')
    await bot.send_message(update.message.chat.id, f'Hello, {name}!')


async def run_context(runner: Runner) -> AsyncIterator[None]:
    storage = MemoryStorage()
    await storage.connect()
    handlers.freeze()
    bot = PollBot(runner['token'], handlers, storage)
    await bot.start()

    yield

    await bot.stop()
    await storage.close()


def main() -> None:
    runner = Runner(run_context)
    runner['token'] = 'some:token'
    runner.run()


if __name__ == '__main__':
    main()

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

aiotgbot-0.14.0.tar.gz (31.4 kB view details)

Uploaded Source

Built Distribution

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

aiotgbot-0.14.0-py3-none-any.whl (34.3 kB view details)

Uploaded Python 3

File details

Details for the file aiotgbot-0.14.0.tar.gz.

File metadata

  • Download URL: aiotgbot-0.14.0.tar.gz
  • Upload date:
  • Size: 31.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for aiotgbot-0.14.0.tar.gz
Algorithm Hash digest
SHA256 eddd2ea88a2a91a4af128b2d649a4d869b971443af9a3bda68f71ea5497058a5
MD5 09d36b5cb1fe5c708a2150eabef13434
BLAKE2b-256 a1a6b488e653392c40faebd7cfa1f87cf4041188621e3eb5d58e64192089a57a

See more details on using hashes here.

File details

Details for the file aiotgbot-0.14.0-py3-none-any.whl.

File metadata

  • Download URL: aiotgbot-0.14.0-py3-none-any.whl
  • Upload date:
  • Size: 34.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for aiotgbot-0.14.0-py3-none-any.whl
Algorithm Hash digest
SHA256 786a5ed497ddf2a4d149191593b655d7bc38f229d1ced8894d3e6de37c6c7867
MD5 689efdcb1197f5d35495419c7aaa4a2e
BLAKE2b-256 989aa44af09f673c89f247f5a48fd3cda35c712e110a27f2625b04daa62f36bd

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