Skip to main content

Python implementation of MikroTik RouterOS API

Project description

Tests Latest PyPI version Supported Python Versions License

About

Python implementation of routeros api. This library uses semantic versioning. On major version things may break, so pin version in dependencies.

Usage

from librouteros import connect

api = connect(username='admin', password='abc', host='some.address.com')

For SSL/TLS you need to create a ssl.SSLContext instance and pass it to connect(). Bare minimal requirement for ssl to work (without certificates).

import ssl
from librouteros import connect

ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
ctx.set_ciphers('ADH')
api = connect(username='admin', password='abc', host='some.address.com', ssl_wrapper=ctx.wrap_socket, port=8729)

Api usage.

api(cmd='/interface/print', stats=True)
({'.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'},)

api(cmd='/interface/print')
({'.id': '*1',
'comment': '',
'disabled': False,
'dynamic': False,
'mtu': 1500,
'name': 'ether1',
'running': True,
'type': 'ether'},)

api.close()

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.

Booleans conversions

Python booleans are converted according to this table:

python

direction

api

False

<-

false,no

True

<-

true,yes

False

->

no

True

->

yes

Contributing

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.

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

librouteros-2.0.0.tar.gz (7.0 kB view details)

Uploaded Source

File details

Details for the file librouteros-2.0.0.tar.gz.

File metadata

  • Download URL: librouteros-2.0.0.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for librouteros-2.0.0.tar.gz
Algorithm Hash digest
SHA256 13d09baca53fa1c889b4c6a4c2720cfe5556569fdd9cdea0a1cba59dd619e903
MD5 8e2a60a6829308fb1f76d837b3cc08e5
BLAKE2b-256 04de3586a56bd2681fa246e910958fe91df7eb27384882e1511dfda6152ad7fb

See more details on using hashes here.

Supported by

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