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.

Pagination Helpers

Paginated list endpoints can be consumed page by page with the regular list(...) methods, or as async iterators when you want all items until Mattermost returns a short or empty page.

async for channel in client.channels.iter_all(team.id, per_page=100):
    print(channel.name)

async for post in client.posts.iter_channel(channel.id, per_page=100):
    print(post.message)

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.1.1.tar.gz (29.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.1.1-py3-none-any.whl (29.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: matteraio-1.1.1.tar.gz
  • Upload date:
  • Size: 29.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.1.1.tar.gz
Algorithm Hash digest
SHA256 b639a08daf7bd4219ec132e39485eb9d09ee6b3b25ddc995f6d431c1c9680144
MD5 df141bfeaeedc99173957db52ba5a7ff
BLAKE2b-256 4d5c4bd873e2a131c9edabbea1f84c613ac96b0fcc4712d3fec876db3ed70326

See more details on using hashes here.

Provenance

The following attestation bundles were made for matteraio-1.1.1.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.1.1-py3-none-any.whl.

File metadata

  • Download URL: matteraio-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 29.3 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.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 46680f681f7739cf9d50072cb5741ef8a0546282bd7b3594594aa02add2b6ebc
MD5 a92946909909befb51208b9f1fa767e4
BLAKE2b-256 6b0654a53832d709531b238d46548ab471a284d13810fa625b701532ce9cd7d5

See more details on using hashes here.

Provenance

The following attestation bundles were made for matteraio-1.1.1-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