Skip to content
CheshireCaat edited this page Mar 6, 2020 · 2 revisions

Setting up the client instance

Before you begin, you need to initialize the client using the start() method. At the same time, remember to execute the close() method after completing the work so that the connection to the script is always interrupted.

This project supports the popular Python library asyncio. It means that you can work with the client asynchronously. If you prefer synchronous code, you can use methods like loop.run_until_complete() with coroutine as argument.

You can also put an instance of the event loop in the constructor of BasRemoteClient. But the client can work without it, since by default the loop is obtained from asyncio.get_event_loop().

import asyncio

from bas_remote import BasRemoteClient
from bas_remote import Options


async def main():
    client = BasRemoteClient(options=Options(script_name='TestRemoteControl'))
    
    # Initialize script (Required)
    await client.start()
    
    # Permorm any actions here     
 
    # Close client connection
    await client.close()


event_loop = asyncio.get_event_loop()
event_loop.run_until_complete(main())

Options object in client constructor contains properties that must be specified for working.

The name of the script is required. Login and password can not be specified only if the script is free and everyone can access it. If you do not change the working directory (options.working_dir), then data folder with the engine and scripts will be placed next to your executable file.

Client launch

start() method contains two main steps:

  • Starting the engine service (Download, unzip and run BAS)
  • Starting the socket service (Connect to WebSocket and other)

But engine initialization are performed only if the version of the BAS engine or the script itself has changed. That is, it usually takes less than 3-5 seconds to start the client.

Clone this wiki locally