Sans io telegram api with couple io backends
Project description
# Sans io implementation of telegram api
Tiny telegram bot-api wrapper library.
## Reasons
* [aiotg](https://github.com/szastupov/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 telegram `camelCase`.
* Polling `offset` handled for you via `get_updates` method.
* Handling timeout between requests automatically (via `delay` keyword-only argument).
* Use any io backend you want.
## Implementation
[Sans io](http://sans-io.readthedocs.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
``` python
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
loop = asyncio.get_event_loop()
loop.run_until_complete(aiohttp_example())
```
### Send files
``` python
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))
```
Tiny telegram bot-api wrapper library.
## Reasons
* [aiotg](https://github.com/szastupov/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 telegram `camelCase`.
* Polling `offset` handled for you via `get_updates` method.
* Handling timeout between requests automatically (via `delay` keyword-only argument).
* Use any io backend you want.
## Implementation
[Sans io](http://sans-io.readthedocs.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
``` python
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
loop = asyncio.get_event_loop()
loop.run_until_complete(aiohttp_example())
```
### Send files
``` python
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.1.0.tar.gz
(4.1 kB
view details)
Built Distribution
File details
Details for the file siotelegram-1.1.0.tar.gz
.
File metadata
- Download URL: siotelegram-1.1.0.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 205735760b25fa5b7e2c7b44349936a0a9f9b6c30307d6d49f9f42e448d36ca6 |
|
MD5 | ecb84275a1288e4fa7715c48db996543 |
|
BLAKE2b-256 | aeab8c4a96cdf2c744c6723df229ca4e5abb095bc5c065d66434f3d592587b2d |
File details
Details for the file siotelegram-1.1.0-py3-none-any.whl
.
File metadata
- Download URL: siotelegram-1.1.0-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2936cc59d9faf6f255760a554db657986ca66bde83cf4f643ec3ea74e4679e94 |
|
MD5 | 39e726ac17691e38a6a39efe3e539ec6 |
|
BLAKE2b-256 | d7da289be70db3d499829a60c028d3348c06a488ea03783749f6d2a9a14ddd70 |