Python¶
- class verta.environment.Python(requirements, constraints=None, env_vars=None, apt_packages=None, _autocapture=True)¶
Capture metadata about Python, installed packages, and system environment variables.
New in version 0.24.0:
python_version
attribute.Note
Comments and blank lines will not be captured during parsing.
- Parameters:
constraints (list of str, optional) – List of PyPI package names with version specifiers. If not provided, nothing will be captured.
env_vars (list of str, or dict of str to str, optional) – Environment variables. If a list of names is provided, the values will be captured from the current environment. If not provided, nothing will be captured.
apt_packages (list of str, optional) – Apt packages to be installed alongside a Python environment.
_autocapture (bool, default True) – Whether to enable the automatic capturing behavior of parameters above.
- Variables:
apt_packages (list of str) – Apt packages to be installed alongside a Python environment.
env_vars (dict of str to str, or None) – Environment variables.
python_version (3-tuple of int, or None) – Python version. This tuple contains three compoennts of the version number: major, minor, and micro. Similar to
sys.version_info
, the components can be accessed by index or by name, soenv.python_version[0]
is equivalent toenv.python_version.major
and so on. ReturnsNone
if no Python version was captured.
Examples
from verta.environment import Python env1 = Python(requirements=Python.read_pip_environment()) env1.apt_packages = ["python3-opencv"] env2 = Python(requirements=Python.read_pip_file("../requirements.txt")) env3 = Python( requirements=[ "scikit-learn==1.0.2", "tensorflow", ], env_vars=["CUDA_VISIBLE_DEVICES"], apt_packages=["python3-opencv"] )
- add_env_vars(env_vars)¶
Add environment variables.
- Parameters:
env_vars (list of str, or dict of str to str) – Environment variables. If a list of names is provided, the values will be captured from the current environment.
Examples
print(env.env_vars) # {} env.add_env_vars(["VERTA_HOST"]) print(env.env_vars) # {'VERTA_HOST': 'app.verta.ai'} env.add_env_vars({"CUDA_VISIBLE_DEVICES": "0,1"}) print(env.env_vars) # {'VERTA_HOST': 'app.verta.ai', 'CUDA_VISIBLE_DEVICES': '0,1'}
- static blob_msg_to_object(blob_msg)¶
Deserialize a blob protobuf message into an instance.
- Parameters:
blob_msg (
VersioningService_pb2.Blob
) –- Returns:
instance of subclass of
Blob
- static read_pip_environment(skip_options=False, exclude=['[a-z]{2}(?:[_-][a-z]+){2}[_-](?:sm|md|lg)', 'anaconda-client'])¶
Read package versions from pip into a list.
Changed in version 0.20.0: This method now includes, rather than skipping, pip packages installed via version control systems. The new skip_options parameter can be set to
True
to restore the old behavior.- Parameters:
skip_options (bool, default False) – Whether to omit lines with advanced pip options.
exclude (list of str, default spaCy models and "anaconda-client") – Regex patterns for packages to omit. Certain tools, such as conda and spaCy, install items into the pip environment that can’t be installed from PyPI when a model is deployed in Verta.
- Returns:
list of str – pip requirement specifiers.
Examples
from verta.environment import Python env = Python(Python.read_pip_environment())
- static read_pip_file(filepath, skip_options=False)¶
Read a pip requirements or constraints file into a list.
Changed in version 0.20.0: This method now includes, rather than skipping, pip packages installed via version control systems,
pip install
options, and other requirements file configurations. The new skip_options parameter can be set toTrue
to restore the old behavior.- Parameters:
- Returns:
list of str – pip requirement specifiers and options.
Examples
from verta.environment import Python env = Python( requirements=Python.read_pip_file("requirements.txt"), constraints=Python.read_pip_file("constraints.txt"), )