Skip to main content

A layered virtual environment manager compatible with PEP 668

Project description

venv-stack

venv-stack is a lightweight PEP 668–compliant tool for layered Python virtual environments.
It lets you assemble project-specific venvs by linking multiple "base" environments,
so heavy dependencies (e.g. PyTorch) live in a shared base instead of being re-installed per-project.

Features

  • Layered Environments
    Create project virtual environments that symlink into one or more named base venvs
    (no redundant copies of large packages).

  • PEP 668 Compliance
    Never require --break-system-packages—you stay safe from system-wide pip installs.

  • Simple CLI

    • venv-stack base <name>: create a named base env
    • venv-stack project [path] <bases>: create a project env in path/.venv
    • venv-stack link <base> <project>: add another base to an existing project
    • venv-stack list: list all known venvs
    • venv-stack activate <name>: activate a base virtual environment. If no name is given, activate the current project environment.
    • venv-stack export [project_path] [output_file]: export installed packages to a file
    • venv-stack sync <requirements_file> [project_path]: install packages from a requirements.txt into the project venv
    • venv-stack list-packages [name]: list installed packages in a specific venv or all venvs if no name is given.

Installation

pip install venv-stack

(Alternatively, clone and pip install ..)

Usage

# 1. Create shared bases
venv-stack base common   # e.g. numpy, pandas, scipy
venv-stack base ml       # e.g. torch, tensorflow

# 2 Activate the base venv, install packages
venv-stack activate common
pip install numpy pandas scipy torch tensorflow

# 3. Create a project venv that layers both
cd my-project
venv-stack project . common,ml

# 4. Activate
venv-stack activate # activates the current project if no name is given

# 5. Install project‑specific deps
pip install fastapi uvicorn

# 6. Export installed packages
venv-stack export [project_path] [output_file]
# e.g. venv-stack export . requirements.txt

# 7. Sync from a requirements file
venv-stack sync [requirements.txt] [project_path]
# e.g. venv-stack sync requirements.txt .

# 8 List all virtual environments
venv-stack list

# 9 List all installed packages in a venv
venv-stack list-packages [name]

# 10 List all packages installed in all virtual environments
venv-stack list-packages

Commands

Command Description
venv-stack base <name> Create a named base environment
venv-stack project [path] <bases> Create a stacked project env at path/.venv
venv-stack link <base> <project> Add a base to an existing project venv
venv-stack list List all known base & project virtual environments
venv-stack activate <name> Activate the given base environment <name>
venv-stack export [project_path] [output_file] Export the stacked project venv’s installed packages (pip freeze) to a file
venv-stack sync <requirements_file> [project_path] Install packages from a requirements.txt into the project venv
venv-stack list-packages [name] List installed packages in a specific venv or all venvs if no name is given

Activate not working with your terminal?

You can update the shells.py file to add your shell:

# needed in order for the activate command to work properly. 
# If you are using a different shell, you may need to adjust the candidates accordingly.
shells = {
    "bash": {
        "flags": lambda tmp_profile_path: ["--rcfile", f"{tmp_profile_path}", "-i"],
        "rc": [".bashrc", ".bash_profile", ".profile"]
    },
    "zsh": {
        "env": lambda tmp_profile_path: f"ZDOTDIR={tmp_profile_path.parent}",
        "flags": ["-i"],
        "rc": [".zshrc", ".zprofile"]
    },
}

Contributing

  1. Fork the repo

  2. Create a feature branch (git checkout -b feature/foo)

  3. Commit your changes (git commit -am 'Add foo')

  4. Push and open a PR

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

venv_stack-1.0.0.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

venv_stack-1.0.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file venv_stack-1.0.0.tar.gz.

File metadata

  • Download URL: venv_stack-1.0.0.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for venv_stack-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ca5a8848b06ed4b448049bb055c471e32ff2a1eb34a9258a6162bee746923ff9
MD5 0fa1b2ab1df15d29626f1846a68d9e6d
BLAKE2b-256 dcc577fa485ee2b04410d56e652d0d8ac806e8fdf539966261b3120db266a05e

See more details on using hashes here.

File details

Details for the file venv_stack-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: venv_stack-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for venv_stack-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5d042cf81a11cb779c4d01360676ff7370486655ecda434bc381ff61da07966e
MD5 25508b3cd6fffc363bbe5e4761417b3c
BLAKE2b-256 a6b85dc8e31127b8e54a2829e159649ff5958005bffa01836c77f73f9f3a8da2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page