Python Mirth Client

Main module containing the MirthAPI class for interacting with a Mirth instance

class mirth_client.Channel(mirth: MirthAPI, id_: str)

Class corresponding to a Mirth channel

async get_info() ChannelModel

Get basic channel metadata from Mirth.

Returns

Channel metadata

Return type

ChannelModel

async get_message(id_: str, include_content: bool = True) Optional[ChannelMessageModel]

Get a specific channel message by ID

Parameters
  • id (str) – Message ID

  • include_content (bool, optional) – Include message content in response. Defaults to True.

Returns

Channel message object

Return type

Optional[ChannelMessageModel]

async get_messages(limit: int = 20, offset: int = 0, include_content: bool = False, status: Optional[List[str]] = None, params: Optional[Dict] = None) List[ChannelMessageModel]

Get a list of messages handled by the channel

Parameters
  • limit (int, optional) – Number of events to return. Defaults to 20.

  • offset (int, optional) – Offset of events list. Defaults to 0.

  • include_content (bool, optional) – Include message content in response. Defaults to True.

  • status (Optional[str], optional) – Filter by message status (e.g. ERROR). Defaults to None.

Returns

List of channel messages

Return type

List[ChannelMessageModel]

async get_statistics() ChannelStatistics

Get basic channel statistics from Mirth.

Includes number of messages that passed, errored etc.

Returns

ChannelStatistics API response

Return type

ChannelStatistics

async post_message(data: Optional[str] = None, raise_errors: bool = True, source_map: Optional[Dict[str, str]] = None) Optional[ChannelMessageModel]

Send a new message to the channel

Parameters

data (Optional[str], optional) – Raw data to send to the channel. Defaults to None.

Returns

Sent message ID

Return type

int

async preview_message(id_: str, params: Optional[Dict] = None) Optional[ChannelMessageModel]

Get a minimal representation of a channel message by ID

Parameters
  • id (str) – Message ID

  • include_content (bool, optional) – Include message content in response. Defaults to True.

Returns

Channel message object

Return type

Optional[ChannelMessageModel]

async reprocess_message(id_: str, replace: bool = False, filter_destinations: bool = False) Optional[ChannelMessageModel]

Reprocess a specific channel message by ID

Parameters
  • id (str) – Message ID

  • include_content (bool, optional) – Include message content in response. Defaults to True.

Returns

Channel message object

Return type

Optional[ChannelMessageModel]

class mirth_client.MirthAPI(url: str, verify_ssl: bool = True, timeout: Optional[int] = 5)

Class corresponding to a Mirth web API connection

channel(id_: Union[str, UUID]) Channel

Return an interactive Channel object

Parameters

id (str, UUID) – Channel GUID/UUID

Returns

Channel object

Return type

Channel

async channel_info() List[ChannelModel]

Get a list of all channel metadata on the Mirth instance.

Returns

List of Mirth channels

Return type

List[Channel]

async channel_statuses() List[DashboardStatusModel]

Get a list of all channel statuses on the Mirth instance.

Returns

List of Mirth channels

Return type

List[Channel]

async channels() List[Channel]

Get a list of interactive Channel objects on the Mirth instance.

Returns

Channel objects

Return type

List[Channel]

async close()

Close the API connection session

async event(id_: str) Optional[EventModel]

Get a specific Mirth event by ID

Parameters

id (str) – Event ID

Returns

Mirth Event object

Return type

Optional[EventModel]

async events(limit: int = 20, offset: int = 0, level: Optional[str] = None, outcome: Optional[str] = None, user_id: Optional[int] = None, name: Optional[str] = None) List[EventModel]

Get a paged list of all events on the Mirth instance.

Parameters
  • limit (int, optional) – Number of events to return. Defaults to 20.

  • offset (int, optional) – Offset of events list. Defaults to 0.

  • level (Optional[str]) – Mirth event LEVEL to filter by. Defaults to None.

  • outcome (Optional[str]) – Searches on whether the event outcome was successful or not. Defaults to None.

  • user_id (Optional[int]) – The user ID to query events by. Defaults to None.

  • name (Optional[str]) – Searches the event name for this string. Defaults to None.

Returns

List of Mirth events

Return type

List[EventModel]

async get(url: str, **kwargs) Response

Send a GET request to the API instance

Parameters

url (str) – Relative URL to the resource

Returns

API response

Return type

httpx.Response

async groups() List[ChannelGroup]

Get a list of Channel groups on the Mirth instance. Includes IDs of channels within each group.

Returns

List of channel groups

Return type

List[ChannelGroup]

async login(user: str, password: str) LoginResponse

Log in to the Mirth instance

Parameters
  • user (str) – Mirth username

  • password (str) – Mirth password

Raises

MirthLoginError – Unable to login due to bad connection or incorrect credentials

Returns

API login response

Return type

LoginResponse

async post(url: str, content_type: Optional[str] = None, **kwargs) Response

Send a POST request to the API instance

Parameters
  • url (str) – Relative URL to the resource

  • content_type (Optional[str], optional) – Request content type. Defaults to None.

Returns

API response

Return type

httpx.Response

async statistics() List[ChannelStatistics]

Get a list of all channel statistics on the Mirth instance.

Returns

List of Mirth channel statistics

Return type

List[Channel]

class mirth_client.channels.Channel(mirth: MirthAPI, id_: str)

Class corresponding to a Mirth channel

async get_info() ChannelModel

Get basic channel metadata from Mirth.

Returns

Channel metadata

Return type

ChannelModel

async get_message(id_: str, include_content: bool = True) Optional[ChannelMessageModel]

Get a specific channel message by ID

Parameters
  • id (str) – Message ID

  • include_content (bool, optional) – Include message content in response. Defaults to True.

Returns

Channel message object

Return type

Optional[ChannelMessageModel]

async get_messages(limit: int = 20, offset: int = 0, include_content: bool = False, status: Optional[List[str]] = None, params: Optional[Dict] = None) List[ChannelMessageModel]

Get a list of messages handled by the channel

Parameters
  • limit (int, optional) – Number of events to return. Defaults to 20.

  • offset (int, optional) – Offset of events list. Defaults to 0.

  • include_content (bool, optional) – Include message content in response. Defaults to True.

  • status (Optional[str], optional) – Filter by message status (e.g. ERROR). Defaults to None.

Returns

List of channel messages

Return type

List[ChannelMessageModel]

async get_statistics() ChannelStatistics

Get basic channel statistics from Mirth.

Includes number of messages that passed, errored etc.

Returns

ChannelStatistics API response

Return type

ChannelStatistics

async post_message(data: Optional[str] = None, raise_errors: bool = True, source_map: Optional[Dict[str, str]] = None) Optional[ChannelMessageModel]

Send a new message to the channel

Parameters

data (Optional[str], optional) – Raw data to send to the channel. Defaults to None.

Returns

Sent message ID

Return type

int

async preview_message(id_: str, params: Optional[Dict] = None) Optional[ChannelMessageModel]

Get a minimal representation of a channel message by ID

Parameters
  • id (str) – Message ID

  • include_content (bool, optional) – Include message content in response. Defaults to True.

Returns

Channel message object

Return type

Optional[ChannelMessageModel]

async reprocess_message(id_: str, replace: bool = False, filter_destinations: bool = False) Optional[ChannelMessageModel]

Reprocess a specific channel message by ID

Parameters
  • id (str) – Message ID

  • include_content (bool, optional) – Include message content in response. Defaults to True.

Returns

Channel message object

Return type

Optional[ChannelMessageModel]

mirth_client.channels.build_channel_message(raw_data: Optional[str], binary: bool = False, source_map: Optional[Dict[str, str]] = None) str

Builds a valid Mirth Channel message XML string from raw data

mirth_client.channels.raise_post_errors(received: ChannelMessageModel) None

Raise errors from Mirth POST response

Parameters

received (ChannelMessageModel) – Mirth POST response message

Raises

MirthPostError – If the Mirth POST response contains an error

Indices and tables