Python Mattermost Driver

7.3.2 · active · verified Fri Apr 17

Mattermostdriver is a Python library providing a client for the Mattermost API. It enables developers to interact with Mattermost servers, manage users, channels, posts, and more. The current version is 7.3.2, and it maintains an active release cadence with regular updates and bug fixes.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `Driver`, log in using username/password (or token if provided via environment variable `MATTERMOST_TOKEN`), retrieve the current user's information, and then log out. Ensure your Mattermost server details and credentials are set as environment variables or passed directly to the Driver constructor.

import os
from mattermostdriver import Driver

# Configure driver with environment variables or provide directly
driver = Driver({
    'url': os.environ.get('MATTERMOST_HOST', 'localhost'),
    'login_id': os.environ.get('MATTERMOST_LOGIN_ID', 'user@example.com'),
    'password': os.environ.get('MATTERMOST_PASSWORD', 'yourpassword'),
    'scheme': os.environ.get('MATTERMOST_SCHEME', 'https'),
    'port': int(os.environ.get('MATTERMOST_PORT', 443)),
    'verify': os.environ.get('MATTERMOST_VERIFY_SSL', 'true').lower() == 'true',
    'token': os.environ.get('MATTERMOST_TOKEN', '') # Optional: for token-based auth
})

try:
    driver.login()
    current_user = driver.users.get_current_user()
    print(f"Successfully logged in as: {current_user['username']} (ID: {current_user['id']})")
    # Example: Get system info
    # info = driver.system.get_ping()
    # print(f"Mattermost Server Status: {info}")

except Exception as e:
    print(f"Login failed: {e}")
finally:
    if driver.is_connected():
        driver.logout()
        print("Logged out.")

view raw JSON →