Guides

Importing a connector

Importing a connector with the SDK in Python.

Prerequisites

  1. Access to the UniteLabs platform.
  2. Have a thermocycler example connector deployed and connected to your tenant.

To install the thermocycler, follow the quickstart guide in the README of the demo thermocycler repository. Specify your tenants cloud endpoint in the connectors .env file to connect it to the platform. Ask your UniteLabs contact if you don't know your cloud endpoint.

Jupyter Notebook pre-setup

In the first code block of your jupyter notebook put the following (required for asynchronous code)

import asyncio
import nest_asyncio
nest_asyncio.apply()

Note:
In the following guide print(...) is used to output information. To get the outputs in the "Jupyter" format, use display(...) or place them without print or display at the end of a code block.

  1. An environment with an installed SDK (see local installation of the SDK).
  2. A thermocycler example connector deployed and connected to your tenant.

To install the thermocycler, follow the quickstart guide in the README of the demo thermocycler repository. Specify your tenants cloud endpoint in the connectors .env file to connect it to the platform. Ask your UniteLabs contact if you don't know your cloud endpoint.

Local python specific pre-setup

In the local installation of the SDK guide you created a project and a __main__.py. You can continue using that or a similar setup for this guide:

import asyncio
from dotenv import load_dotenv
# place new imports here


async def main():
    # place new code lines here in the main function

if __name__ == "__main__":
    load_dotenv()
    asyncio.run(main())
  1. An environment with an installed SDK (see local installation of the SDK).
  2. A thermocycler example connector deployed and connected to your tenant.

To install the thermocycler, follow the quickstart guide in the README of the demo thermocycler repository. Specify your tenants cloud endpoint in the connectors .env file to connect it to the platform. Ask your UniteLabs contact if you don't know your cloud endpoint.

Jupyter Notebook specific pre-setup

Install nest_asyncio which is required for asynchronous code execution in Jupyter.

Terminal
poetry add nest-asyncio

or

Terminal
pip install nest-asyncio

In the first code block of your jupyter notebook put the following import:

import asyncio
import nest_asyncio
nest_asyncio.apply()

Note:
In the following guide print(...) is used to output information. To get the outputs in the "Jupyter" format, use display(...) or place them without print() or display() at the end of a code block.

Get all available connectors

First, import the generic client class:

from unitelabs.sdk import Client

The information about available connectors can be accessed via the Client object.

    client = Client()
    print(await client.list_services())

The .list_services() method returns a tuple of all available connector objects. If you connected the Thermocycler demo and nothing else, it should look like this:

Terminal
(Thermocycler(client=<unitelabs.sdk.client.client.Client object at 0x106e70dc0>, id='daa46515-49bc-4a7d-944f-369732edde2e', name='Thermocycler'))

To connect to the instance of the connector, use the full name (including whitespace and special characters, like the name attribute in the output above):

client = Client()
thermocylcer = await client.get_service_by_name(name="Thermocycler")

Each connector also has a unique ID (uuid4), a name, as well as implemented modules. It is also possible to instantiate a client object of a connector by passing the id to the client.get_service() method by using the service_id parameter.

print(thermocycler.name)
print(thermocycler.id)
print(thermocycler.modules.keys())
Terminal
Thermocycler (2)
daa46515-49bc-4a7d-944f-369732edde2e
dict_keys(['sila_service', 'temperature_controller', 'door_controller'])

The modules contain the actions that can be called directly via the connector. Some connectors, like the thermocycler in this example, are simple and these actions are already enough to get started. Others, like liquid handling systems and robots, will require additional logic to be usable in a meaningful way. For that, UniteLabs offers additional packages for the SDK that include labware and liquid handling specific classes for deck building and other related tasks.


Copyright © 2024