mautrix

raw JSON →
0.21.0 verified Sat May 09 auth: no python

A Python 3 asyncio Matrix framework for building Matrix clients and application services. Current version 0.21.0 supports Python 3.10+. The bridge module is deprecated in favor of Go rewrites. Release cadence is irregular, roughly quarterly.

pip install mautrix
error ImportError: cannot import name 'Client' from 'mautrix' (unknown location)
cause Incorrect import path; Client is in the 'client' submodule.
fix
Use from mautrix.client import Client
error ModuleNotFoundError: No module named 'mautrix.crypto'
cause Missing optional dependencies; crypto requires libolm.
fix
Install with pip install mautrix[crypto]
error TypeError: __init__() missing 1 required positional argument: 'base_url'
cause Client constructor requires base_url argument.
fix
Initialize with Client('https://matrix.example.com')
error mautrix.errors.MatrixError: M_UNKNOWN_TOKEN
cause Invalid or expired access token.
fix
Set a valid access token: client.access_token = '...'
deprecated The `bridge` module is deprecated. All bridges are being rewritten in Go. See https://mau.fi/blog/2024-h1-mautrix-updates/
fix Migrate to Go-based bridges or use the client module directly.
breaking The `state_store` SQLAlchemy implementations were removed in v0.20.0.
fix Use the built-in file-based state store or implement your own.
breaking SQLite database URI format changed: `sqlite:///path.db` no longer works for relative paths. Use `sqlite:path.db` for relative, `sqlite:/path.db` for absolute.
fix Update your database URI accordingly.
gotcha Python 3.9 support was dropped in v0.20.4. Use Python >=3.10.
fix Upgrade Python to 3.10 or later.

Basic Matrix client syncing rooms

import asyncio
from mautrix.client import Client

async def main():
    client = Client("https://matrix.example.com")
    # Replace with actual access token
    client.access_token = "your_token_here"
    resp = await client.sync()
    print(resp.rooms)

asyncio.run(main())