Home Assistant Unofficial Reference 2024.12.1
homeassistant.util.package Namespace Reference

Functions

str async_get_user_site (str deps_dir)
 
set[str] get_installed_versions (set[str] specifiers)
 
bool install_package (str package, bool upgrade=True, str|None target=None, str|None constraints=None, int|None timeout=None)
 
bool is_docker_env ()
 
bool is_installed (str requirement_str)
 
bool is_virtual_env ()
 

Variables

 _LOGGER = logging.getLogger(__name__)
 
tuple _UV_ENV_PYTHON_VARS
 

Detailed Description

Helpers to install PyPi packages.

Function Documentation

◆ async_get_user_site()

str homeassistant.util.package.async_get_user_site ( str  deps_dir)
Return user local library path.

This function is a coroutine.

Definition at line 162 of file package.py.

◆ get_installed_versions()

set[str] homeassistant.util.package.get_installed_versions ( set[str]  specifiers)
Return a set of installed packages and versions.

Definition at line 35 of file package.py.

◆ install_package()

bool homeassistant.util.package.install_package ( str  package,
bool   upgrade = True,
str | None   target = None,
str | None   constraints = None,
int | None   timeout = None 
)
Install a package on PyPi. Accepts pip compatible package strings.

Return boolean if install successful.

Definition at line 93 of file package.py.

◆ is_docker_env()

bool homeassistant.util.package.is_docker_env ( )
Return True if we run in a docker env.

Definition at line 30 of file package.py.

◆ is_installed()

bool homeassistant.util.package.is_installed ( str  requirement_str)
Check if a package is installed and will be loaded when we import it.

expected input is a pip compatible package specifier (requirement string)
e.g. "package==1.0.0" or "package>=1.0.0,<2.0.0"

For backward compatibility, it also accepts a URL with a fragment
e.g. "git+https://github.com/pypa/pip#pip>=1"

Returns True when the requirement is met.
Returns False when the package is not installed or doesn't meet req.

Definition at line 40 of file package.py.

◆ is_virtual_env()

bool homeassistant.util.package.is_virtual_env ( )
Return if we run in a virtual environment.

Definition at line 21 of file package.py.

Variable Documentation

◆ _LOGGER

homeassistant.util.package._LOGGER = logging.getLogger(__name__)
private

Definition at line 18 of file package.py.

◆ _UV_ENV_PYTHON_VARS

tuple homeassistant.util.package._UV_ENV_PYTHON_VARS
private
Initial value:
1 = (
2  "UV_SYSTEM_PYTHON",
3  "UV_PYTHON",
4 )

Definition at line 87 of file package.py.