mautrix.client package

Submodules

mautrix.client.client module

class mautrix.client.client.Client(*args, store: mautrix.client.store.ClientStore = None, **kwargs)[source]

Bases: mautrix.client.api.client.ClientAPI

Client is a high-level wrapper around the client API.

add_event_handler(event_type: mautrix.client.api.types.event.base.EventType, handler: Callable[NewType.<locals>.new_type, Awaitable[None]]) → None[source]

Add a new event handler.

Parameters:
  • event_type (EventType) – The event type to add. If not specified, the handler will be called for all event types.
  • handler (Callable[[Event[Union[MessageEvent, ReactionEvent, RedactionEvent, StateEvent, ReceiptEvent, PresenceEvent, TypingEvent, GenericEvent]]], Awaitable[None]]) – The handler function to add.
Return type:

None

call_handlers(event: NewType.<locals>.new_type, source: mautrix.client.client.SyncStream) → None[source]

Send the given event to all applicable event handlers.

Parameters:
Return type:

None

handle_sync(data: NewType.<locals>.new_type) → None[source]

Handle a /sync object.

Parameters:data (JSON[Union[str, int, float, None, Dict[str, _Forwardref], List[_Forwardref]]]) – The data from a /sync request.
Return type:None
on(var: Union[Callable[NewType.<locals>.new_type, Awaitable[None]], mautrix.client.api.types.event.base.EventType]) → Union[Callable[NewType.<locals>.new_type, Awaitable[None]], Callable[Callable[NewType.<locals>.new_type, Awaitable[None]], Callable[NewType.<locals>.new_type, Awaitable[None]]]][source]

Add a new event handler. This method is for decorator usage. Use add_event_handler() if you don’t use a decorator.

Parameters:var (Union[Callable[[Event[Union[MessageEvent, ReactionEvent, RedactionEvent, StateEvent, ReceiptEvent, PresenceEvent, TypingEvent, GenericEvent]]], Awaitable[None]], EventType]) – Either the handler function or the event type to handle.
Return type:Union[Callable[[Event[Union[MessageEvent, ReactionEvent, RedactionEvent, StateEvent, ReceiptEvent, PresenceEvent, TypingEvent, GenericEvent]]], Awaitable[None]], Callable[[Callable[[Event[Union[MessageEvent, ReactionEvent, RedactionEvent, StateEvent, ReceiptEvent, PresenceEvent, TypingEvent, GenericEvent]]], Awaitable[None]]], Callable[[Event[Union[MessageEvent, ReactionEvent, RedactionEvent, StateEvent, ReceiptEvent, PresenceEvent, TypingEvent, GenericEvent]]], Awaitable[None]]]]
Returns:If var was the handler function, the handler function is returned.

If var was an event type, a function that takes the handler function as an argument is returned.

Examples

>>> client = Client(...)
>>> @client.on(EventType.ROOM_MESSAGE)
>>> def handler(event: MessageEvent) -> None:
...     pass
remove_event_handler(event_type: mautrix.client.api.types.event.base.EventType, handler: Callable[NewType.<locals>.new_type, Awaitable[None]]) → None[source]

Remove an event handler.

Parameters:
Return type:

None

start(filter_data: Union[NewType.<locals>.new_type, mautrix.client.api.types.filter.Filter, None]) → _asyncio.Future[source]

Start syncing with the server. Can be stopped with stop().

Parameters:filter_data (Union[FilterID[str], Filter, None]) – The filter data or filter ID to use for syncing.
Return type:Future
stop() → None[source]

Stop a sync started with start().

Return type:None
class mautrix.client.client.SyncStream[source]

Bases: enum.Flag

An enumeration.

ACCOUNT_DATA = 64
EPHEMERAL = 32
INVITED_ROOM = 2
JOINED_ROOM = 1
LEFT_ROOM = 4
STATE = 16
TIMELINE = 8

mautrix.client.store module

class mautrix.client.store.ClientStore[source]

Bases: abc.ABC

ClientStore persists high-level client stuff.

next_batch
Return type:SyncToken[str]
class mautrix.client.store.MemoryClientStore(next_batch: Optional[NewType.<locals>.new_type] = None)[source]

Bases: mautrix.client.store.ClientStore

MemoryClientStore is a ClientStore implementation that stores the data in memory.

next_batch
Return type:Optional[SyncToken[str]]

Module contents