Skip to main content

Async Python client for the Max messenger Bot API

Project description

python-max-bot

PyPI Python License: MIT

Async Python client for the Max messenger Bot API.

A thin, stable, Pydantic-modeled wrapper. No bot framework, no FSM, no middleware — just the API surface you need to send messages, upload attachments, and poll for updates.

Install

pip install python-max-bot

Quickstart

import asyncio
from max_bot_api import MaxClient

async def main():
    async with MaxClient(token="YOUR_BOT_TOKEN") as client:
        # Send a plain message
        await client.send_message(chat_id=42, text="Hello, Max!")

        # Send a message with an image
        with open("photo.jpg", "rb") as f:
            img = await client.upload_image(f.read(), filename="photo.jpg")
        await client.send_message(
            chat_id=42,
            text="<b>Look at this</b>",
            format="html",
            attachments=[img],
        )

asyncio.run(main())

What's in v0.1

Feature Status
Send / edit / delete messages
Long-poll updates (get_updates)
Image / video / audio / file uploads
Inline keyboards
Chat metadata (get_chat)
HTML and Markdown formatting
Typed exceptions per HTTP status
Auto-retry / backoff
Webhook subscription endpoints ⏳ v0.3+
Bot framework (handlers, FSM) ❌ out of scope

Errors

from max_bot_api import (
    MaxClient,
    MaxAuthError,
    MaxRateLimitError,
    MaxTransportError,
)

async with MaxClient(token=...) as client:
    try:
        await client.send_message(chat_id=42, text="hi")
    except MaxAuthError:
        # Bad token — surface to user
        ...
    except MaxRateLimitError as e:
        await asyncio.sleep(e.retry_after or 1)
    except MaxTransportError:
        # Network problem; retry your way
        ...

Retries

Retries are opt-in. Pass a RetryPolicy to the client constructor:

from max_bot_api import MaxClient, RetryPolicy

async with MaxClient(token, retry=RetryPolicy()) as client:
    await client.get_chat(42)               # retries on 5xx and transport errors
    await client.send_message(chat_id=42, text="hi")  # only retries on transport errors

The default policy: 3 attempts, exponential backoff (1s, 2s, 4s with ±25% jitter), capped at 30s per wait. Tune via RetryPolicy(max_attempts=..., backoff_initial=..., backoff_multiplier=..., backoff_max=..., jitter=...).

Read methods (get_messages, get_updates, get_chat, request_upload_url) retry on both transport errors and 5xx responses. Write methods (send_message, edit_message, delete_message, the upload POST) only retry on transport errors — a 5xx during a write could mean the server processed it, so blind retry could double-apply.

429 responses always retry. The library waits at least as long as the server's Retry-After header asks; backoff_max does not clamp the server's instruction.

Without retry=, behavior is identical to v0.1 — one attempt per call.

Built with Claude

This project is developed in collaboration with Claude, Anthropic's AI assistant — design, code, and tests. Commits are co-authored. The repo ships with a CLAUDE.md and .claude/settings.json so any contributor running Claude on the codebase picks up the same conventions automatically. See the v0.1 design for the full collaboration workflow.

Links

License

MIT — see LICENSE.

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

python_max_bot-0.2.0.tar.gz (22.3 kB view details)

Uploaded Source

Built Distribution

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

python_max_bot-0.2.0-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

Details for the file python_max_bot-0.2.0.tar.gz.

File metadata

  • Download URL: python_max_bot-0.2.0.tar.gz
  • Upload date:
  • Size: 22.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for python_max_bot-0.2.0.tar.gz
Algorithm Hash digest
SHA256 df48a051bb649c8781eddcf281810479f4f8e72ebe7171b338dc28e7b5f0e831
MD5 7f3f485a5b84312fb88d34a872a92c39
BLAKE2b-256 47b2660aefa3b30f716278f54326b17a3ae43a0144bb460230195835b7453502

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_max_bot-0.2.0.tar.gz:

Publisher: release.yml on Kitaeza/python-max-bot

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file python_max_bot-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: python_max_bot-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 17.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for python_max_bot-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9eae8771b1df497bdf9f570741856a56d418a345fc870e0d55753732776f2b0a
MD5 6dbf6efe44e9f3bbce8b1eb6bf5ca32c
BLAKE2b-256 79595cc1350c7d1be57a54f61f2fb341d2de3e724316cf041ec063d8cfc218b7

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_max_bot-0.2.0-py3-none-any.whl:

Publisher: release.yml on Kitaeza/python-max-bot

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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