ubii.node.connect module

class ubii.node.connect.connect(url=None, config: UbiiConfig = constants.GLOBAL_CONFIG, client_type: Type[UbiiClient] = client.UbiiClient, protocol_type: Type[P] = protocol_.DefaultProtocol)

Bases: Awaitable[UbiiClient[P]], AsyncContextManager[UbiiClient[P]], ContextManager[UbiiClient[P]], Generic[P]

Use this callable to easily get a running Ubi Interact Node. If you don’t want to change the node behaviour significantly, this is the go-to to connect with the master node.

Example

Use the default connect callable with defaults to connect to a master node. If connect uses a url argument, it takes precedence over the DEFAULT_SERVICE_URL of the config argument. If connect does not use a specific constants, the shared GLOBAL_CONFIG is used by default.

There are multiple ways to create the client with connect.

with Await expression

from ubii.node.connect import connect
import asyncio

async def main():
    global client
    client = await connect()
    assert client.id

    # do something with the client
    ...

asyncio.run(main())
class ClientFactory(*args, **kwargs)

Bases: Protocol

__call__(instance: connect, *, client_type: Type[UbiiClient], protocol_type: Type[P]) UbiiClient[P]

ClientFactory objects need to have this call signature

Parameters:
Returns:

A client using the protocol

__init__(url=None, config: UbiiConfig = constants.GLOBAL_CONFIG, client_type: Type[UbiiClient] = client.UbiiClient, protocol_type: Type[P] = protocol_.DefaultProtocol)
Parameters:
config: constants.UbiiConfig

reference to used config

client: client.UbiiClient[P]

Will be created with a callable from client_factories if it contains one for the client_type and protocol_type

default_create(*, client_type, protocol_type)

Simply instantiates the protocol_type (passing config as config), creates a client with this protocol, and sets the protocols client attribute

Parameters:
  • client_type

  • protocol_type

Returns:

the client using the protocol

client_factories: Dict[Tuple[Type[client.UbiiClient], Type[protocol.AbstractProtocol]], ClientFactory] = {(<class 'ubii.framework.client.UbiiClient'>, <class 'ubii.node.protocol.ResettableProtocol'>): <function connect.default_create>, (<class 'ubii.framework.client.UbiiClient'>, <class 'ubii.node.protocol.LegacyProtocol'>): <function connect.default_create>}