Install & Compatibility
Where this runs
tested against v2.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.645s · 22.6MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 3.1s · import 0.586s · 23MB
20MB installed
● package 20MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
MattermostAPI
✓ from mattermostwrapper import MattermostAPI
Initializes the Mattermost API client, logs in with credentials, retrieves available teams and channels, and demonstrates how to post a message to a specific channel. Ensure Mattermost server URL, login, password, and team name are correctly configured via environment variables for a runnable example.
import os
from mattermostwrapper import MattermostAPI
# Replace with your Mattermost instance details
MATTERMOST_URL = os.environ.get('MATTERMOST_URL', 'https://your-mattermost-instance.com/api/v4')
MATTERMOST_LOGIN = os.environ.get('MATTERMOST_LOGIN', 'your_username')
MATTERMOST_PASSWORD = os.environ.get('MATTERMOST_PASSWORD', 'your_password')
MATTERMOST_TEAM_NAME = os.environ.get('MATTERMOST_TEAM_NAME', 'your_team_name')
MATTERMOST_CHANNEL_ID = os.environ.get('MATTERMOST_CHANNEL_ID', 'your_channel_id') # Optional for direct posts
def main():
try:
m = MattermostAPI(MATTERMOST_URL, MATTERMOST_TEAM_NAME)
m.login(MATTERMOST_LOGIN, MATTERMOST_PASSWORD)
print("Successfully logged into Mattermost.")
# Example: Get teams
teams = m.get_teams()
print(f"Teams: {teams}")
# Example: Get channel listings for a team
if teams:
first_team_id = teams[0]['id']
# If MATTERMOST_TEAM_NAME is used above, you might need to get team_id dynamically
# For simplicity, if MATTERMOST_TEAM_NAME is set to a specific team name during MattermostAPI init,
# the internal methods should work with the associated team.
# If not, you'd need to find the team ID from 'teams'
print(f"Getting channels for team: {MATTERMOST_TEAM_NAME}")
channel_list = m.get_channel_listing(MATTERMOST_TEAM_NAME)
for channel in channel_list:
print(f" Channel: {channel['display_name']} (ID: {channel['id']})")
# Example: Post a message to a channel (requires channel_id)
if MATTERMOST_CHANNEL_ID:
message = "Hello from mattermostwrapper! This is a test message."
post_response = m.post_channel(MATTERMOST_CHANNEL_ID, message)
print(f"Message posted: {post_response['message']}")
else:
print("MATTERMOST_CHANNEL_ID not set. Skipping message post.")
except Exception as e:
print(f"An error occurred: {e}")
if __name__ == '__main__':
main()
Errors
Common errors & fixes
mattermostwrapper.exceptions.MattermostAPIError: Login Failed
Incorrect Mattermost URL, username, password, or the specified team name does not exist or is inaccessible.
fixVerify the `MATTERMOST_URL` (ensure it includes `/api/v4`), `MATTERMOST_LOGIN`, `MATTERMOST_PASSWORD`, and `MATTERMOST_TEAM_NAME` variables are correct and the user has permission to access the team. Test credentials manually via web interface.
No module named 'mattermostwrapper'
The `mattermostwrapper` package is not installed in the current Python environment.
fixRun `pip install mattermostwrapper` to install the library.
requests.exceptions.ConnectionError: HTTPSConnectionPool(...) Failed to establish a new connection
The Python environment cannot reach the Mattermost server URL, possibly due to network issues, incorrect URL, or firewall blocking.
fixCheck network connectivity from where the script is run to the Mattermost server. Verify the `MATTERMOST_URL` is correct and accessible (e.g., try `ping` or `curl` from the command line). Check firewall rules.
Upgrade
Version history
2.2latest on PyPI · released Feb 17, 2020
Audit
Dependencies
requestsrequiredUsed for making HTTP requests to the Mattermost API. While not explicitly listed in the project's PyPI metadata or README, it is a de facto dependency for most Python HTTP clients and is implied by the library's function.
Resources
No resource links recorded.