Python implementation of routeros api. This library uses semantic versioning. On major version things may break, so pin version in dependencies.
Before using this library, you need to create and connect to a socket. If using plain TCP socket, easiest way is to use socket.create_connection(). For SSL/TLS I'd recommend using ssl.warp_socket(connected_socket, ciphers='ALL')
as a bare minimum. This will work even when no certificate is set on remote device.
In [1]: from librouteros import login
In [2]: api = login(username='admin', password='abc', sock=connected_socket)
In [4]: api(cmd='/interface/print', stats=True)
Out[4]:
({'.id': '*1',
'bytes': '418152/157562',
'comment': '',
'disabled': False,
'drops': '0/0',
'dynamic': False,
'errors': '0/0',
'mtu': 1500,
'name': 'ether1',
'packets': '3081/1479',
'running': True,
'type': 'ether'},)
In [5]: api(cmd='/interface/print')
Out[5]:
({'.id': '*1',
'comment': '',
'disabled': False,
'dynamic': False,
'mtu': 1500,
'name': 'ether1',
'running': True,
'type': 'ether'},)
In [7]: api.close()
In [8]:
If you want to pass parameters that start with a dot character you can do it in this way:
params = {'disabled': True, '.id' :'*7'}
api(cmd='/ip/firewall/nat/set', **params)
Note that .id
must always be passed as read from API. They usually start with a *
followed by a number. Keep in mind that they do change across reboots. As a rule of thumb, always read them first.
Python booleans are converted according to this table:
python | direction | api |
---|---|---|
False | <- | false,no |
True | <- | true,yes |
False | -> | no |
True | -> | yes |
To submit a feature requests or a bug report, please use issues from within github. If you would like to submit a patch please contact author or use pull request.