Skip to main content

tenvstack

Machine learning and AI libraries for Python are big. Really big. Nobody wants to download and install multiple copies of PyTorch or CUDA if they can reasonably avoid it.

tenvstack is a fork of venvstacks that allows you to package Python applications and all their dependencies into a portable, deterministic format, without needing to include copies of these large Python frameworks in every application archive.

I made this fork because I use a project built around this approach in Tiles, and I wanted a place to adapt the tooling for that use case.

It achieves this by using Python's sitecustomize.py environment setup feature to chain together three layers of Python virtual environments:

  • "Runtime" layers: environment containing the desired version of a specific Python runtime
  • "Framework" layers: environments containing desired versions of key Python frameworks
  • "Application" layers: environments containing components to be launched directly

Application layer environments may include additional unpackaged Python launch modules or packages for invocation with python's -m switch.

While the layers are archived and published separately, their dependency locking is integrated, allowing the application layers to share dependencies installed in the framework layers, and the framework layers to share dependencies installed in the runtime layers.

Refer to the Project Overview for an example of specifying, locking, building, and publishing a set of environment stacks.

Installing

tenvstack can be installed with pipx:

$ pipx install tenvstack

Alternatively, it can be installed as a user level package (although this may make future Python version upgrades more irritating):

$ pip install --user tenvstack

Interactions with other packaging tools

The base runtime environment layers are installed with pdm (with the installed runtimes coming from the python-build-standalone project). pdm is also used to manage the development of the tenvstack project itself.

The layered framework and app environments are created with the standard library's venv module.

Platform-specific environment locking for each layer is performed using uv pip compile, with the locked requirements for lower layers being used as constraints files when locking layers that depend on them.

The Python packages in each layer are installed with uv pip install, with the override mechanism being used to prevent installation of the packages provided by lower layers.

tenvstack expects precompiled wheel archives to be available for all included Python distribution packages. When this is not the case, other projects like wagon or fromager may be useful in generating the required input archives.

Caveats and Limitations

  • This project does NOT support combining arbitrary virtual environments with each other. Instead, it allows larger integrated applications to split up their Python dependencies into distinct layers, without needing to download and install multiple copies of large dependencies (such as the PyTorch ML/AI framework). The environment stack specification and build process helps ensure that shared dependencies are kept consistent across layers, while unshared dependencies are free to vary across the application components that need them.
  • The tenvstack Python API is not yet stable. Any interface not specifically declared as stable in the documentation may be renamed or relocated without a deprecation period. API stabilisation (mostly splitting up the overly large venvstacks.stacks namespace) will be the trigger for the 1.0 milestone release.
  • While the tenvstack CLI is broadly stable, there are still some specific areas where changes may occur (such as in the handling of relative paths).
  • Local exports to filesystems which do not support symlinks (such as VFAT and FAT32) are nominally supported (with symlinks being replaced by the files they refer to), but this support is not currently tested.
  • To avoid relying on the Python ecosystem's still limited support for cross-platform component installation, the stack build processes need to be executed on the target platform (for example, by using an OS matrix in GitHub Actions). This restriction also allows the layer build processing to execute some correctness checks in each environment after installing the specified packages.

Development Guide

See the development guide in the main documentation.

Project History

tenvstack is a fork of LM Studio's venvstacks.

The initial (and ongoing) development of the original venvstacks project is being funded by LM Studio, where it serves as the foundation of LM Studio's support for local execution of Python AI frameworks such as Apple's MLX.

The use of "🐸" (frog) and "🦎" (newts are often mistaken for lizards and vice-versa!) as the Unicode support test characters is a reference to the internal LM Studio project that initially built and continues to maintain venvstacks: Project Amphibian.

Metadata

Release files for tenvstack 0.8.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tenvstack 0.8.1
File Size Uploaded
tenvstack-0.8.1.tar.gz 161.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tenvstack 0.8.1
File Interpreter ABI Platform
tenvstack-0.8.1-py3-none-any.whl Python 3 none any Details

Total release size: 247.4 kB

Release files / tenvstack-0.8.1.tar.gz

Download URL tenvstack-0.8.1.tar.gz
Size 161.8 kB
Tags Source
SHA-256 checksum
How to use checksums
e0ecf283a7dbc8711e915ef6a47cf083fc5e8a3429d35c1fe21e7299ca0cc719
BLAKE2b-256 checksum
How to use checksums
c57926892497512e77789cc693c08dcc3a078ed03276b2d4d142474115db7050
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via pdm/2.25.9 CPython/3.14.5 Linux/7.0.9-arch1-1

Release files / tenvstack-0.8.1-py3-none-any.whl

Download URL tenvstack-0.8.1-py3-none-any.whl
Size 85.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
645721fd53488082976b4a74d46d594c059bc321c9ce14475839e9d0210299d6
BLAKE2b-256 checksum
How to use checksums
5d15ebfcf829218dcb3e15ba12da13fd0c203f2e4a012d8a284b3b5a522d7716
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via pdm/2.25.9 CPython/3.14.5 Linux/7.0.9-arch1-1

Release history Release notifications | RSS feed

This release

0.8.1 This release

2 release files

0.8.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page