Skip to main content

Asynchronous library for Telegram bot API

Project description

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.10.5.tar.gz (31.5 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.10.5-py3-none-any.whl (37.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: aiotgbot-0.10.5.tar.gz
  • Upload date:
  • Size: 31.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.6

File hashes

Hashes for aiotgbot-0.10.5.tar.gz
Algorithm Hash digest
SHA256 88fee09f4ab6e44f445c17d8e63c1ce4a059643ca7dff6d44c131c8f0f79b225
MD5 afee37df5846031f509cc8fc29ad94d3
BLAKE2b-256 61c5b907b34dfe5f12c48fa4cbea428dd39e37c97ee770befae5bea8ca6fc8b0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aiotgbot-0.10.5-py3-none-any.whl
  • Upload date:
  • Size: 37.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.6

File hashes

Hashes for aiotgbot-0.10.5-py3-none-any.whl
Algorithm Hash digest
SHA256 9e6b8d7e220bbc34f8329a9a80db5ebb3a0f54b8491059d5fa9ca3eb5468dcbe
MD5 200911e224082cbddf5db8d12f548efe
BLAKE2b-256 db0c4e62311ddaeb431bf7c3e7b96784015983a9994911e6a5b94b962ebdf7d4

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