Skip to main content

A python package to communicate with mirth connects client api.

Project description

mirthpy

Python api wrapper for Mirth Connect

NOTE: This api wrapper is not totally complete with all of Mirth's REST api calls. If you have a request for a specific api call, please make an issue on GitHub.

Table of Contents

Installation

Setup

Usage

Supported Mirth API Calls

Installation

Use the package manager pip to install mirthpy.

pip install mirthpy

Setup

Config file must match the following:

{
    "instanceName": "{instance IP or DNS Name}",
    "credentials": {
        "username": "{username}", 
        "password": "{password}"
    }
}

alternatively you can provide the mirth instance (ip or domain name) and user/pass combo

service = MirthService(username="{username}", password="{password}", instance="{mirthInstance}")

Usage

import json
import mirthpy
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) #to supress ssl warning

config = json.load(open('config.json'))

service = MirthService(config)
service.open()  # to login and initialize any service variables

# Get channel names
namesAndIds = service.getChannelIdsAndNames()
for ni in namesAndIds.entry:
    print(f"{ni.string[1]} - {ni.string[0]}") # channelName - channelId

# Get Id by name
id = service.getChannelIdByName('Test Channel')

channel = service.getChannel(id)

print(channel.name)
print(channel.description)
print(channel.sourceConnector.transformer)

if type(channel.sourceConnector.properties) == JavaScriptReceiverProperties:
    # do stuff we'd know only a javascript reader would have
    script = channel.sourceConnector.properties.script

# Get multiple channels
channelIds = ["44dacc20-718a-490c-bfcf-82355ed9209d", "3bb08639-7725-4b1b-a2ac-13687101fe9b"]
c = service.getChannels(channelIds)

for channel in c.channels: print(channel.name)


# Get all channels
channels = service.getChannels()

for channel in channels.channels:
    print(f"{channel.name} - {channel.description}")


# get all enabled channels
enabledChannels = [channel for channel in channels.channels if channel.exportData.metadata.enabled == 'true']

# get only javascript readers
jReaders = [channel for channel in enabledChannels if type(channel.sourceConnector.properties) == JavaScriptReceiverProperties]

# get certain code templates
codeTemplates = service.getCodeTemplates(['0d42f17b-54a4-40c1-8e7b-b43c3eb1b433', '37139e86-88db-41fa-bf80-8c08456caa10'])

for ct in codeTemplates.codeTemplates:
    print(f"{ct.name} - {ct.id}")

# get all code templates
codeTemplates = service.getCodeTemplates()

for ct in codeTemplates.codeTemplates:
    print(f"{ct.name} - {ct.id}")
    code = ct.properties.find('code').text

service.close() # to log out and close any service related objects

Supported Mirth API Calls

Server

Mirth API Route mirthpy method Description
GET /server/version service.getVersion() Gets Mirth Instance version
POST /server/_generateGUID service.getGUID() Gets Mirth specific GUID for ids
GET /server/time service.getTime() Gets current Mirth Server time
GET /server/channelTags service.getTags() Gets all tags
GET /server/configurationMap service.getConfigurationMaps() Gets all configuration mappings

Events

Mirth API Route mirthpy method Description
/events service.getEvents(jsonParams) Gets mirth events, can specify what parameters to pass

Channel

Mirth API Route mirthpy method Description
POST /channels service.createChannel(channel) Creates a channel in mirth instance based on channel object
GET /channels service.getChannels(channelIds, pollingOnly, includeCodeTemplates) Get all channels or certain channels in criteria
GET /channels/{channelId} service.getChannel(channelId, includeCodeTemplates) Get a single channel
GET /channels/{channelId} service.getChannel(channelId, includeCodeTemplates) Get a single channel
GET /channels/idsAndNames service.getChannelIdsAndNames() Get all channel name and ids
GET /channels/idsAndNames service.getChannelIdByName(name) Get only the channel id based on channel name
POST /channels/{channelId}/_stop service.stopChannel(channelId) Stop specified channel
POST /channels/{channelId}/_start service.startChannel(channelId) Start specified channel

Channel Status

Mirth API Route mirthpy method Description
GET /channels/statuses service.getChannelStatus(channelIds, filter, includeUndeployed) Get Dashboard status of channels

Code Template Calls

Mirth API Route mirthpy method Description
GET /codeTemplates service.getCodeTemplates(codeTemplateIds) Get all or some Code Templates

Message Calls

Mirth API Route mirthpy method Description
GET /channels/{channelId}/messages service.getMessages(channelId, limit, includeContent, offset, startDate, endDate, status) Get messages by channelId with filtering options
GET /channels/{channelId}/messages/count service.getMessageCount(channelId, startDate, endDate, status) Get messages count by channelId with filtering options

Channel Deployment

Mirth API Route mirthpy method Description
POST /channels/_deploy service.deployChannels(channelIds, returnErrors) Deploy set of channels

Channel Statistics

Mirth API Route mirthpy method Description
GET /channels/statistics service.getChannelStatistics(channelIds, includeUndeployed, includeMetadataId, excludeMetaDataId, aggregateStates) Get Channel Statistics

Extensions (Commercial License)

Mirth API Route mirthpy method Description
GET /extensions/history/channels/{channelId}/snapshots service.getChannelHistory(channelId) Get Channel History
GET /extensions/history/channels/{channelId}/snapshots/{snapshotId} service.getSnapshot(channelId, snapshotId) Get Channel History Snapshot

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mirthpy-0.1.5.tar.gz (52.2 kB view details)

Uploaded Source

Built Distribution

mirthpy-0.1.5-py3-none-any.whl (40.7 kB view details)

Uploaded Python 3

File details

Details for the file mirthpy-0.1.5.tar.gz.

File metadata

  • Download URL: mirthpy-0.1.5.tar.gz
  • Upload date:
  • Size: 52.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for mirthpy-0.1.5.tar.gz
Algorithm Hash digest
SHA256 6bba9086d613893ea4fafe1a3602220647034ee664527bfcfa58a1d90d2f3c00
MD5 94cfa7781d1a99405cdbe34b50ec3e02
BLAKE2b-256 8829005256b589d10ab5f715cb3744fc71e2c0787ba23265f26194ec8461e437

See more details on using hashes here.

File details

Details for the file mirthpy-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: mirthpy-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 40.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for mirthpy-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 48208369a27d287462f83f926f12fba110a82d29812fd7ac7e1f798d42149411
MD5 2042ef9d7c0457d8bcb1d46019cee19c
BLAKE2b-256 5c29b9e34e5f6794846ccde20a4a003a38aabd5a5f10bb097ffb924c39b29901

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page