librouteros
raw JSON → 4.0.1 verified Mon Apr 27 auth: no python
Pure Python implementation of the MikroTik RouterOS API for managing RouterOS devices. Version 4.0.1, requires Python >=3.9. Release cadence is irregular.
pip install librouteros Common errors
error ModuleNotFoundError: No module named 'librouteros.api' ↓
cause In version 4.0.0, the API submodule was reorganized. connect() is now at the top level.
fix
Replace import with
from librouteros import connect. error AttributeError: module 'librouteros' has no attribute 'Login' ↓
cause The Login class was removed in version 4.0.0.
fix
Use the connect() function instead.
Warnings
breaking In version 4.0.0, the connect() function moved from librouteros.api to librouteros (top-level). Old imports will break. ↓
fix Use `from librouteros import connect` instead of `from librouteros.api import connect`.
breaking The Login class and related exceptions (LoginError) were removed. Use connect() which returns a connection object directly. ↓
fix Replace `api = Login(host, user, pass).get_instance()` with `api = connect(host=host, username=user, password=pass)`.
gotcha Resource paths (e.g., '/system/identity') must start with a slash. Omitting the slash returns empty results without error. ↓
fix Always prefix resource paths with '/'.
Imports
- connect wrong
from librouteros.api import connectcorrectfrom librouteros import connect - Login wrong
from librouteros.login import Logincorrectfrom librouteros import connect
Quickstart
from librouteros import connect
api = connect(
host=os.environ.get('ROUTEROS_HOST', ''),
username=os.environ.get('ROUTEROS_USER', 'admin'),
password=os.environ.get('ROUTEROS_PASS', ''),
)
print(api.get_resource('/system/identity').get())