Session
A Session is an authenticated connection to a Lablink instance, obtained from Instance.login. The session is the main object for interacting with the Lablink: listing and claiming instruments, starting measurements, retrieving stored measurements, etc.
Some calls are cached. For example, Session.instruments holds the result of the most recent Session.list_instruments call. They may be stale or empty. Call those methods to refresh.
Claims are held until released. Use async with so the claim is released even if the measurement raises an exception:
instruments = await session.list_instruments()
instrument, *_ = instruments
async with await instrument.claim() as claim:
job = await claim.start_measurement(method=method)
measurement = await job # claim released here
data = await measurement.get_data()
To work with several instruments at once, use the batch methods on the session.
session.claim(instruments) returns an InstrumentClaimBatch and session.start_measurement(claims, method=...) one MeasurementJob per instrument:
instruments = await session.list_instruments()
async with await session.claim(instruments) as claims:
jobs = await session.start_measurement(claims, method=method)
refs = await asyncio.gather(*jobs) # claims released here
data = [await ref.get_data() for ref in refs]
Tip
Similarly named methods exist on both Session and Instrument. As a guideline, use Session for batch (multi-instrument) operations, use Instrument for single-instrument operations.
pypalmsens.lablink.Session
A session managing a connection to a Lablink instance.
Use Session.list_instruments to list instruments, Session.claim to claim them, and Session.start_measurement to run measurements.
Parameters:
-
(hoststr) –Base URL of the Lablink instance (e.g. 'lablink.example.com').
-
(tokenstr) –Token used to authenticate API calls.
-
(portint, default:5000) –Port for the API server, defaults to 5000.
Methods:
-
abort_measurement–Abort a running measurement and cancel job.
-
claim–Claim multiple instruments.
-
delete_measurements–Delete measurement data from Lablink.
-
delete_user–Delete a user by their identifier.
-
get_info–Fetch metadata for this instance.
-
get_instrument_info–Get info dictionary for currently attached instruments.
-
get_measurement–Fetch a specific measurement by its reference ID.
-
list_instruments–List currently attached instruments.
-
list_measurements–List all measurements.
-
list_users–Get list of users.
-
pause_measurement–Pause running measurements on the given jobs.
-
release–Release the given instruments back to Lablink.
-
resume_measurement–Resume a measurement that was previously paused.
-
skip_pre_measurement_stage–Skip the pre-measurement stage on the given measurement jobs.
-
start_measurement–Start a measurement on each of the claimed instruments.
-
start_workflow–Start a workflow on the given instruments.
Attributes:
-
info(LablinkInfo | None) –Last fetched metadata, or
Noneif not yet fetched. -
instrument_info(dict[str, dict[str, Any]]) –The instrument info from the most recent get_instrument_info call.
-
instruments(list[Instrument]) –The instruments from the most recent list_instruments call.
Source code in src/pypalmsens/lablink/_session.py
51 52 53 54 55 56 57 | |
info
property
info: LablinkInfo | None
Last fetched metadata, or None if not yet fetched.
Use get_info to (re)populate this.
instrument_info
property
The instrument info from the most recent get_instrument_info call.
May be stale or empty. Use list_instruments or get_instrument_info to update the cache.
instruments
property
instruments: list[Instrument]
The instruments from the most recent list_instruments call.
May be stale or empty. Use list_instruments or get_instrument_info update the cache.
abort_measurement
async
abort_measurement(jobs: Sequence[MeasurementJob]) -> None
Abort a running measurement and cancel job.
Parameters:
-
(jobsSequence[MeasurementJob]) –The measurement to abort.
Source code in src/pypalmsens/lablink/_session.py
383 384 385 386 387 388 389 390 391 392 393 394 395 396 | |
claim
async
claim(instruments: Sequence[Instrument], *, auto_release: bool = False) -> InstrumentClaimBatch
Claim multiple instruments.
The claim is held until you release it, or until the enclosing
async with block exits.
Parameters:
-
(instrumentsSequence[Instrument]) –The instruments to claim.
-
(auto_releasebool, default:False) –If True, the server releases the claims after measurement ends.
Returns:
-
claims(ClaimBatch) –A batch containing the instrument claims.
Source code in src/pypalmsens/lablink/_session.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
delete_measurements
async
delete_measurements(measurements: list[Measurement | str]) -> None
Delete measurement data from Lablink.
Measurements are deleted by their unique identifier (GUID),
either using the guid attribute from the Measurement instance or
directly as a string.
Parameters:
-
(measurementslist[Measurement | str]) –A list of measurements to delete. Each item in the list can be either an instance of
Measurementor a GUID string.
Source code in src/pypalmsens/lablink/_session.py
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 | |
delete_user
async
Delete a user by their identifier.
Users are deleted using their unique identifier (GUID),
either using the guid attribute from the UserInfo instance or
directly as a string.
Parameters:
-
(userUserInfo | str) –The identifier for the user to delete. This can be either an instance of UserInfo, or a GUID string.
Source code in src/pypalmsens/lablink/_session.py
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 | |
get_info
async
get_info() -> LablinkInfo
Fetch metadata for this instance.
Source code in src/pypalmsens/lablink/_session.py
82 83 84 85 86 | |
get_instrument_info
async
Get info dictionary for currently attached instruments.
Refreshes the instrument_info dictionary and caches it in-place.
Returns:
-
dict[str, dict[str, Any]]–A mapping from serial number to instrument info for each currently attached instrument.
Source code in src/pypalmsens/lablink/_session.py
114 115 116 117 118 119 120 121 122 123 124 125 126 | |
get_measurement
async
get_measurement(measurement: Measurement | str) -> Dataset | DataTree
Fetch a specific measurement by its reference ID.
Parameters:
-
(measurementMeasurementRef | str) –The measurement to fetch. Can be a MeasurementRef or its string ID.
Returns:
Source code in src/pypalmsens/lablink/_session.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | |
list_instruments
async
list_instruments() -> list[Instrument]
List currently attached instruments.
Refreshes the instruments list.
Returns:
-
list of Instrument–A list of currently attached instruments.
Source code in src/pypalmsens/lablink/_session.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
list_measurements
async
list_measurements() -> list[Measurement]
List all measurements.
Returns:
-
list of MeasurementRef–A list of measurement references.
Source code in src/pypalmsens/lablink/_session.py
188 189 190 191 192 193 194 195 196 197 198 199 | |
list_users
async
list_users() -> list[UserInfo]
Get list of users.
Returns:
-
users(list[UserInfo]) –List of user info
Source code in src/pypalmsens/lablink/_session.py
419 420 421 422 423 424 425 426 427 428 | |
pause_measurement
async
pause_measurement(jobs: Sequence[MeasurementJob]) -> None
Pause running measurements on the given jobs.
Parameters:
-
(jobsSequence[MeasurementJob]) –The measurement jobs to pause.
Source code in src/pypalmsens/lablink/_session.py
353 354 355 356 357 358 359 360 361 362 363 364 365 366 | |
release
async
release(instruments: Sequence[InstrumentClaim]) -> None
Release the given instruments back to Lablink.
Parameters:
-
(instrumentsSequence[InstrumentClaim]) –Claimed instruments to release.
Source code in src/pypalmsens/lablink/_session.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |
resume_measurement
async
resume_measurement(jobs: Sequence[MeasurementJob]) -> None
Resume a measurement that was previously paused.
Parameters:
-
(jobsSequence[MeasurementJob]) –The measurement jobs to resume.
Source code in src/pypalmsens/lablink/_session.py
368 369 370 371 372 373 374 375 376 377 378 379 380 381 | |
skip_pre_measurement_stage
async
skip_pre_measurement_stage(jobs: Sequence[MeasurementJob]) -> None
Skip the pre-measurement stage on the given measurement jobs.
Parameters:
-
(jobsSequence[MeasurementJob]) –The running measurements to skip the pre-stage of.
Source code in src/pypalmsens/lablink/_session.py
338 339 340 341 342 343 344 345 346 347 348 349 350 351 | |
start_measurement
async
start_measurement(instruments: Sequence[InstrumentClaim], *, method: MethodTypeCompatible) -> list[MeasurementJob]
Start a measurement on each of the claimed instruments.
Parameters:
-
(instrumentsSequence[InstrumentClaim]) –Instruments (claimed) to start measuremeents on.
-
(methodMethodTypeCompatible) –The measurement method to apply.
Returns:
-
list[MeasurementJob]–One job per instrument, each with an associated MeasurementJob.
Source code in src/pypalmsens/lablink/_session.py
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 | |
start_workflow
async
start_workflow(instruments: Sequence[InstrumentClaim], *, workflow: str) -> None
Start a workflow on the given instruments.
Parameters:
-
(instrumentsSequence[InstrumentClaim]) –The claimed instruments that will run the workflow.
-
(workflowstr) –Name of the workflow to start.
Source code in src/pypalmsens/lablink/_session.py
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 | |