A Python library for interfacing with various laboratory instruments through GPIB/VISA connections
Project description
Lab Instrument Library
A Python library for interfacing with laboratory instruments through GPIB/VISA connections. Control multimeters, oscilloscopes, power supplies, SMUs, and more with a unified, Pythonic API.
Born from real-world lab experience - this library supports the common instruments you'll find in professional electronics and research labs, curated from years of hands-on testing and characterization work.
Quick Start
from pylabinstruments import Multimeter
# Auto-detect and connect to any supported multimeter
dmm = Multimeter("GPIB0::15::INSTR")
voltage = dmm.measure_voltage()
print(f"Measured: {voltage} V")
dmm.close()
Supported Instruments
Multimeters (4 models)
- HP 34401A
- Keithley 2000
- Keithley 2110
- Tektronix DMM4050
Source Measure Units (SMUs) (3 models)
- Keysight B2902A (2-channel, advanced features)
- Keithley 228
- Keithley 238
Power Supplies (5 models)
- Agilent E3631A (Triple output)
- Agilent E3632A (Single output)
- Keysight E3649A (Dual output)
- Keysight E36313A (Triple output)
- Keysight E36234A (Quad output)
Oscilloscopes (4 series)
- Tektronix TDS1000/2000 Series
- Tektronix DPO/MSO2000 Series
- Tektronix MDO3000 Series
- Tektronix TBS1000 Series
Other Instruments
- Function Generators: Tektronix AFG3000 series
- Network Analyzers: Agilent/Keysight E5061B
- Temperature Controllers: Thermonics T-2500SE, T-2420, X-Stream 4300
- Temperature Sensors: Thermocouples, Thermometers
Installation
# Clone the repository
git clone https://github.com/rothenbergt/pylabinstruments.git
cd pylabinstruments
# Install in development mode
pip install -e .
# Optional: Install with GUI utilities
pip install -e ".[gui]"
# Optional: Install with development tools
pip install -e ".[dev]"
Requirements:
- Python 3.10+
- PyVISA and a VISA backend (NI-VISA or Keysight IO Libraries)
- NumPy, Pandas, Matplotlib, Pillow (installed automatically)
Usage Examples
Multimeter - Quick Measurements
from pylabinstruments import Multimeter
# Auto-detect instrument model
dmm = Multimeter("GPIB0::15::INSTR")
# Quick measurements
voltage = dmm.measure_voltage()
current = dmm.measure_current()
resistance = dmm.measure_resistance()
# Statistics from multiple readings
stats = dmm.measure_statistics("VOLT", samples=10)
print(f"Mean: {stats['mean']:.6f} V, StdDev: {stats['std_dev']:.6f} V")
dmm.close()
Power Supply - Set and Measure
from pylabinstruments import Supply
ps = Supply("GPIB0::26::INSTR", selected_instrument="E36313A")
# Set 3.3V with 500mA current limit on channel 1
ps.set_voltage(3.3, 0.5, channel=1)
ps.enable_output(channel=1)
# Measure actual output
v = ps.measure_voltage(channel=1)
i = ps.measure_current(channel=1)
print(f"Output: {v:.3f}V @ {i*1000:.1f}mA")
ps.disable_output(channel=1)
ps.close()
SMU - IV Characterization
from pylabinstruments.smu import KeysightB2902A
smu = KeysightB2902A("USB0::0x0957::0xCE18::MY51141974::INSTR")
# Perform voltage sweep and measure current
voltages, currents = smu.measure_iv_curve(
channel=1,
start_v=0,
stop_v=5,
points=50,
current_limit=0.1
)
smu.close()
Oscilloscope - Capture Waveform
from pylabinstruments.oscilloscope import TektronixTDS2000
scope = TektronixTDS2000("GPIB0::7::INSTR")
# Configure and capture
scope.auto_set()
scope.set_vertical_scale(1, 0.5) # Channel 1: 500mV/div
scope.set_horizontal_scale(0.001) # 1ms/div
# Acquire waveform data
time, voltage = scope.acquire(1)
# Save screenshot
scope.save_image("capture.png")
scope.close()
Temperature Control
from pylabinstruments.thermonics import Thermonics
tc = Thermonics("GPIB0::21::INSTR", selected_instrument="Thermonics T-2500SE")
# Set and monitor temperature
tc.set_temperature(-40)
temp = tc.get_temperature()
print(f"Current: {temp}°C")
# Return to ambient
tc.select_ambient()
tc.close()
Architecture
The library uses a base class pattern for consistency:
LibraryTemplate (base.py)
├── MultimeterBase → HP34401A, Keithley2000, Keithley2110, TektronixDMM4050
├── SMUBase → KeysightB2902A, Keithley228, Keithley238
├── OscilloscopeBase → TektronixTDS2000, TektronixDPO2000, ...
└── PowerSupplyBase → E3631A, E3632A, E36313A, ...
Key Features:
- 🎯 Common methods shared across instrument types
- 🔧 Model-specific capabilities when needed
- ✅ Parameter validation via decorators
- 🛡️ Consistent error handling
Development
Running Tests
# Run all tests
pytest
# Run with coverage
pytest --cov=pylabinstruments --cov-report=html
# Run specific test file
pytest tests/test_multimeter_factory.py -v
Git hooks and linting
This repo includes a pre-commit configuration using Ruff (lint + format).
Enable it locally:
pip install -e .[dev]
pre-commit install
# Run on all files once
pre-commit run --all-files
Ruff configuration lives in pyproject.toml. The hook auto-fixes where possible.
Project Structure
pylabinstruments/
├── pylabinstruments/ # Main package
│ ├── multimeter.py # Multimeter implementations
│ ├── smu.py # SMU implementations
│ ├── oscilloscope.py # Oscilloscope implementations
│ ├── supply.py # Power supply implementations
│ ├── base.py # Base classes
│ └── utils/ # Utilities and decorators
├── tests/ # Test suite
├── examples/ # Usage examples
└── docs/ # Documentation
Contributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes with tests
- Run the test suite (
pytest) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Documentation
- 📚 Full API Documentation: [Coming soon]
- 💡 More Examples: See the
examples/directory - 🐛 Issues & Bugs: GitHub Issues
Tip: All instrument classes include links to official programming manuals in their docstrings. Check the source code for SCPI command references!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pylabinstruments-0.1.0.tar.gz.
File metadata
- Download URL: pylabinstruments-0.1.0.tar.gz
- Upload date:
- Size: 64.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e592748db50dccb853d4c349916e08b32d08dd6b025a4400bf3a79663df731c4
|
|
| MD5 |
2799c114cd623e140d452e512b76d4a1
|
|
| BLAKE2b-256 |
cefc9f3fd535942dd07ff0f570b4a243fbc9f321c71fe71dc187efb04f9d7689
|
Provenance
The following attestation bundles were made for pylabinstruments-0.1.0.tar.gz:
Publisher:
publish.yml on rothenbergt/pylabinstruments
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pylabinstruments-0.1.0.tar.gz -
Subject digest:
e592748db50dccb853d4c349916e08b32d08dd6b025a4400bf3a79663df731c4 - Sigstore transparency entry: 601413850
- Sigstore integration time:
-
Permalink:
rothenbergt/pylabinstruments@6e10a0dc70b129be1a17bdfa73cb9b94462a8bfa -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/rothenbergt
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6e10a0dc70b129be1a17bdfa73cb9b94462a8bfa -
Trigger Event:
push
-
Statement type:
File details
Details for the file pylabinstruments-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pylabinstruments-0.1.0-py3-none-any.whl
- Upload date:
- Size: 69.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b4555c0c1d40619fcce48694451174d6dae48d16e3e26a8a5338a4fc18bcae44
|
|
| MD5 |
2f75d6c9784f5536b36070dff6531e88
|
|
| BLAKE2b-256 |
6d1c7ec474f8ef9ede74a315d0709e12ed5ca0c1372c27aa98da197ac8826666
|
Provenance
The following attestation bundles were made for pylabinstruments-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on rothenbergt/pylabinstruments
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pylabinstruments-0.1.0-py3-none-any.whl -
Subject digest:
b4555c0c1d40619fcce48694451174d6dae48d16e3e26a8a5338a4fc18bcae44 - Sigstore transparency entry: 601413855
- Sigstore integration time:
-
Permalink:
rothenbergt/pylabinstruments@6e10a0dc70b129be1a17bdfa73cb9b94462a8bfa -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/rothenbergt
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6e10a0dc70b129be1a17bdfa73cb9b94462a8bfa -
Trigger Event:
push
-
Statement type: