Client Base Objects

Base class and options for API clients

class matterapi.client.base.ApiClientOptions(*, url: pydantic.networks.AnyHttpUrl, ws_url: pydantic.networks.AnyUrl = None, basepath: str = '/api/v4', auth: Optional[Union[matterapi.client.base.AuthLogin, matterapi.client.base.AuthToken]] = None, httpx_client_options: matterapi.client.base.HttpxClientOptions = None, debug: bool = False, ws_concurrent: bool = True, ws_reconnect_wait_time: int = 5, skip_response_parsing: bool = False)

Bases: pydantic.main.BaseModel

Options to be passed to a api client

auth: Optional[Union[matterapi.client.base.AuthLogin, matterapi.client.base.AuthToken]]

Authentication information for the client

Provide login information for tasks which require authentication. If set, this can be an instance of AuthLogin or AuthToken

basepath: str

API path. Usually you won’t need to change this

debug: bool

Set to true to enable debugging

httpx_client_options: Optional[matterapi.client.base.HttpxClientOptions]

Options to be passed to the underlying http client doing the actual requests

skip_response_parsing: bool

If this is set, responses will not be parsed into objects, but will be returned as raw httpx response

url: pydantic.networks.AnyHttpUrl

Mattermost base url

Example: https://localhost:8065

ws_concurrent: bool

Change handling behaviour of websocket messages

If set to true, websocket messages will be handled concurrently. This means that the loop will not wait until messages are handled but continue to wait/handle the next message. If set to false, messages will be handled sequentially. Handling of a new message only starts after the event_handler returns.

ws_reconnect_wait_time: int

The waiting time between re-connect attempts for websocket connections

ws_url: Optional[pydantic.networks.AnyUrl]

Mattermost websocket url

class matterapi.client.base.AuthLogin(*, login_id: str, password: str, mfa_token: str = None)

Bases: pydantic.main.BaseModel

Mattermost Auhentication Credentials

login_id: str

Login id for authentication

mfa_token: Optional[str]

MultiFactorAuthentication token

password: str

Password

class matterapi.client.base.AuthToken(*, token: str)

Bases: httpx.Auth, pydantic.main.BaseModel

Mattermost Auhentication Token

auth_flow(request)

Execute the authentication flow.

To dispatch a request, yield it:

` yield request `

The client will .send() the response back into the flow generator. You can access it like so:

` response = yield request `

A return (or reaching the end of the generator) will result in the client returning the last response obtained from the server.

You can dispatch as many requests as is necessary.

token: str

Bearer Authentication token

class matterapi.client.base.BaseClient(*, options: Union[matterapi.client.base.ApiClientOptions, Dict], active_token: str = None)

Bases: pydantic.main.BaseModel

Contains shared business logic of Sync and Async client for interacting with the mattermost api

active_token: Optional[str]

The currently active authentication token.

This will either be the token passed as :class:~AuthToken or the session token acquired through username/password based authentication. Used for websocket connections

options: Union[matterapi.client.base.ApiClientOptions, Dict]

Options to be passed to the client

classmethod set_logging_mode(value)
async start_ws(event_handler: Callable, relogin=False)

Start the websocket connection and pass messages to event_handler

Connects to the websocket, completes authentication, and handles incoming messages. Will automatically try to reconnect to the server on connection errors.

Parameters
  • event_handler – The message handler. Can be a function or coroutine. Get’s the message passed as argument

  • relogin – Set to True to run _login() after a connection error. This might be useful in case a session ends for username/password based logins and you need to acquire a new session token.

start_ws_sync(event_handler: Callable, relogin=False)

Same as .start_ws but wraps the async call to be called synchronously

class matterapi.client.base.HttpxClientOptions(*, timeout: Any = 10.0, verify: Union[bool, Any] = True, cert: Any = None, proxies: Dict = None, auth: Any = None, **extra_data: Any)

Bases: pydantic.main.BaseModel

Options for the httpx client

class Config

Bases: object

Pydantic config for class

arbitrary_types_allowed = True
extra = 'allow'
auth: Optional[Any]
cert: Optional[Any]
proxies: Optional[Dict]
timeout: Optional[Any]

Timeout for operations

verify: Union[bool, Any]

If and how TLS should be verified.