Skip to main content

Async HTTP client for Mattermost API

Project description

mm-async

Async HTTP client for Mattermost API with High-Level API support.

Features

  • Async/await with httpx
  • High-Level APIclient.users, client.teams, client.channels, client.posts
  • Type-safe — Pydantic models for all responses
  • Resilient — automatic retry with exponential backoff
  • Rate limit aware — respects Retry-After headers
  • SecureSecretStr for token storage, SSL verification warnings

Installation

pip install mm-async

Or with Poetry:

poetry add mm-async

Quick Start

from mm_async import AsyncMattermostClient

async def main():
    async with AsyncMattermostClient(
        url="https://mattermost.example.com",
        token="your-bot-token",
    ) as client:
        # Get current user
        me = await client.users.get_me()
        print(f"Bot: {me.username}")

        # Search users
        users = await client.users.search("john")

        # Send message
        post = await client.posts.create(
            channel_id="abc123",
            message="Hello from bot!"
        )

        # Create DM and send message
        dm = await client.channels.create_direct([me.id, users[0].id])
        await client.posts.create(dm.id, "Private message")

Configuration

Parameter Type Default Description
url str Mattermost server URL
token str Bot or User access token
verify_ssl bool True Verify SSL certificates
timeout float 30.0 Request timeout (sec)
connect_timeout float 10.0 Connection timeout (sec)

High-Level API

Namespace Methods Description
client.users 7 User operations (search, get, update)
client.teams 11 Team management (members, admins)
client.channels 15 Channel operations (create, members, DMs, search, admin listing)
client.posts 7 Messaging (create, thread, search)

See API Reference for complete method documentation.

Error Handling

from mm_async import (
    AsyncMattermostClient,
    MattermostAuthError,
    MattermostRateLimitError,
    MattermostNotFoundError,
)

async with AsyncMattermostClient(url=url, token=token) as client:
    try:
        user = await client.users.get_by_username("john")
        if user is None:
            print("User not found")
    except MattermostAuthError:
        print("Invalid token")
    except MattermostRateLimitError as e:
        print(f"Rate limited, retry after {e.retry_after}s")

Retry Logic

  • GET, DELETE — automatic retry with exponential backoff
  • POST, PUT — no retry (to avoid duplicates)
  • Retries on: 500, 502, 503, 504, 429 status codes
  • Respects Retry-After header for rate limits

Exceptions

Exception HTTP Code Description
MattermostError Base exception
MattermostAuthError 401 Invalid or expired token
MattermostForbiddenError 403 Insufficient permissions
MattermostNotFoundError 404 Resource not found
MattermostRateLimitError 429 Rate limit exceeded
MattermostServerError 5xx Server error
MattermostConnectionError Connection failed
MattermostValidationError Invalid input parameters

Documentation

Requirements

  • Python 3.11+
  • httpx >= 0.28.0
  • pydantic >= 2.0.0

License

MIT

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

mm_async-0.4.1.tar.gz (31.8 kB view details)

Uploaded Source

Built Distribution

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

mm_async-0.4.1-py3-none-any.whl (16.9 kB view details)

Uploaded Python 3

File details

Details for the file mm_async-0.4.1.tar.gz.

File metadata

  • Download URL: mm_async-0.4.1.tar.gz
  • Upload date:
  • Size: 31.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for mm_async-0.4.1.tar.gz
Algorithm Hash digest
SHA256 95a6b7f6ec66a8fe72d0fd8e7bf792adeb83f3d8e8222de39d9329c8bb6e93ea
MD5 51a954edad2858286b9bc4f7c3ee17cb
BLAKE2b-256 c6b94350d7c8b7e5ca80191682a3e4b20e7c5baa0898eb5d773b91068d1a3759

See more details on using hashes here.

File details

Details for the file mm_async-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: mm_async-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 16.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for mm_async-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 689b6e41866cbd54ec1980c709dddf75c2ade6a13e4a83e10f1fa08f578810dc
MD5 c616f178911902b4509ea5c6a6dcfba6
BLAKE2b-256 1eb27a42ae9123ae3687074538066f7edde88d7d97167691c5e0ac65be1c2bf0

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