PyLabLib: Python package for device control and experiment automation

PyLabLib aims to provide support for device control and experiment automation. It interfaces with lots of different devices, including several different camera interfaces, translational stages, oscilloscopes, AWGs, sensors, and more. The interface is implemented in a natural way through Python objects, and is easy to understand. For example, here is a complete script which steps Thorlabs KDC101 stage by 10000 steps ten times, and each time grabs a frame with Andor iXon camera:

from pylablib.devices import Thorlabs, Andor  # import the device libraries
import numpy as np  # import numpy for saving

# connect to the devices
with Thorlabs.KinesisMotor("27000000") as stage, Andor.AndorSDK2Camera() as cam:
   # change some camera parameters
   cam.set_roi(0, 128, 0, 128, hbin=2, vbin=2)
   # start the stepping loop
   images = []
   for _ in range(10):
      stage.move_by(10000)  # initiate a move
      stage.wait_move()  # wait until it's done
      img = cam.snap()  # grab a single frame

np.array(images).astype("<u2").tofile("frames.bin")  # save frames as raw binary

The list of the devices is constantly expanding.

Additional utilities are added to simplify data acquisition, storage, and processing:

  • Simplified data processing utilities: convenient fitting, filtering, feature detection, FFT (mostly wrappers around NumPy and SciPy).
  • Universal multi-level dictionaries which are convenient for storing heterogeneous data and settings in human-readable format.
  • Assorted functions for dealing with file system (creating, moving and removing folders, zipping/unzipping, path normalization), network (simplified interface for client and server sockets), strings (conversion of various Python objects to and from string), and more.
  • Tools for GUI generation and advanced multi-threading built on top of Qt5 (still in development stage: the documentation is incomplete, and the interfaces can change in later versions)

The library only works on Python 3, and has been most extensively tested on Windows 10 with 64-bit Python. Linux is, in principle, supported, but devices which require manufacturer-provided DLLs (mostly cameras) might, potentially, have problems.


This is documentation for the newer 1.x version of the library. The older 0.x documentation can be found at .

Indices and tables