Crate matrix_sdk[][src]

Expand description

A Matrix client library written in Rust.

The matrix-sdk aims to be a general purpose client library for writing Matrix clients, bots, and other Matrix related things that use the client-server API to communicate with a Matrix homeserver.


Connecting and logging in to a homeserver is pretty starightforward:

use std::convert::TryFrom;
use matrix_sdk::{
    Client, SyncSettings, Result,
    ruma::{UserId, events::{SyncMessageEvent, room::message::MessageEventContent}},

async fn main() -> Result<()> {
    let alice = UserId::try_from("")?;
    let client = Client::new_from_user_id(alice.clone()).await?;

    // First we need to log in.
    client.login(alice.localpart(), "password", None, None).await?;

            |ev: SyncMessageEvent<MessageEventContent>| async move {
                println!("Received a message {:?}", ev);

    // Syncing is important to synchronize the client state with the server.
    // This method will never return.


More examples can be found in the examples directory.

Crate Feature Flags

The following crate feature flags are available:

  • encryption: Enables end-to-end encryption support in the library.
  • qrcode: Enables qrcode verification support in the library. This will also enable encryption. Enabled by default.
  • sled_cryptostore: Enables a Sled based store for the encryption keys. If this is disabled and encryption support is enabled the keys will by default be stored only in memory and thus lost after the client is destroyed.
  • markdown: Support for sending markdown formatted messages.
  • socks: Enables SOCKS support in reqwest, the default HTTP client.
  • sso_login: Enables SSO login with a local http server.
  • require_auth_for_profile_requests: Whether to send the access token in the authentication header when calling endpoints that retrieve profile data. This matches the synapse configuration require_auth_for_profile_requests. Enabled by default.
  • appservice: Enables low-level appservice functionality. For an high-level API there’s the matrix-sdk-appservice crate
  • anyhow: Support for returning anyhow::Result<()> from event handlers.

Enabling logging

Users of the matrix-sdk crate can enable log output by depending on the tracing-subscriber crate and including the following line in their application (e.g. at the start of main):


The log output is controlled via the RUST_LOG environment variable by setting it to one of the error, warn, info, debug or trace levels. The output is printed to stdout.

The RUST_LOG variable also supports a more advanced syntax for filtering log output more precisely, for instance with crate-level granularity. For more information on this, check out the tracing_subscriber documentation.


pub use bytes;
pub use reqwest;
pub use ruma;


Types and traits related for event handlers. For usage, see Client::register_event_handler.

Abstraction over an executor so we can spawn tasks under WASM the same way we do usually.


Cryptographic identities used in Matrix.

Common types for media content.

High-level room API

Generate and parse UUIDs.


Interactive verification for E2EE capable users and devices in Matrix.


The underlying room data structure collecting state for joined, left and invited rooms.

A member of a room.

An async/await enabled Matrix client.

Configuration for the creation of the Client.


Struct holding all the information that is needed to decrypt an encrypted file.

Configuration for requests the Client makes.

The underlying pure data structure for joined and left rooms.

The high-level RoomMember representation

A user session, containing an access token and information about the associated user account.

Store state changes and pass them to the StateStore.

Settings for a sync call.


Internal representation of errors.

An HTTP error, representing either a connection error or an error while converting the raw HTTP response into a Matrix response.


The local trust state of a device.

Enum controlling if a loop running callbacks should continue or abort.

Enum keeping track in which state the room is, e.g. if our own user is joined, invited, or has left the room.

State store specific error type.


Super trait that is used for our store traits, this trait will differ if it’s used on WASM. WASM targets will not require Send and Sync to have implemented, while other targets will.

Abstraction around the http layer. The allows implementors to use different http libraries.

Type Definitions

Result type of a pure HTTP request.

Result type of the rust-sdk.

Attribute Macros