matterlab_balances
matterlab_balances provides drivers for the balances used in the Matter Lab. It includes a serial driver for Sartorius balances and a network client for Mettler Toledo XPR/XSR balances, along with a small shared base interface for balance operations.
Supported Devices
Balance: shared abstract base classSartoriusBalanceMTXPRBalanceMTXPRBalanceDoors: door identifiers for the MT client
Installation
Install the package:
pip install matterlab_balances
For development:
pip install -e .[dev]
The package depends on:
matterlab_serial_devicerequestssudsjinja2pprp
Quick Start
Example with a Sartorius balance:
from matterlab_balances import SartoriusBalance
balance = SartoriusBalance(com_port="COM5")
print(balance.weigh(stable=False))
balance.tare(stable=False)
Example with an MT XPR/XSR balance:
from matterlab_balances import MTXPRBalance
from matterlab_balances.mt_balance import WeighingCaptureMode
balance = MTXPRBalance(host="192.168.1.1", port=8002, password="password")
value, unit, stable = balance.get_weight(capture_mode=WeighingCaptureMode.IMMEDIATE)
print(value, unit, stable)
balance.close_session()
Core API
The shared Balance interface exposes:
weigh(stable=True)tare(stable=True)
Device-specific classes add their own helpers:
SartoriusBalance: direct serial weighing and tare controlMTXPRBalance: session handling,get_weight(...),tare(...),zero(...), door control, and dosing-related operations
Testing
Simulation Tests
Simulation tests are the default validation layer and are safe for CI.
One-click run:
python examples/test_sim.py
Direct pytest run:
pytest tests/test_base_balance.py tests/test_sartorius_sim.py tests/test_mt_sim.py
Hardware Tests
Hardware tests are opt-in because real balances may not be reachable in every environment.
Available hardware test files:
tests/test_sartorius_real.pytests/test_mt_real.py
They are marked with @pytest.mark.real and are skipped unless --run-real is supplied.
Examples:
pytest tests/test_sartorius_real.py --run-real --com-port COM5
pytest tests/test_mt_real.py --run-real --host 192.168.1.1 --port 8002 --password password
You can also provide hardware configuration through environment variables:
BALANCE_COM_PORTBALANCE_HOSTBALANCE_PORTBALANCE_PASSWORD
Examples
The examples/ directory contains the recommended entry points:
examples/test_sim.py: one-click simulation-only test runnerexamples/real_devices.py: readable examples for Sartorius and MT balancesexamples/README.md: short guide to the examples directory
Development
Useful commands:
pytest
ruff check .
ruff format .
The default pytest configuration includes retries, timeouts, coverage output, and uses src as the import root for local development.
Package Layout
src/matterlab_balances/
base_balance.py
mt_balance.py
sartorius_balance.py
tests/
examples/
License
This project is distributed under the MIT License. See LICENSE for details.
Metadata
Release files for matterlab-balances 1.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| matterlab_balances-1.2.1.tar.gz | 48.7 kB | Without provenance | Details for matterlab_balances-1.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| matterlab_balances-1.2.1-py3-none-any.whl | Python 3 | none | any | Details for matterlab_balances-1.2.1-py3-none-any.whl |
Total release size: 93.3 kB
Release files / matterlab_balances-1.2.1.tar.gz
| Download URL | matterlab_balances-1.2.1.tar.gz |
|---|---|
| Size | 48.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3903a7f6fc2df89799765431062cb6d51a6346c35eab7047d4a2e7edab953fc7
|
|
BLAKE2b-256 checksum How to use checksums |
beb5d2941755d507d8eedbe7954bba2b07ec04b4d2f08137c21850cf590ca7fe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.13
|
Release files / matterlab_balances-1.2.1-py3-none-any.whl
| Download URL | matterlab_balances-1.2.1-py3-none-any.whl |
|---|---|
| Size | 44.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2ec77873d95c89ce860563e24df103c5e0875adc6f8d62708c5d0d8ffbb1b5db
|
|
BLAKE2b-256 checksum How to use checksums |
087f3defeca2be8af61275c947df5dca8abecd71b11c0d47d28390f4aff2f232
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.13
|
Security for matterlab-balances 1.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.