Registry / http-networking / matrix-client

matrix-client

JSON →
library0.4.0pypypi✓ verified 85d ago

The `matrix-client` library is a Client-Server SDK for the Matrix protocol, providing functionality to interact with Matrix homeservers. It is currently at version 0.4.0 and releases are infrequent, often addressing breaking changes or incompatibilities with the Matrix protocol or Synapse homeserver.

pip install matrix-client
INSTALL
IMPORT
SIG · MATRIX-CLIENT
M
matrix-client
http-networkingpythonv0.4.0
Install
2.6s avg
Import
560ms
Disk
25MB
Pass rate
4/ 10
Env Coverage4 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.4.0 · 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
musl
glibc
py 3.10
4/8 runs
✓ 2.58s
py 3.11
4/8 runs
✓ 2.6s
py 3.12
4/8 runs
✓ 2.26s
py 3.13
4/8 runs
4/8 runs
py 3.9
4/8 runs
✓ 3.03s
25MB installed
● package 25MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

MatrixClient
from matrix_client.client import MatrixClient
Room
from matrix_client.room import Room
Typically accessed via MatrixClient methods, not directly instantiated.

This quickstart demonstrates how to log into a Matrix homeserver, join a room, send a message, and then log out. Ensure `MATRIX_HOMESERVER_URL`, `MATRIX_USERNAME`, `MATRIX_PASSWORD`, and `MATRIX_ROOM` environment variables are set or replaced with actual values.

import os from matrix_client.client import MatrixClient HOMESERVER_URL = os.environ.get('MATRIX_HOMESERVER_URL', 'https://matrix.org') USERNAME = os.environ.get('MATRIX_USERNAME', 'test_user') PASSWORD = os.environ.get('MATRIX_PASSWORD', 'test_password') ROOM_ID_OR_ALIAS = os.environ.get('MATRIX_ROOM', '#test:matrix.org') # Replace with a valid room try: # For matrix-client v0.4.0+, `use_authorization_header=True` is recommended # for better compatibility with modern Synapse versions. client = MatrixClient(HOMESERVER_URL, use_authorization_header=True) client.login(username=USERNAME, password=PASSWORD) print(f"Successfully logged in as {USERNAME}") # Try to join a room room = client.join_room(ROOM_ID_OR_ALIAS) print(f"Successfully joined room: {room.name} ({room.room_id})") # Send a message room.send_text("Hello from matrix-client Python SDK!") print("Sent a test message.") # Logout client.logout() print("Logged out.") except Exception as e: print(f"An error occurred: {e}") print("Ensure MATRIX_HOMESERVER_URL, MATRIX_USERNAME, MATRIX_PASSWORD, and MATRIX_ROOM are set correctly and are valid.")
Debug
Known issues
breakingOlder versions of `matrix-client` (prior to 0.4.0) are incompatible with Synapse homeservers running version 1.38.0 or newer, leading to connection issues or failed API calls.
fix
Upgrade to `matrix-client` v0.4.0 or newer. When initializing `MatrixClient`, it's recommended to set `use_authorization_header=True` for better compatibility with modern Synapse versions.
affects: <0.4.0
gotchaEnd-to-end encryption (E2E) support is experimental, disabled by default, and requires specific native `libolm` (v3.0.0+) and Python dependencies (`matrix-client[e2e]`) to be installed.
fix
First, install `libolm` (version 3.0.0 or higher) system-wide on your operating system. Then, install the Python E2E dependencies using `pip install matrix-client[e2e]`.
affects: 0.4.0+
deprecatedMany getter and setter methods (e.g., `get_name()`, `set_topic()`) were deprecated in v0.3.2 in favor of direct attribute access or alternative methods.
fix
Refer to the latest documentation for preferred ways to access and modify properties (e.g., `room.name` instead of `room.get_name()`), avoiding deprecated methods.
affects: 0.3.2+
deprecatedThe Matrix API endpoints `/initialSync` and `/events` were deprecated in v0.0.4, with `/sync` becoming the standard for event retrieval.
fix
Ensure your code uses the `/sync` API calls via the client's methods, rather than making direct calls to the deprecated endpoints, which may no longer be supported by homeservers.
affects: 0.0.4+
Errors
Common errors & fixes
matrix_client.client.MatrixRequestError: 403 Forbidden: Invalid homeserver or credentials.
This error often occurs when `matrix-client` prior to v0.4.0 attempts to connect to Synapse homeservers v1.38.0+ due to changes in authorization header handling, or simply incorrect login credentials.
fix
Upgrade to `matrix-client` v0.4.0 and initialize `MatrixClient(homeserver_url, use_authorization_header=True)`. Double-check your username and password.
ModuleNotFoundError: No module named 'olm'
You are attempting to use experimental End-to-End Encryption (E2E) features, but the necessary native `libolm` library and/or its Python wrapper have not been installed.
fix
First, install `libolm` (version 3.0.0 or higher) system-wide on your operating system. Then, install the Python E2E dependencies: `pip install matrix-client[e2e]`.
AttributeError: 'Room' object has no attribute 'get_name'
You are using a deprecated getter method (e.g., `get_name()`) that was removed or replaced by direct attribute access.
fix
Access the attribute directly (e.g., `room.name`) instead of using `room.get_name()`. Consult the library's documentation for current API methods.
Upgrade
Version history
0.4.0latest on PyPI · released Jul 26, 2021
Audit
Dependencies
libolmoptionalNative library required for experimental End-to-End Encryption (E2E) features. Must be installed system-wide (v3.0.0+).
Agent activity
28 hits · last 30 days
node
24
Amazon
1
OpenAI (training)
1
Resources
matrix-client — pip install matrix-client · libregistry