Skip to content

Commit

Permalink
updated docs for async usage
Browse files Browse the repository at this point in the history
  • Loading branch information
theGowda committed Dec 5, 2024
1 parent e61beeb commit d65abf8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
10 changes: 0 additions & 10 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,3 @@ Documentation
Documentation resides over at
`readthedocs <https://librouteros.readthedocs.io/>`_

Async Usage
connection = await async_connect(
host="127.0.0.1",
username="admin",
password="admin",
timeout=30
)

hotspot_user_path = connection.path('/ip/hotspot/user')
hotspot_users = [user async for user in hotspot_user_path.select('.id')]
9 changes: 8 additions & 1 deletion docs/connect.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@ Unencrypted

.. code-block:: python
from librouteros import connect
from librouteros import connect, async_connect
api = connect(
username='admin',
password='abc',
host='some.address.com',
)
# For async version use async_connect
api = await async_connect(
username='admin',
password='abc',
host='some.address.com',
)
Encrypted
---------
Expand Down
21 changes: 20 additions & 1 deletion docs/path.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ Get all
# This also will work, as well as anything else you can do with iterables
for item in interfaces:
print(item)
# async version
async for item in interfaces:
print(item)
# or you can use list comprehension
items = [item async for item in interfaces]
Add
---

Expand All @@ -34,6 +41,9 @@ Add
# Will return newly created .id
path.add(interface='ether1', address='172.31.31.1/24')
# async version
await path.add(interface='ether1', address='172.31.31.1/24')
Remove
------

Expand All @@ -42,6 +52,9 @@ Remove
# Pass each .id as an argument.
path.remove('*1', '*2')
# async version
await path.remove('*1', '*2')
.. note::

``.id`` change on reboot. Always read them first.
Expand All @@ -54,6 +67,9 @@ Update
params = {'disabled': True, '.id' :'*7'}
path.update(**params)
# async version
await path.update(**params)
.. note::

``.id`` change on reboot. Always read them first.
Expand All @@ -69,3 +85,6 @@ As a first argument, pass command that you wish to run without absolute path.
script = api.path('system', 'script')
# Will run /system/script/run with desired .id
tuple(script('run', **{'.id': '*1'}))
# async version
[item async for item in script('run', **{'.id': '*1'})]

0 comments on commit d65abf8

Please sign in to comment.