Skip to main content

pure-teleapi

Pure declarative Telegram Bot API and implementation with Pydantic models and Protocol-based API definitions (both sync and async) with neat typehints and docstrings, generated directly from Telegram website docs, parser/generator is included.

Motivation

Get tired of dozens telegram libs with strange json-parsing stuff and a bunch of unnecessary bells and whistles? Me too, so please meet N+1th one.

No helpers, no handlers, no batteries included, only pure API models, pydantic-based, which, I believe, is golden standard for json parsing/converting now, abstract API protocols, fully typed and documented with well-formatted docstrings, and just few of lines of python magic to make it work with any of requests-like library, httpx implementation both sync and async is included as extra.

Features

  • Fully-generated from API docs (Bot API 8.3 from Feb 12, 2025).
  • Always is up-to-date, because parser/generator is included.
  • Full set of pydantic models for all of Telegram API objects.
  • Declarative protocols (both sync and async) for Telegram API methods.
  • All with neat well-formatted docstrings, so no need to check website, everything is in code.
  • Compatible both with pydantic v1/v2.
  • Can use any underlying requests-like lib, httpx-based implementation is included, both sync and async.
  • Supports upload from ordinary file-like objects (IOBased) (relied on files= parameter of underlying lib).
  • Async file io can be implemented by user.

Installation

To install with ready to use httpx-based implementation type

pip install pure-teleapi[httpx]

To install with no external dependencies (except pydantic)

pip install pure-teleapi

In this case it's a must to provide underlying transport, it's easy, just check teleapi/httpx_transport.py.

Quickstart

from teleapi.httpx_transport import httpx_teleapi_factory

bot = httpx_teleapi_factory("<BOT_TOKEN>", timeout=60)

offset = 0
while True:
    print("Waiting for updates...")
    updates = bot.getUpdates(offset=offset, timeout=50)
    for update in updates:
        bot.sendMessage(
            chat_id=update.message.chat.id,
            text="Yes " + (update.message.text or "??"),
        )
        offset = update.update_id + 1

Using parser/generator

If this lib becomes outdated, one can parse and generate updated version easily.

Clone repo, then type poetry install --with dev --all-extras and just run apigen/main.py.

teleapi.py will appear in .generated dir, check then copy it to teleapi package.

Because docs are human readable, some sort of adoptions in parser may be necessary.

Most difficulties are in parsing return type of the methods, so please check apigen.models.ApiType.parse_return_type() method.

Metadata

Release files for pure-teleapi 1.8.3

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

Source distribution (sdist)

Source distribution for pure-teleapi 1.8.3
File Size Uploaded
pure_teleapi-1.8.3.tar.gz 89.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pure-teleapi 1.8.3
File Interpreter ABI Platform
pure_teleapi-1.8.3-py3-none-any.whl Python 3 none any Details

Total release size: 178.4 kB

Release files / pure_teleapi-1.8.3.tar.gz

Download URL pure_teleapi-1.8.3.tar.gz
Size 89.0 kB
Tags Source
SHA-256 checksum
How to use checksums
17a4a0f9b4bd3e547e48bdce9ea889a2490ba9f05e415d631822dfdf3a5c668f
BLAKE2b-256 checksum
How to use checksums
80e1d9e7a3002849904273af542bc8fe4135753bfd687898f2e647fcc5412bc6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.9.12

Release files / pure_teleapi-1.8.3-py3-none-any.whl

Download URL pure_teleapi-1.8.3-py3-none-any.whl
Size 89.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e88ac3d5d1ecdb42955a1cca22114b6ca667009ace988fcc34eeacb44f8fe35c
BLAKE2b-256 checksum
How to use checksums
26d0a9becbd3987803f347ac88fb13144e32cbf16d0a8af47a06d8e3e545ed20
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.9.12

Release history Release notifications | RSS feed

This release

1.8.3 This release

2 release files

1.7.4

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