Market LabDocs
Scripting V2 - PythonPlain Python Files

Python V2 with Docker

Deploy a local Python environment to Docker without writing a Dockerfile.

Market Lab reproduces your local Python environment inside Docker automatically. You do not need a Dockerfile or requirements.txt.

Deploy

Install your packages in a virtual environment beside the script:

python3 -m venv .venv
.venv/bin/python -m pip install numpy pandas matplotlib

Select Docker and run the script:

mlab daemon backend docker

mlab script run strategy.py \
  --python .venv/bin/python

On the first deployment, Market Lab:

  1. reads the Python version and installed packages from the selected environment;
  2. creates an isolated Linux environment with the same pinned package versions; and
  3. snapshots the strategy into the job directory before starting it.

Later jobs reuse that environment:

Python runtime 394af2a3f753 reused (80 packages)

Changing only strategy.py does not reinstall packages. Changing Python or any installed package creates a new runtime.

What is stored

Managed environments live under:

~/.market-lab/python-runtimes/<fingerprint>/

They survive daemon-container replacement because ~/.market-lab is mounted into the container. Market Lab currently captures every package installed in the selected environment, so keep the strategy environment focused.

Packages must be pinned distributions available from a package index. Editable installs, local paths, and direct URL dependencies are rejected with a clear error.

Backtests

Backtests run directly with the selected local interpreter and do not use mlabd:

mlab script backtest strategy.py \
  --python .venv/bin/python \
  --from 2026-07-15 \
  --to 2026-07-16

Inspect a live job

mlab script status <JOB_ID>
mlab script logs <JOB_ID> --follow

The status shows the Python version, runtime fingerprint, and package count. Use only Python packages and strategy code you trust.

On this page