Skip to main content

venvctl

codecov pipeline status security: bandit Python package Known Vulnerabilities

venvctl is a CLI tool allowing the creation of fully portable Python virtual environments.

Synopsis

venvctl helps to build fully portable Python virtual environments, in bulk, or single mode, keeping the state in config files. Each virtual environment comes with a detailed markdown report, to overview the integrity of its state, broken dependencies, errors, and warnings that occurred in the build process. Eventually, the folders ready for distributions get packed in tarballs.

Limitations

It is evident that the portability is limited to systems sharing the same kernel, do not expect to build a virtual environment on a Debian based system, and deploy it on a RHEL host, to mention one of the many cases;

It is possible shipping a virtual environment with a different version of python other than the one installed on the destination system, yet again, do not assume to run python3 based venvs on a system solely configured with python 2.x.

Requirements

venvctl relies on a few packages to explicate its core functionalities:

piphyperd==1.9.10

piphyperd, a wrapper around pip to manage installations and audits.

markd==0.1.20

markd, a Python package that facilitates the generation of markdown flavored files.

virtualenv==20.4.7  # Virtual Python Environment builder.
click8==8.0.1  # Composable command line interface toolkit.
binaryornot==0.4.4  # Ultra-lightweight pure Python package to check if a file is binary or text.

Installation

venvctl is currently distributed only through PyPi.org

pip install --user venvctl

Visit the project page for further information about the package status and releases.

Documentation

For the detailed instructions and a full API walkthroug, refer to the Official Documenation.

You can leverage venvctl both programmatically, or calling the CLI, as shown in the examples below:

Build virtual environments in bulk programmatically

"""Python"""
from venvctl import VenvCtl

# Build virtualenvs in bulk
VenvCtl(config_file=/path/to/config.json,
        python_binary=/usr/bin/python{version},
        output_dir=/my/output/dir).run()

Build virtual environments in bulk leveraging the CLI

#!/bin/bash

# Build virtualenvs in bulk
venvctl generate \
    --config ~/path/to/your/config/venvs.json \
    --out ./venvs

Build a single virtual environment programmatically

"""Python"""
from venvctl import VenvCtl

name = "test-venv"
packages = [
    "Click==7.0",
    "binaryornot==0.4.4"
]

# Build a single virtual env;
# It will generate the config file for you.
VenvCtl.create_venv(name=name, packages=packages_list,
                    output_dir=/my/output/dir)

Build a single virtual environment leveraging the CLI

#!/bin/bash

# Build a single virtual env;
# It will generate the config file for you.
venvctl create --name my_venv --packages '["tox", "docker"]' --out /my/output/dir

Configuration File

A config file follows the json structure:

[
  {
      "name": "base",
      "packages": [
          "asn1crypto==1.3.0",
          "dnspython==1.16.0",
          "enum34==1.1.10",
          "ipaddress==1.0.23",
          "jmespath==0.9.5",
          "lxml==4.5.0",
          "paramiko==2.7.1",
          "psutil==5.7.0",
          "pycrypto==2.6.1",
          "pyopenssl==19.1.0",
          "python-ldap==3.2.0",
          "python-memcached==1.59"
      ]
  },
  {
    "name": "base_networking",
    "parent": "base",
    "packages": [
      "f5-sdk==3.0.21",
      "bigsuds==1.0.6",
      "netaddr==0.7.19",
      "cloudshell-networking-cisco-iosxr==4.0.6"
    ]
  },
  {
    "name": "ansible_2_9",
    "parent": "base",
    "packages": [
        "ansible==2.9.6"
    ]
  },
  {
    "name": "ansible_2_9_networking",
    "parent": "base_networking",
    "packages": [
        "ansible==2.9.6"
    ]
  }
]

The build process follows an inheritance pattern, in the example above, the environment named base is the core for the rest; ansible_2_9 inherits its packages; ansible_2_9_tox adds modules on the top of its parent, ansible_2_9.

With this logic, the build process in bulk can be quite fast, even when deploying complex virtual environments.

Run it with Containers

It is possible to take advantage of a container image, built to ship venvctl and the whole toolchain to create virtual environments leveraging both Python 2 and Python 3. Here to follow, two examples running Docker.

Build virtual environments in bulk, shipping Python 3.6.8:

docker run -it --rm -v $(pwd)/conf.json:/opt/conf.json \
  -v $(pwd)/venvs:/opt/venvs:rw \
  eu.gcr.io/hyperd-containers/venv-builder:latest venvctl generate \
  --config /opt/conf.json \
  --out /opt/venvs \

Build virtual environments in bulk, shipping Python 2.7.16:

docker run -it --rm -v $(pwd)/conf.json:/opt/conf.json \
  -v $(pwd)/venvs:/opt/venvs:rw \
  eu.gcr.io/hyperd-containers/venv-builder:latest venvctl generate \
  --config /opt/conf.json \
  --out /opt/venvs \
  --python /usr/bin/python2

Containers limitations

Currently, the container image available is based on CentOS 8. It fits the purpose of any RHEL based deployment; however, it won't be useful in other scenarios. More kernels will be added, stay tuned, or feel free to build your own and poke me.

License

GNU General Public License v3 (GPLv3)

Report a Vulnerability

If you believe you have found a security vulnerability in venvctl, drop me a line, I will coordinate the vunerability response and disclosure.

About the author

Francesco Cosentino

I'm a surfer, a crypto trader, and a DevSecOps Engineer with 15 years of experience designing highly-available distributed production environments and developing cloud-native apps in public and private clouds.

Metadata

Release files for venvctl 1.4.12

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

Source distribution (sdist)

Source distribution for venvctl 1.4.12
File Size Uploaded
venvctl-1.4.12.tar.gz 68.4 kB Details

Release files / venvctl-1.4.12.tar.gz

Download URL venvctl-1.4.12.tar.gz
Size 68.4 kB
Tags Source
SHA-256 checksum
How to use checksums
9709c7a9f3eed2be83b76dfffb15b6fdfeb21396787d2463f92bd14ca9e8af82
BLAKE2b-256 checksum
How to use checksums
0a1e59db27524309d57e39f99d9a94717490668d3b7a11b65aafe1e9a7302835
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6

Release history Release notifications | RSS feed

This release

1.4.12 This release

1 release file

1.4.7

1 release file

1.4.4

1 release file

1.4.3

1 release file

1.4.1

1 release file

1.4.0

1 release file

1.3.31

1 release file

1.3.29

1 release file

1.3.27

1 release file

1.3.26

1 release file

1.3.25

1 release file

1.3.24

1 release file

1.3.23

1 release file

1.3.22

1 release file

1.3.20

1 release file

1.3.19

1 release file

1.3.18

1 release file

1.3.17

1 release file

1.3.16

1 release file

1.3.10

1 release file

1.3.9

1 release file

1.3.8

1 release file

1.3.7

1 release file

1.3.6

1 release file

1.3.5

1 release file

1.3.4

1 release file

1.3.3

1 release file

1.3.2

1 release file

1.3.1

1 release file

1.3.0

1 release file

1.2.25

1 release file

1.2.24

1 release file

1.2.7

1 release file

1.2.6

1 release file

1.2.4

1 release file

1.2.3

1 release file

1.2.2

1 release file

1.2.1

1 release file

1.2.0

1 release file

1.1.0

1 release file

1.0.0

1 release file

0.5.21

1 release file

0.5.20

1 release file

0.5.19

1 release file

0.5.15

1 release file

0.5.12

1 release file

0.5.11

1 release file

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