Skip to content

Environment API#

To create an object of this class, use get_environment_api. You can then use the following methods of EnvironmentApi to create or get an Environment.

create_environment #

create_environment(
    name: str,
    description: str | None = None,
    base_environment_name: str
    | None = "python-feature-pipeline",
    await_creation: bool | None = True,
) -> environment.Environment

Create Python environment for the project.

import hopsworks

project = hopsworks.login()

env_api = project.get_environment_api()

new_env = env_api.create_environment("my_custom_environment", base_environment_name="python-feature-pipeline")
PARAMETER DESCRIPTION
name

Name of the environment.

TYPE: str

base_environment_name

The name of the environment to clone from.

TYPE: str | None DEFAULT: 'python-feature-pipeline'

await_creation

Whether the method returns only when the creation is finished.

TYPE: bool | None DEFAULT: True

RETURNS DESCRIPTION
environment.Environment

The Environment object.

RAISES DESCRIPTION
hopsworks.client.exceptions.RestAPIError

If the backend encounters an error when handling the request.

get_environment #

get_environment(
    name: str,
) -> environment.Environment | None

Get handle for a Python environment in the project.

import hopsworks

project = hopsworks.login()

env_api = project.get_environment_api()

env = env_api.get_environment("my_custom_environment")
PARAMETER DESCRIPTION
name

Name of the environment.

TYPE: str

RETURNS DESCRIPTION
environment.Environment | None

The Environment object or None if it does not exist.

RAISES DESCRIPTION
hopsworks.client.exceptions.RestAPIError

If the backend encounters an error when handling the request.

Environment #

description property #

description

Description of the environment.

name property #

name

Name of the environment.

python_version property #

python_version

Python version of the environment.

delete #

delete()

Delete the environment.

Potentially dangerous operation

This operation deletes the python environment.

RAISES DESCRIPTION
hopsworks.client.exceptions.RestAPIError

If the backend encounters an error when handling the request.

install_requirements #

install_requirements(
    path: str, await_installation: bool | None = True
) -> Library

Install libraries specified in a requirements.txt file.

import hopsworks

project = hopsworks.login()

# Upload to Hopsworks
ds_api = project.get_dataset_api()
requirements_path = ds_api.upload("requirements.txt", "Resources")

# Install
env_api = project.get_environment_api()
env = env_api.get_environment("my_custom_environment")

env.install_requirements(requirements_path)
PARAMETER DESCRIPTION
path

The path in Hopsworks where the requirements.txt file is located.

TYPE: str

await_installation

If True the method returns only when the installation is finished.

TYPE: bool | None DEFAULT: True

RETURNS DESCRIPTION
Library

The library object.

RAISES DESCRIPTION
hopsworks.client.exceptions.RestAPIError

If the backend encounters an error when handling the request.

install_wheel #

install_wheel(
    path: str, await_installation: bool | None = True
) -> Library

Install a python library packaged in a wheel file.

import hopsworks

project = hopsworks.login()

# Upload to Hopsworks
ds_api = project.get_dataset_api()
whl_path = ds_api.upload("matplotlib-3.1.3-cp38-cp38-manylinux1_x86_64.whl", "Resources")

# Install
env_api = project.get_environment_api()
env = env_api.get_environment("my_custom_environment")

env.install_wheel(whl_path)
PARAMETER DESCRIPTION
path

The path in Hopsworks where the wheel file is located.

TYPE: str

await_installation

If True the method returns only when the installation finishes.

TYPE: bool | None DEFAULT: True

RETURNS DESCRIPTION
Library

The library object.

RAISES DESCRIPTION
hopsworks.client.exceptions.RestAPIError

If the backend encounters an error when handling the request.