Skip to main content

Modern asynchronous library for Telegram Bot API

Project description

Telegram Async

Python Version aiohttp License Downloads Code style: black Type checked Tests

An asynchronous Telegram API client library for Python, using aiohttp for efficient communication with Telegram servers.

๐Ÿ‘ค Author

Denys Ostrovskyi

๐Ÿ“‹ Table of Contents

โœจ Features

  • โœ… Fully asynchronous - uses async/await for maximum performance
  • โœ… Full Telegram Bot API 9.6 - complete coverage including:
    • ๐Ÿค– Managed Bots - Create and manage sub-bots
    • ๐Ÿ“Š Enhanced Polls - Multiple correct answers, revoting, descriptions
    • ๐Ÿ’ณ Paid Media - Premium content for Telegram Stars
    • ๐Ÿ”— Invite Links - Full management with limits/expiration
    • ๐Ÿ“Œ Pin/Unpin Messages - Complete pinning support
    • ๐Ÿšช Join Requests - Approve/decline membership
    • ๐Ÿ” Chat Permissions - Granular member control
    • ๐Ÿ‘‘ Admin Rights - Set/get administrator rights
  • โœ… Session management - automatic connection renewal
  • โœ… Webhook support - easy configuration for receiving updates
  • โœ… Multimedia sending - photos, videos, documents, audio
  • โœ… Inline and reply keyboards - interactive messages
  • โœ… Rate limiting - automatic adaptation to API limits
  • โœ… Full typing - support for IDEs and type checkers
  • โœ… Error handling - advanced retry system and exception handling
  • โœ… Multilingualism - support for different languages in bot responses
  • โœ… Middleware - request processing system
  • โœ… Unit tests - 36 tests with comprehensive coverage

๐Ÿ”ง Requirements

  • Python 3.7 or later
  • aiohttp >= 3.8.0
  • Telegram bot account (token from @BotFather)

๐Ÿ“ฆ Installation

Installation from PyPI

pip install telegram-async

Installation from Source

git clone https://github.com/Denba236/telegram-async.git
cd telegram-async
pip install -e .

Installation with Dev Dependencies

pip install -e ".[dev]"

๐Ÿš€ Quick Start

Minimal Bot

from telegram_async import Bot, Dispatcher, Router

TOKEN = "YOUR_BOT_TOKEN"

bot = Bot(token=TOKEN)
dp = Dispatcher(bot)
router = Router()

@router.command("start")
async def cmd_start(ctx):
    await ctx.reply("Hello! Use /help for commands.")

@router.message()
async def echo(ctx):
    await ctx.reply(ctx.text)

dp.include_router(router)

if __name__ == "__main__":
    dp.run_polling(bot)

๐Ÿ“š API Documentation

Full API documentation with examples for all 115+ methods:

  • API 9.6 Full Support Guide - Complete documentation for all new features:

    • ๐Ÿค– Managed Bots - Create and manage sub-bots
    • ๐Ÿ“Š Enhanced Polls - Multiple correct answers, revoting, descriptions
    • ๐Ÿ’ณ Paid Media - Premium content for Telegram Stars
    • ๐Ÿ”— Invite Links - Full management with limits/expiration
    • ๐Ÿ“Œ Pin/Unpin Messages - Complete pinning support
    • ๐Ÿšช Join Requests - Approve/decline membership
    • ๐Ÿ” Chat Permissions - Granular member control
    • ๐Ÿ‘‘ Admin Rights - Set/get administrator rights
  • Colored Buttons Guide - Guide for colored buttons (API 9.4+)

  • Migration Guide - How to migrate to new structure

  • Restructure Summary - Project improvements

๐Ÿ“– Usage Examples

Check out the examples/ directory for complete working examples:

  • examples/main.py - Basic echo bot
  • examples/examples_api_95.py - API 9.5 features
  • examples/examples_colored_buttons.py - Colored buttons guide
  • examples/examples_new_features.py - 20+ feature examples

Run any example:

python examples/main.py

๐Ÿงช Testing

# Run all tests
pytest

# Run with coverage
pytest --cov=telegram_async --cov-report=html

# Run specific test file
pytest tests/test_basic.py
pytest tests/test_api_96.py

# Run with verbose output
pytest -v

Test Results: 36 tests passing โœ…

๐Ÿ—๏ธ Project Structure

telegram_async/
โ”œโ”€โ”€ examples/              # All example files
โ”œโ”€โ”€ tests/                 # Test suite
โ”‚   โ”œโ”€โ”€ test_basic.py     # Basic tests
โ”‚   โ””โ”€โ”€ test_api_96.py    # API 9.6 tests
โ”œโ”€โ”€ docs/                  # Documentation
โ”‚   โ”œโ”€โ”€ API_96_FULL_SUPPORT.md
โ”‚   โ””โ”€โ”€ COLORED_BUTTONS_GUIDE.md
โ”œโ”€โ”€ telegram_async/        # Main package
โ”‚   โ”œโ”€โ”€ client/           # API client
โ”‚   โ”œโ”€โ”€ dispatcher/       # Dispatcher & Router
โ”‚   โ”œโ”€โ”€ exceptions/       # Exceptions
โ”‚   โ”œโ”€โ”€ filters/          # Filter system
โ”‚   โ”œโ”€โ”€ fsm/              # Finite State Machine
โ”‚   โ”œโ”€โ”€ handlers/         # Handler utilities
โ”‚   โ”œโ”€โ”€ keyboards/        # Keyboard builders
โ”‚   โ”œโ”€โ”€ middleware/       # Middleware
โ”‚   โ”œโ”€โ”€ telegram_types/   # Telegram types
โ”‚   โ”œโ”€โ”€ utils/            # Utilities
โ”‚   โ””โ”€โ”€ contrib/          # Community modules
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ MIGRATION_GUIDE.md
โ”œโ”€โ”€ RESTRUCTURE_SUMMARY.md
โ”œโ”€โ”€ pyproject.toml
โ””โ”€โ”€ .env.example

๐ŸŒ Multilingualism

The library supports internationalization (i18n):

from telegram_async.utils import I18n

i18n = I18n(locales_dir='locales', default_locale='en')

# In handler
@router.command("start")
async def cmd_start(ctx):
    greeting = await i18n.gettext(ctx.user_id, "Hello!")
    await ctx.reply(greeting)

๐Ÿค Contribution

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ†˜ Contact and Support

๐Ÿ“Š Statistics

  • Total Methods: 115+
  • API Version: 9.6 (Latest)
  • Test Coverage: 36 tests
  • Python Versions: 3.7+
  • External Dependencies: 1 (aiohttp)

Made with โค๏ธ by Denys Ostrovskyi

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_async-3.11.3.tar.gz (122.6 kB view details)

Uploaded Source

Built Distribution

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

telegram_async-3.11.3-py3-none-any.whl (138.8 kB view details)

Uploaded Python 3

File details

Details for the file telegram_async-3.11.3.tar.gz.

File metadata

  • Download URL: telegram_async-3.11.3.tar.gz
  • Upload date:
  • Size: 122.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for telegram_async-3.11.3.tar.gz
Algorithm Hash digest
SHA256 ffd0a39be7b9f708609809776d230591cdef5c744952df40da454e99e793a519
MD5 de5b3a55c01461594137367c1dee8efc
BLAKE2b-256 6979c8407162311ebeb5a55d4c9e13fbb41e1b234644c44ad02c8a23eec51d65

See more details on using hashes here.

File details

Details for the file telegram_async-3.11.3-py3-none-any.whl.

File metadata

File hashes

Hashes for telegram_async-3.11.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e6e5f2e74ad357e4701c34f64d296f33d068142d901324da270efcf62bb614ba
MD5 a2a9a56352da4251579f25f963d1dc59
BLAKE2b-256 b25efbd51d032dcc12c293e54ce50304ff3a9efdc790c4959bbd146d97e1fd4a

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