Skip to main content

A python wrapper for bale api

Project description

pyrobaletext

Bale Bot API Python Library

A Python wrapper for the Bale Bot API that makes it easy to build Bale bots.

Features

  • Full Bale Bot API support
  • Object-oriented design
  • Easy-to-use interface
  • Support for:
    • Messages
    • Photos
    • Documents
    • Audio
    • Video
    • Voice messages
    • Location
    • Contact sharing
    • Inline keyboards
    • Menu keyboards
    • Callback queries
    • Chat administration
    • Payment system
    • Database integration

Installation

pip install pyrobale

Quick Start

from bale import Client, MenuKeyboardMarkup, MenuKeyboardButton

Initialize bot with token

bot = Client("YOUR_BOT_TOKEN")

Handle incoming messages

@bot.on_message def handle_message(message): if message.text == "/start": # Create keyboard keyboard = MenuKeyboardMarkup() keyboard.add(MenuKeyboardButton("Hello!"))

    # Send welcome message
    message.reply_message("Welcome!", reply_markup=keyboard)

Start the bot

bot.run()

Key Components

Client

The main class for interacting with Bale API. Handles all API requests and provides event decorators.

Message

Represents a message in Bale with methods for replying, editing, and deleting messages.

User

Represents a Bale user with their properties and methods.

Chat

Represents a chat conversation with methods for sending messages and managing chat settings.

Keyboards

  • MenuKeyboardMarkup: For creating text keyboards
  • InlineKeyboardMarkup: For creating inline keyboards

Database

Built-in SQLite database support for storing persistent data.

Event Handlers

Message handler

@bot.on_message def handle_message(message): pass

Callback query handler

@bot.on_callback_query def handle_callback(callback): pass

Periodic task handler

@bot.on_tick(60) # Runs every 60 seconds def handle_tick(): pass

Ready event handler

@bot.on_ready def handle_ready(): pass

Member join handler

@bot.on_member_chat_join def handle_join(message, chat, user): pass

Member leave handler

@bot.on_member_chat_leave def handle_leave(message, chat, user): pass

Database Usage

Access database

with bot.database as db:
    db.write_key("user_123", {"points": 100})
    
    data = db.read_key("user_123")

Running Multiple Bots

from bale import run_multiple_clients

bot1 = Client("TOKEN1")
bot2 = Client("TOKEN2")

run_multiple_clients(bot1, bot2)```


## License

This project is licensed under the MIT License - see the LICENSE file for details.

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

pyrobale-0.2.2.tar.gz (35.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyrobale-0.2.2-py3-none-any.whl (36.2 kB view details)

Uploaded Python 3

File details

Details for the file pyrobale-0.2.2.tar.gz.

File metadata

  • Download URL: pyrobale-0.2.2.tar.gz
  • Upload date:
  • Size: 35.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.11

File hashes

Hashes for pyrobale-0.2.2.tar.gz
Algorithm Hash digest
SHA256 4927c46af8b7ce6e677b3e92d6e1bfbda14d0791235e20d43b737120b7209ca4
MD5 e932e7a92cff458b827bb27935f1afe5
BLAKE2b-256 5e63452ad66f774e9806d0f68993ec3d487f1834eedd128a004f2d76e18b7fb0

See more details on using hashes here.

File details

Details for the file pyrobale-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: pyrobale-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 36.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.11

File hashes

Hashes for pyrobale-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6cc8116fcd2a838aba0a62d37c9a32ca2afbfc32e3dd49ce3bf4c30d2078c122
MD5 bdceb1d6177a7ed20a0bfa2c2f3cf9be
BLAKE2b-256 54aca91c5f4b9382c531c99e1813c88e6f3ce22d5f10a498a0fe89650bd69dd2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page