laboratory
Sure-footed refactoring achieved through experimenting
What it is and what it does
Laboratory is a Python framework for running controlled experiments on refactored code in production. You define a control block (your existing, known-good code) and a candidate block (your new implementation), and Laboratory executes both in randomized order, compares their return values, records timing, catches exceptions in the candidate, and publishes results—while always returning the control value to the caller. This lets you gain confidence that a refactor is correct before fully committing to it, even in complex production environments with legacy data and high load.
The package is designed for critical code paths where correctness matters more than speed. You can ramp experiments up gradually by overriding the `enabled` method, customize comparison logic, add context for debugging, and implement your own `publish` method to send metrics and mismatches to monitoring systems. The main caveat is that code with side effects (database writes, state changes) is unsuitable because both branches will execute, potentially causing duplicate writes.
Use it for:
- Refactoring authorization or permission-checking logic in production while verifying the new code matches the old behavior.
- Gradually migrating from one database query strategy to another by running both and comparing results before switching fully.
- Testing a rewritten algorithm on real production data and load to catch edge cases that unit tests miss.
- Validating a new authentication method against the existing one without risking user lockouts.
- Ramping up a candidate implementation for only a subset of users or requests to limit blast radius if issues arise.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Laboratory lets you safely refactor critical code paths by running new and old implementations side-by-side in production, comparing their results, and collecting timing and error data without affecting the live control flow.
Yes, if you own critical code paths and want a structured way to validate refactors in production. The zero-dependency design and MIT license make it low-risk to add. However, the aging maintenance status (last release 2019) means you should verify it works with your target Python version and be prepared to maintain a fork if needed. Not suitable for code with side effects.
Install
laboratory on PyPI
pip
pip install laboratoryuv
uv add laboratorypoetry
poetry add laboratoryInstalling laboratory
Before you install
Low friction: pure Python wheel with no runtime dependencies. However, the package is aging—last release was 2019-05-05 and last commit 2025-12-22, so while not abandoned, it receives infrequent updates.
License in practice
MIT license (permissive) means you can use, modify, and distribute this package freely in commercial and private projects with minimal restrictions.
Quickstart
pip install laboratory
import laboratory
experiment = laboratory.Experiment()
experiment.control(old_func, args=[data])
experiment.candidate(new_func, args=[data])
result = experiment.conduct() # returns old_func's value
Code with side effects (database writes, file I/O, state mutations) will execute in both control and candidate branches, causing duplicated writes—unsuitable for such operations.
Verify before relying
- Whether the package still works reliably with modern Python versions beyond those listed in classifiers (3.6 was the latest in the original release metadata).
- Current state of the GitHub repository and whether maintenance is truly active despite the aging status flag.
Package facts
| License | MIT (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | aging — 2,658 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 174,049/month — #10,293 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: laboratory-1.0.2-py2.py3-none-any.whl
Tags
More Utilities packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
charset-normalizerDetects and normalizes text encoding from…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
PygmentsPygments is a syntax highlighter that colorizes…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
dvcDVC is a command-line tool for versioning data…
permissive · top 5,000 on PyPI
optimizely-sdkProvides A/B testing, feature flagging, and…
permissive · top 15,000 on PyPI
sagemaker-experimentsTracks machine learning experiments, trials,…
permissive · top 15,000 on PyPI
ropeRope is a Python refactoring library that…
copyleft · top 5,000 on PyPI
qiskit-experimentsQiskit Experiments provides tools for building,…
permissive · top 15,000 on PyPI
amplitude-experimentProvides server-side A/B testing and feature…
permissive · top 15,000 on PyPI
kaggle-environmentsKaggle Environments provides a framework for…
unclear · top 15,000 on PyPI
jsoncomparisonCompares two JSON-like objects and returns a…
permissive · top 5,000 on PyPI
haystack-experimentalProvides archived experimental features for…
permissive · top 15,000 on PyPI
pure-evalSafely evaluate Python AST nodes without…
permissive · top 1,000 on PyPI