Skip to main content

Async Python client for the Mattermost REST API and WebSocket events.

Project description

MatterAio

Async Python client for the Mattermost REST API and WebSocket events.

MatterAio is intentionally small and explicit:

  • async-only
  • thin wrapper over Mattermost API v4
  • no hidden multi-step workflows
  • typed responses with Pydantic models

Installation

With pip:

pip install matteraio

With Poetry:

poetry add matteraio

With uv:

uv add matteraio

Quick Start

Create a bot token in Mattermost and pass it to MattermostClient.

import asyncio

from matteraio import MattermostClient


async def main() -> None:
    async with MattermostClient(
        base_url="https://mattermost.example.com",
        token="YOUR_BOT_TOKEN",
    ) as client:
        bot = await client.init_session()
        print(bot.username)

        team = await client.teams.get_by_name("engineering")
        channel = await client.channels.get_by_name(team.id, "town-square")

        post = await client.posts.create(
            channel_id=channel.id,
            message="Hello from matteraio",
        )

        thread = await client.posts.thread(post.id)
        users = await client.users.search("alice", team_id=team.id, limit=10)

        print(post.id, len(thread.posts), [user.username for user in users])


asyncio.run(main())

If you need login/password authentication instead of a bot token, construct the client without token and call client.users.login(...). Token changes inside one client instance are not supported; create a new client when credentials change.

WebSocket Handlers

Use routers and decorators to handle incoming WebSocket events.

from matteraio import MattermostEventDispatcher, MattermostWebSocketClient, PostedEvent

dispatcher = MattermostEventDispatcher()


@dispatcher.on(PostedEvent)
async def on_posted(event: PostedEvent) -> None:
    print(event.data.post.message)


async def main() -> None:
    async with MattermostWebSocketClient(
        base_url="https://mattermost.example.com",
        token="YOUR_BOT_TOKEN",
    ) as websocket:
        await dispatcher.start(websocket)

Documentation

  • Endpoint reference: REST docs split by Mattermost API area, plus WebSocket and handler references.

Development

Install development dependencies:

uv sync --all-groups

Run local checks:

uv run ruff format .
uv run ruff check .
uv run mypy src tests
uv run pytest

Run opt-in integration tests against a local Mattermost preview server:

docker compose -f docker-compose.integration.yml up -d
MATTERAIO_RUN_INTEGRATION=1 uv run pytest tests/integration -m integration
docker compose -f docker-compose.integration.yml down -v

Set MATTERAIO_BASE_URL to override the default integration server URL.

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

matteraio-1.0.0.tar.gz (27.2 kB view details)

Uploaded Source

Built Distribution

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

matteraio-1.0.0-py3-none-any.whl (27.2 kB view details)

Uploaded Python 3

File details

Details for the file matteraio-1.0.0.tar.gz.

File metadata

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

File hashes

Hashes for matteraio-1.0.0.tar.gz
Algorithm Hash digest
SHA256 8ce00c3368b0df543479b9e8e4d8173aac2cf0a15156aec257f5a1628721c1d5
MD5 cf971b070b8680b5b167cae1cca04b73
BLAKE2b-256 2df5fc51c317926dcc868b8d8b6a9838da73c5eefc351a8c56d07c8277f7a50f

See more details on using hashes here.

Provenance

The following attestation bundles were made for matteraio-1.0.0.tar.gz:

Publisher: publish.yml on Sergeydmitr/MatterAio

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

File details

Details for the file matteraio-1.0.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for matteraio-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 92b5cc6a4162ef02e1dc49c696cb26e6d8ac370ed150dae398df3e0c767f7d75
MD5 e9abde17963d496f7fa85706eb09ec94
BLAKE2b-256 fe0df693c82d642d1f303af403d4378013ddc254b2629e9989e1e22f5117247c

See more details on using hashes here.

Provenance

The following attestation bundles were made for matteraio-1.0.0-py3-none-any.whl:

Publisher: publish.yml on Sergeydmitr/MatterAio

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