Pure declarative Telegram Bot API and implementation with pydantic models and sync and async API Protocol.
Project description
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.
Argue
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 7.4 from May 28, 2024).
- 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.
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
Built Distribution
File details
Details for the file pure_teleapi-1.7.4.tar.gz
.
File metadata
- Download URL: pure_teleapi-1.7.4.tar.gz
- Upload date:
- Size: 80.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c291ac4ece09b3e7a61b59b2c3f0e4e202417030133afa54f3862a359c58d29 |
|
MD5 | 4a8faab59c1a5afb5ff94de0f7db53d0 |
|
BLAKE2b-256 | 955e689f501890e0f349bc007c2a9fe7cc103cdfc1cfea317452c68ff7e483cd |
File details
Details for the file pure_teleapi-1.7.4-py3-none-any.whl
.
File metadata
- Download URL: pure_teleapi-1.7.4-py3-none-any.whl
- Upload date:
- Size: 81.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76bd9d90f1409dc058200fa53f671258b88dfab2d0e61918255630c859b3b76e |
|
MD5 | dcd381b74cc46a98f7788b44a1c707bf |
|
BLAKE2b-256 | cfeeac485e8a430c0d9aec611b028597bc2ef67cdab8444f312be590c59c520b |