Skip to main content

bot-storage

Storage - an object that allows you to save the states and data of users.
The storage.py file describes the abstract class BaseStorage, inheriting from which, you can implement your own storage (eg DBStorage or JSONStorage).
Such storages, however, will obviously not be more efficient than the already implemented RedisStorage.

Installation:

pip install bot-storage

Setting up

YourProject/tbot/storage.py

from os import getenv

from bot_storage.storage import RedisStorage


storage = RedisStorage(
    host=getenv('REDIS_HOST', 'localhost'),
    username=getenv('REDIS_USER', None),
    password=getenv('REDIS_PASSWORD', None)
)

YourProject/settings.py

from tbot.storage import storage


# Your storage for user states & data
BOT_STORAGE = storage

Start Redis

redis-server

Usage

For example YourProject/tbot/handlers.py

from telebot import types
from telebot.apihelper import ApiTelegramException
from tbot_base.bot import tbot

from .storage import storage as st


@tbot.message_handler(
    func=lambda msg: st.get_user_state(msg.from_user.id) == 'some_state#'
)
def send_faq_search(msg: types.Message):
    tbot.send_message(chat_id=msg.from_user.id, text='Hello!')

Release files for bot-storage 1.0.1

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

Source distribution (sdist)

Source distribution for bot-storage 1.0.1
File Size Uploaded
bot-storage-1.0.1.tar.gz 3.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bot-storage 1.0.1
File Interpreter ABI Platform
bot_storage-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 6.5 kB

Release files / bot-storage-1.0.1.tar.gz

Download URL bot-storage-1.0.1.tar.gz
Size 3.2 kB
Tags Source
SHA-256 checksum
How to use checksums
9eab0a36a4e7903822133567d3b2ae7b4a789c551773d45cc2977739e4cd2aac
BLAKE2b-256 checksum
How to use checksums
e66cfac7d50ab227fa45e6ee4d4739342b1613273d56ed1bd62f182412897f7d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

Release files / bot_storage-1.0.1-py3-none-any.whl

Download URL bot_storage-1.0.1-py3-none-any.whl
Size 3.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cadf76d22cd341bb1b23e8f4df9b3bc5bdbe715b9e3f4420a8dd7cf55480912c
BLAKE2b-256 checksum
How to use checksums
e7d67e7c9af87017e9141ebca88124848ea18ef6a541566dd1f5acd8c252f138
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

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