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.0.2.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.0.2-py3-none-any.whl (29.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: matteraio-1.0.2.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.0.2.tar.gz
Algorithm Hash digest
SHA256 60c4210fcd46a72e243e28d2c0511f657b30df5e64d856563efbd6fadb6d452c
MD5 f6908c9768abaa94ce57202e618a809e
BLAKE2b-256 5e5ba5a74a128a3a72c0b8b23410692a80743f3f12339368d73c52e72a1744ac

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: matteraio-1.0.2-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.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ed26901bbffad6fcf6ba2b03c10585eef4c1ba540274de82ff7bd4e7fd1425a5
MD5 a827a894ec454ea8bc9c108b28b48581
BLAKE2b-256 236c96e60e24bda560b1dd6c66e8832fe3686aaf35a86aa08c78f351c1b5270d

See more details on using hashes here.

Provenance

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