Skip to content

Instance

Use discover to find Lablink instances on the network. The default address (https://127.0.0.1) points to the local server.

An Instance holds the server's address and optionally its metadata. Call get_info to fill in the name, version, and serial number.

Use login to start an authenticated Session.

from pypalmsens import lablink

local = lablink.Instance('https://127.0.0.1/')
info = await local.get_info()
# LablinkInfo(name=..., version=...)
session = await local.login('Alice', 'hunter2')

pypalmsens.lablink.Instance

Instance(address: str = 'https://127.0.0.1', port: int = 5000)

A reference to a Lablink instance.

Exposes basic metadata through properties and provides get_info to refresh that information. Use login for an authenticated session.

Parameters:

  • address

    (str, default: 'https://127.0.0.1' ) –

    The address of the instance (default is 'https://127.0.0.1').

  • port

    (int, default: 5000 ) –

    Port to use on the instance (default is 5000).

Methods:

  • get_info –

    Fetch instance metadata from the lablink server.

  • login –

    Start an authenticated session with this lablink instance.

  • register_new_user –

    Register a new user account.

Attributes:

  • address (str) –

    The address of the instance.

  • info (LablinkInfo | None) –

    Last fetched metadata, or None if not yet fetched.

Source code in src/pypalmsens/lablink/_instance.py
35
36
37
38
def __init__(self, address: str = 'https://127.0.0.1', port: int = 5000):
    self._address = address.rstrip('/')
    self._http = HttpClient(f'{self._address}/api/v1')
    self._info: LablinkInfo | None = None

address property

address: str

The address of the instance.

info property

info: LablinkInfo | None

Last fetched metadata, or None if not yet fetched.

May be stale or empty.

See get_info to (re)populate this.

get_info async

get_info() -> LablinkInfo

Fetch instance metadata from the lablink server.

Returns:

  • LablinkInfo –

    Instance metadata including name, version and serial number.

Source code in src/pypalmsens/lablink/_instance.py
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
async def get_info(self) -> LablinkInfo:
    """
    Fetch instance metadata from the lablink server.

    Returns
    -------
    LablinkInfo
        Instance metadata including name, version and serial number.
    """
    data = await self._http.get('/Home/GetInfo')
    self._info = LablinkInfo.from_wire(data.json())
    if not self._info.is_supported:
        msg = (
            f'LabLink instance at {self.address} reports version {self._info.version}. '
            f'This version of pypalmsens supports {SUPPORTED}. '
            'Calls may fail or behave unexpectedly. '
            'Upgrade pypalmsens or the LabLink server.'
        )
        warnings.warn(msg, stacklevel=2)

    return self._info

login async

login(name: str, password: str) -> Session

Start an authenticated session with this lablink instance.

Parameters:

  • name

    (str) –

    The username for authentication.

  • password

    (str) –

    The password for authentication.

Returns:

  • Session –

    A new session object for this instance.

Source code in src/pypalmsens/lablink/_instance.py
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
async def login(self, name: str, password: str) -> Session:
    """Start an authenticated session with this lablink instance.

    Parameters
    ----------
    name : str
        The username for authentication.
    password : str
        The password for authentication.

    Returns
    -------
    Session
        A new session object for this instance.
    """
    payload = AuthRequestModel(UserName=name, Password=password).model_dump()

    data = await self._http.post('/Auth/ApiKey', json=payload)
    auth = AuthResponseModel.model_validate(data.json())
    assert auth.Token
    self._http.set_token(auth.Token)
    return Session._from_http(self._http)

register_new_user async

register_new_user(name: str, password: str) -> None

Register a new user account.

Parameters:

  • name

    (str) –

    The username for authentication.

  • password

    (str) –

    The password for authentication.

Source code in src/pypalmsens/lablink/_instance.py
86
87
88
89
90
91
92
93
94
95
96
97
98
99
async def register_new_user(self, name: str, password: str) -> None:
    """
    Register a new user account.

    Parameters
    ----------
    name : str
        The username for authentication.
    password : str
        The password for authentication.
    """
    payload = AuthRequestModel(UserName=name, Password=password).model_dump()

    await self._http.post('/Auth/Register', json=payload)