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
connectcallable with defaults to connect to a master node. Ifconnectuses aurlargument, it takes precedence over theDEFAULT_SERVICE_URLof theconfigargument. Ifconnectdoes not use a specific constants, the sharedGLOBAL_CONFIGis 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]¶
ClientFactoryobjects need to have this call signature- Parameters:
instance – a
connectinstanceclient_type – a
UbiiClienttypeprotocol_type – a
AbstractProtocoltype
- 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:
url – URL of the master node, overwrites the
ubii.framework.constants.UbiiConfig.DEFAULT_SERVICE_URLof the usedconfigconfig – contains information like default topic for server configuration service call
client_type – a
UbiiClienttypeprotocol_type – a
AbstractProtocoltype
- config: constants.UbiiConfig¶
reference to used config
- client: client.UbiiClient[P]¶
Will be created with a callable from
client_factoriesif it contains one for theclient_typeandprotocol_type
- default_create(*, client_type, protocol_type)¶
Simply instantiates the
protocol_type(passingconfigasconfig), creates a client with this protocol, and sets the protocolsclientattribute- 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>}¶