Python implementation of Mikrotik RouterOS API protocol. This lib currently provides some helpers for communication with RouterOS, so it's not complete "api framework".
Example with login process and sending commands for receiving list of interfaces can be found here.
Lib helpers:
frommiktapi.sentenceimportsentence_pack, sentence_unpack, SentenceUnpackerfrommiktapi.helperimportSentenceParser, password_encode# encode command for router, returns byte stringsentence_pack(['/interface/print', '.tag=mytag', '?name=ether1']) # decode response from router if you have complete one sentence in appropriate format# returns tuple('!done', '.tag=mytag', '=disabled=true', ...)sentence_unpack(one_sentence_bytes)
# also you can decode sentences as you read bytes# unpacker is itarable object# returns tuple('!done', '.tag=mytag', '=disabled=true', ...) on each iterationunpacker=SentenceUnpacker()
whileTrue:
readed_bytes=sock.read(2048)
unpacker.feed(readed_bytes)
forsentenceinunpacker:
print(sentence)
# if you want to parse decoded sentence (tuple) in more readable view# returns tuple(REPLY_WORD, TAG_WORD, dict('disabled': True, ....))reply, tag, words=SentenceParser.parse_sentence(sentence, cast_int=True, cast_bool=True)
# to encode password for login process# challenge=from initial login responsepassword_encode(password, challenge)