Here is a quick example for sending midi from pythonista. I am using MidiFire to process the messages as discussed here. https://audeonic.boards.net/thread/734/adding-scripting-languages-using-midifire. My midifire setup to send out midi consists of an osc block connected to an event monitor connected to a midi output block.
import socket
# addressing information of target
#fill in your ip and port
IPADDR = '127.0.0.1'
PORTNUM = 8051
# enter the data content of the UDP packet as hex
msg1 = bytearray([0x90, 0x40, 0x60])
msg2 = bytes.fromhex('903e70')
#or using variable for midi note message
midi_message = '903c50'
midi_packet = bytes.fromhex(midi_message)
# initialize a socket, think of it as a cable
# SOCK_DGRAM specifies that this is UDP
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 0)
# connect the socket, think of it as connecting the cable to the address location
s.connect((IPADDR, PORTNUM))
# send the command
s.send(midi_packet)
s.send(msg1)
s.send(msg2)
# close the socket
s.close()