From d65abf8b6f60b5514f1767ca41dcea48af793dc6 Mon Sep 17 00:00:00 2001 From: theGowda Date: Fri, 6 Dec 2024 02:19:49 +0530 Subject: [PATCH] updated docs for async usage --- README.rst | 10 ---------- docs/connect.rst | 9 ++++++++- docs/path.rst | 21 ++++++++++++++++++++- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/README.rst b/README.rst index 0a31955..6dc76ec 100644 --- a/README.rst +++ b/README.rst @@ -4,13 +4,3 @@ Documentation Documentation resides over at `readthedocs `_ -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')] diff --git a/docs/connect.rst b/docs/connect.rst index 4e5e774..1e82469 100644 --- a/docs/connect.rst +++ b/docs/connect.rst @@ -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 --------- diff --git a/docs/path.rst b/docs/path.rst index 44b173a..7604562 100644 --- a/docs/path.rst +++ b/docs/path.rst @@ -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 --- @@ -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 ------ @@ -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. @@ -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. @@ -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'})]