Sans io telegram api with couple io backends
Project description
Sans io implementation of telegram api
Tiny telegram bot-api wrapper library.
Reasons
- aiotg is framework, not library and have no proxy support.
- Raw api calls translation is better for understanding and will not break if telegram api will be changed.
snake_case
Features
- support both, sync and async ways to deal with io.
- Simple as telegram api is.
snake_case
api converted to telegramcamelCase
.- Polling
offset
handled for you viaget_updates
method. - Handling timeout between requests automatically (via
delay
keyword-only argument). - Use any io backend you want.
Implementation
Sans io implementation based on generators
for simplifying flow and holding state. siotelegram
have io backends based on:
- requests
- aiohttp
Installation
- sync:
python -m pip install siotelegram[requests]
- async:
python -m pip install siotelegram[aiohttp]
Examples
Common
import asyncio
import siotelegram
TOKEN = "token"
def requests_example():
api = siotelegram.RequestsTelegramApi(TOKEN, timeout=10)
response = api.get_updates()
print(response)
async def aiohttp_example():
async with siotelegram.AioHTTPTelegramApi(TOKEN, timeout=10) as api:
response = await api.get_updates()
print(response)
if __name__ == "__main__":
import time
# requests
requests_example()
time.sleep(1)
# aiohttp
asyncio.run(aiohttp_example())
Send files
import siotelegram
api = siotelegram.RequestsTelegramApi(TOKEN, timeout=10)
name = "capybara.jpg"
api.send_photo(chat_id=chat_id, caption="Hellow world!", files_=dict(photo=open(, "rb")))
# or from in-memory bytes
import pathlib
import io
data = pathlib.Path(name).read_bytes()
f = io.BytesIO(data)
f.name = name
api.send_photo(chat_id=chat_id, caption="Hellow world!", files_=dict(photo=f))
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
siotelegram-1.2.0.tar.gz
(4.9 kB
view details)
Built Distribution
File details
Details for the file siotelegram-1.2.0.tar.gz
.
File metadata
- Download URL: siotelegram-1.2.0.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 805796fd267c2ff93b318d3c513e206db1a510c3bef83ad3a8a84e92cd417d5f |
|
MD5 | efc2cd0b7cd35d38e8e7a0c247b477bd |
|
BLAKE2b-256 | 8cabb7382e94100b8c8269d05a2a52cc22968e5a2dcc1dc3d57272c3ee31bbee |
File details
Details for the file siotelegram-1.2.0-py3-none-any.whl
.
File metadata
- Download URL: siotelegram-1.2.0-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05aa995089434c5c59fdf9682b92a9e63dcee13dc98c110e4c245231de7bccda |
|
MD5 | 9659e1f908462b9c9e96f73037a3c138 |
|
BLAKE2b-256 | cc09316d2e626052a23959360e4ca45ec4be645cf603143bc1ed700b3b1308b3 |